Skip to content

Commit 5e7083a

Browse files
authored
Merge pull request #21 from sakhnyuk/dev
#20 fix: window is not defined
2 parents 33ff3ec + 05850a7 commit 5e7083a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-scrollbars",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "React scrollbars component",
55
"main": "lib/index.js",
66
"scripts": {

src/utils/getScrollbarWidth.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import css from 'dom-css';
22

33
let scrollbarWidth: number | undefined = undefined;
4-
let pxRatio: number = window.screen.availWidth / document.documentElement.clientWidth;
4+
let pxRatio: number = getPxRatio();
55

66
export default function getScrollbarWidth() {
77
/**
88
* Check zoom ratio. If it was changed, then it would update scrollbatWidth
99
*/
10-
const newPxRatio = window.screen.availWidth / document.documentElement.clientWidth;
10+
const newPxRatio = getPxRatio();
11+
1112
if (pxRatio !== newPxRatio) {
1213
scrollbarWidth = getScrollbarWidthFromDom();
1314
}
@@ -42,3 +43,8 @@ function getScrollbarWidthFromDom() {
4243

4344
return result;
4445
}
46+
47+
function getPxRatio() {
48+
if (typeof window === 'undefined') return 1;
49+
return window.screen.availWidth / document.documentElement.clientWidth;
50+
}

0 commit comments

Comments
 (0)