Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit f9204ba

Browse files
committed
fix: scroll bug
1 parent a9655c6 commit f9204ba

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"react-hot-loader": "^4.13.0",
9393
"react-scroll-to-bottom": "^4.1.0",
9494
"sass-loader": "^10.1.0",
95+
"scrollparent": "^2.0.1",
9596
"smoothscroll-polyfill": "^0.4.4",
9697
"source-map-loader": "^1.1.3",
9798
"style-loader": "^2.0.0",

src/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'scrollparent' {
2+
export default function (element: Element): Element
3+
}

src/pages/Content/components/TranslationItem.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react'
22
import Clipboard from 'react-clipboard.js'
33
import { useSnackbar } from 'notistack'
44
import { Collapse } from 'react-collapse'
5+
import scrollParent from 'scrollparent'
56

67
import logger from '../../../common/logger'
78
import { TranslateResult } from '../../../common/types'
@@ -34,8 +35,22 @@ const TranslationItem: React.FC<{
3435
return
3536
}
3637

38+
const scrollContainer = scrollParent(parentElement)
39+
3740
if (parentElement instanceof HTMLElement) {
38-
window.scrollTo(0, parentElement.offsetTop - 20)
41+
if (scrollContainer === document.body) {
42+
document.documentElement.scrollTo({
43+
top: parentElement.offsetTop - 20,
44+
left: 0,
45+
behavior: 'smooth',
46+
})
47+
} else {
48+
scrollContainer.scrollTo({
49+
top: parentElement.offsetTop - 20,
50+
left: 0,
51+
behavior: 'smooth',
52+
})
53+
}
3954
}
4055
}
4156

src/pages/Content/styles/components/App.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
width: 450px;
44
height: 600px;
55
z-index: 1;
6+
will-change: transform;
67
@apply bg-white shadow rounded-lg overflow-hidden flex flex-col;
78

89
&--inactive {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7730,6 +7730,11 @@ schema-utils@^3.0.0:
77307730
ajv "^6.12.5"
77317731
ajv-keywords "^3.5.2"
77327732

7733+
scrollparent@^2.0.1:
7734+
version "2.0.1"
7735+
resolved "https://registry.yarnpkg.com/scrollparent/-/scrollparent-2.0.1.tgz#715d5b9cc57760fb22bdccc3befb5bfe06b1a317"
7736+
integrity sha1-cV1bnMV3YPsivczDvvtb/gaxoxc=
7737+
77337738
scss-tokenizer@^0.2.3:
77347739
version "0.2.3"
77357740
resolved "https://registry.yarnpkg.com/scss-tokenizer/-/scss-tokenizer-0.2.3.tgz#8eb06db9a9723333824d3f5530641149847ce5d1"

0 commit comments

Comments
 (0)