Skip to content

Commit

Permalink
fix: remove UA sniffing as it doesn't work and switch to feature dete…
Browse files Browse the repository at this point in the history
…ction instead
  • Loading branch information
Grsmto committed Oct 17, 2019
1 parent c52057d commit fbb5d3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 1 addition & 5 deletions packages/simplebar/src/scrollbar-width.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ window.addEventListener('resize', () => {

export default function scrollbarWidth() {
if (cachedScrollbarWidth === null) {
if (
typeof document === 'undefined' ||
/AppleWebKit/.test(navigator.userAgent) ||
'scrollbarWidth' in document.documentElement.style
) {
if (typeof document === 'undefined') {
cachedScrollbarWidth = 0;
return cachedScrollbarWidth;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/simplebar/src/simplebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
scrollbar-width: none;
}

.simplebar-content-wrapper::-webkit-scrollbar {
.simplebar-content-wrapper::-webkit-scrollbar,
.simplebar-hide-scrollbar::-webkit-scrollbar {
display: none;
}

Expand Down Expand Up @@ -206,7 +207,3 @@
overflow-y: scroll;
scrollbar-width: none;
}

.simplebar-hide-scrollbar::-webkit-scrollbar {
display: none;
}
17 changes: 15 additions & 2 deletions packages/simplebar/src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class SimpleBar {
if (canUseDOM) {
this.initDOM();

this.scrollbarWidth = scrollbarWidth();
this.scrollbarWidth = this.getScrollbarWidth();

this.recalculate();

Expand Down Expand Up @@ -579,7 +579,7 @@ export default class SimpleBar {

onWindowResize = () => {
// Recalculate scrollbarWidth in case it's a zoom
this.scrollbarWidth = scrollbarWidth();
this.scrollbarWidth = this.getScrollbarWidth();

this.hideNativeScrollbar();
};
Expand Down Expand Up @@ -823,6 +823,19 @@ export default class SimpleBar {
return this.contentWrapperEl;
}

getScrollbarWidth() {
// Detect Chrome/Firefox and do not calculate
if (
getComputedStyle(this.contentWrapperEl, '::-webkit-scrollbar').display ===
'none' ||
'scrollbarWidth' in document.documentElement.style
) {
return 0;
} else {
return scrollbarWidth();
}
}

removeListeners() {
// Event listeners
if (this.options.autoHide) {
Expand Down

0 comments on commit fbb5d3e

Please sign in to comment.