Skip to content

Commit a67daa1

Browse files
committed
use getComputedStyle, fix ant-design/ant-design#13280
1 parent b6f5d68 commit a67daa1

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

examples/simple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Demo extends React.Component {
7878
}}
7979
>
8080
内容区块
81-
</div>
81+
</div>
8282
</div>
8383
)
8484
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"main": "./lib/index",
3333
"module": "./es/index",
3434
"scripts": {
35-
"start": "father doc dev --storybook",
35+
"start": "rm -rf .storybook lib es && father doc dev --storybook",
3636
"build": "father doc build --storybook",
3737
"compile": "father build && lessc assets/index.less assets/index.css",
3838
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",

src/DrawerChild.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
121121
}
122122

123123
public componentWillUnmount() {
124-
const { getOpenCount, getContainer, open } = this.props;
124+
const { getOpenCount, open } = this.props;
125125
delete currentDrawer[this.drawerId];
126126
if (open) {
127127
this.setLevelDomTransform(false);

src/utils.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,24 @@ export const getTouchParentScroll = (
8888

8989
const scrollY = currentTarget.scrollHeight - currentTarget.clientHeight;
9090
const scrollX = currentTarget.scrollWidth - currentTarget.clientWidth;
91-
/**
92-
* <div style="height: 300px">
93-
* <div style="height: 900px"></div>
94-
* </div>
95-
* 在没设定 overflow: auto 或 scroll 时,currentTarget 里获取不到 scrollTop 或 scrollLeft,
96-
* 预先用 scrollTo 来滚动,如果取出的值跟滚动前取出不同,则 currnetTarget 被设定了 overflow; 否则就是上面这种。
97-
*/
98-
const t = currentTarget.scrollTop;
99-
const l = currentTarget.scrollLeft;
100-
currentTarget.scrollTop += 1;
101-
currentTarget.scrollLeft += 1;
102-
const currentT = currentTarget.scrollTop;
103-
const currentL = currentTarget.scrollLeft;
104-
currentTarget.scrollTop -= 1;
105-
currentTarget.scrollLeft -= 1;
91+
92+
const style = document.defaultView.getComputedStyle(currentTarget);
93+
const overflowY = style.overflowY === 'auto' || style.overflowY === 'scroll';
94+
const overflowX = style.overflowX === 'auto' || style.overflowX === 'scroll';
95+
96+
const y = scrollY && overflowY;
97+
const x = scrollX && overflowX;
98+
10699
if (
107-
(isY &&
108-
(!scrollY ||
109-
!(currentT - t) ||
110-
(scrollY &&
111-
((currentTarget.scrollTop >= scrollY && differY < 0) ||
112-
(currentTarget.scrollTop <= 0 && differY > 0))))) ||
113-
(isX &&
114-
(!scrollX ||
115-
!(currentL - l) ||
116-
(scrollX &&
117-
((currentTarget.scrollLeft >= scrollX && differX < 0) ||
118-
(currentTarget.scrollLeft <= 0 && differX > 0)))))
100+
isY && (!y ||
101+
(y && (
102+
(currentTarget.scrollTop >= scrollY && differY < 0) ||
103+
(currentTarget.scrollTop <= 0 && differY > 0)
104+
))) ||
105+
isX && (!x ||
106+
x && (
107+
(currentTarget.scrollLeft >= scrollX && scrollX < 0) ||
108+
(currentTarget.scrollLeft <= 0 && scrollX > 0)))
119109
) {
120110
return getTouchParentScroll(
121111
root,

0 commit comments

Comments
 (0)