From 5920e9d36d8bedcc12acb5d191e7cdb4cca38bb3 Mon Sep 17 00:00:00 2001 From: Victoria Kuchina Date: Fri, 2 Dec 2022 09:58:13 -0600 Subject: [PATCH] don't set up scrollbarWidth while zero offsetWidth and clientWidth --- src/utils/getScrollbarWidth.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/getScrollbarWidth.js b/src/utils/getScrollbarWidth.js index a8ee721..c13df6b 100644 --- a/src/utils/getScrollbarWidth.js +++ b/src/utils/getScrollbarWidth.js @@ -15,7 +15,13 @@ export default function getScrollbarWidth(cacheEnabled = true) { MsOverflowStyle: 'scrollbar' }); document.body.appendChild(div); - scrollbarWidth = (div.offsetWidth - div.clientWidth); + + if (div.offsetWidth !== 0 && div.clientWidth !== 0) { + scrollbarWidth = (div.offsetWidth - div.clientWidth); + } else { + scrollbarWidth = false; + } + document.body.removeChild(div); } else { scrollbarWidth = 0;