@helpscout/hsds-react
Version:
React component library for Help Scout's Design System
44 lines (37 loc) • 1.14 kB
JavaScript
exports.__esModule = true;
exports.default = void 0;
/* istanbul ignore file */
// Based on this solution
// https://davidwalsh.name/detect-scrollbar-width
// Slightly modified with caching, for performance
var getScrollBarWidth = function getScrollBarWidth() {
var namespace = 'BlueOSScrollbarWidthDetect';
if (window[namespace]) {
return window[namespace];
}
var inner = document.createElement('p');
inner.style.width = '100%';
inner.style.height = '200px';
var outer = document.createElement('div');
outer.style.position = 'absolute';
outer.style.top = '0px';
outer.style.left = '0px';
outer.style.visibility = 'hidden';
outer.style.width = '200px';
outer.style.height = '150px';
outer.style.overflow = 'hidden';
outer.appendChild(inner);
document.body.appendChild(outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 === w2) {
w2 = outer.clientWidth;
}
document.body.removeChild(outer);
window[namespace] = w1 - w2;
return window[namespace];
};
var _default = getScrollBarWidth;
exports.default = _default;
;