@rc-component/portal 1.0.0-3 → 1.0.0-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/useScrollLocker.js +3 -1
- package/es/util.d.ts +4 -0
- package/es/util.js +6 -0
- package/lib/useScrollLocker.js +4 -1
- package/lib/util.d.ts +4 -0
- package/lib/util.js +13 -0
- package/package.json +1 -1
package/es/useScrollLocker.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { updateCSS, removeCSS } from "rc-util/es/Dom/dynamicCSS";
|
|
3
3
|
import useLayoutEffect, { useLayoutUpdateEffect } from "rc-util/es/hooks/useLayoutEffect";
|
|
4
4
|
import getScrollBarSize from "rc-util/es/getScrollBarSize";
|
|
5
|
+
import { isBodyOverflowing } from "./util";
|
|
5
6
|
var lockCount = 0;
|
|
6
7
|
var locked = false;
|
|
7
8
|
var UNIQUE_ID = "rc-util-locker-".concat(Date.now());
|
|
@@ -14,7 +15,8 @@ function syncLocker() {
|
|
|
14
15
|
|
|
15
16
|
if (locked) {
|
|
16
17
|
var scrollbarSize = getScrollBarSize();
|
|
17
|
-
|
|
18
|
+
var isOverflow = isBodyOverflowing();
|
|
19
|
+
updateCSS("\nhtml body {\n overflow-y: hidden;\n ".concat(isOverflow ? "width: calc(100% - ".concat(scrollbarSize, "px);") : '', "\n}"), UNIQUE_ID);
|
|
18
20
|
} else {
|
|
19
21
|
removeCSS(UNIQUE_ID);
|
|
20
22
|
}
|
package/es/util.d.ts
ADDED
package/es/util.js
ADDED
package/lib/useScrollLocker.js
CHANGED
|
@@ -17,6 +17,8 @@ var _useLayoutEffect = _interopRequireWildcard(require("rc-util/lib/hooks/useLay
|
|
|
17
17
|
|
|
18
18
|
var _getScrollBarSize = _interopRequireDefault(require("rc-util/lib/getScrollBarSize"));
|
|
19
19
|
|
|
20
|
+
var _util = require("./util");
|
|
21
|
+
|
|
20
22
|
var lockCount = 0;
|
|
21
23
|
var locked = false;
|
|
22
24
|
var UNIQUE_ID = "rc-util-locker-".concat(Date.now());
|
|
@@ -29,7 +31,8 @@ function syncLocker() {
|
|
|
29
31
|
|
|
30
32
|
if (locked) {
|
|
31
33
|
var scrollbarSize = (0, _getScrollBarSize.default)();
|
|
32
|
-
(0,
|
|
34
|
+
var isOverflow = (0, _util.isBodyOverflowing)();
|
|
35
|
+
(0, _dynamicCSS.updateCSS)("\nhtml body {\n overflow-y: hidden;\n ".concat(isOverflow ? "width: calc(100% - ".concat(scrollbarSize, "px);") : '', "\n}"), UNIQUE_ID);
|
|
33
36
|
} else {
|
|
34
37
|
(0, _dynamicCSS.removeCSS)(UNIQUE_ID);
|
|
35
38
|
}
|
package/lib/util.d.ts
ADDED
package/lib/util.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isBodyOverflowing = isBodyOverflowing;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Test usage export. Do not use in your production
|
|
10
|
+
*/
|
|
11
|
+
function isBodyOverflowing() {
|
|
12
|
+
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
|
|
13
|
+
}
|