Skip to content

Commit 502e402

Browse files
committed
better overflow check
1 parent 48415a8 commit 502e402

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/ModalManager.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import css from 'dom-helpers/style';
22
import classes from 'dom-helpers/class';
33
import getScrollbarSize from 'dom-helpers/util/scrollbarSize';
4-
import isWindow from 'dom-helpers/query/isWindow';
5-
6-
function containerClientHeight(container) {
7-
let win = isWindow(container);
8-
return win
9-
? win.documentElement.clientHeight
10-
: container.clientHeight;
11-
}
4+
import isOverflowing from './utils/isOverflowing';
125

136
let findContainer = (data, modal)=> {
147
let idx = -1;
@@ -73,7 +66,7 @@ class ModalManager {
7366
overflow: 'hidden'
7467
};
7568

76-
data.overflowing = container.scrollHeight > containerClientHeight(container);
69+
data.overflowing = isOverflowing(container);
7770

7871
if (data.overflowing) {
7972
// use computed style, here to get the real padding

src/utils/isOverflowing.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import isWindow from 'dom-helpers/query/isWindow';
2+
import ownerDocument from 'dom-helpers/ownerDocument';
3+
4+
function isBody(node){
5+
return node && node.tagName.toLowerCase() === 'body';
6+
}
7+
8+
function bodyIsOverflowing(node){
9+
let doc = ownerDocument(node);
10+
let win = isWindow(doc);
11+
let fullWidth = win.innerWidth;
12+
13+
// Support: ie8, no innerWidth
14+
if (!fullWidth) {
15+
let documentElementRect = doc.documentElement.getBoundingClientRect();
16+
fullWidth = documentElementRect.right - Math.abs(documentElementRect.left);
17+
}
18+
19+
return doc.body.clientWidth < fullWidth;
20+
}
21+
22+
export default function isOverflowing(container) {
23+
let win = isWindow(container);
24+
25+
return win || isBody(container)
26+
? bodyIsOverflowing(container)
27+
: container.scrollHeight > container.clientHeight;
28+
}

0 commit comments

Comments
 (0)