Skip to content

Commit 5d6b0f9

Browse files
committed
Add support for flexbox parents (fix Grsmto#473)
Previously attempting to use SimpleBar in a parent with "display: flex" resulted in no scrolling at all. If you specified "overflow: scroll" on the SimpleBar element you got two scroll bars being displayed the SimpleBar one and the native one. The fix is to simply add "overflow: hidden" on the SimpleBar element (otherwise the track offsetHeigth is equal to our scrollHeight). Since we currently respect overflow settings (by setting the respective scrollbar to a size of 0), we also need to skip that check for flex parents.
1 parent 0ca9cf6 commit 5d6b0f9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/simplebar/src/simplebar.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export default class SimpleBar {
6464

6565
SimpleBar.getRtlHelpers = memoize(SimpleBar.getRtlHelpers);
6666

67+
const parentDisplay = getElementWindow(this.el).getComputedStyle(this.el.parentElement).display;
68+
if (parentDisplay == 'flex' || parentDisplay == 'inline-flex') {
69+
this.parentIsFlex = true;
70+
this.el.style.overflow = 'hidden';
71+
}
6772
this.init();
6873
}
6974

@@ -361,11 +366,13 @@ export default class SimpleBar {
361366
this.axis.y.isOverflowing =
362367
contentElScrollHeight > contentWrapperElOffsetHeight;
363368

364-
// Set isOverflowing to false if user explicitely set hidden overflow
365-
this.axis.x.isOverflowing =
366-
elOverflowX === 'hidden' ? false : this.axis.x.isOverflowing;
367-
this.axis.y.isOverflowing =
368-
elOverflowY === 'hidden' ? false : this.axis.y.isOverflowing;
369+
if (!this.parentIsFlex){
370+
// Set isOverflowing to false if user explicitely set hidden overflow
371+
this.axis.x.isOverflowing =
372+
elOverflowX === 'hidden' ? false : this.axis.x.isOverflowing;
373+
this.axis.y.isOverflowing =
374+
elOverflowY === 'hidden' ? false : this.axis.y.isOverflowing;
375+
}
369376

370377
this.axis.x.forceVisible =
371378
this.options.forceVisible === 'x' || this.options.forceVisible === true;

0 commit comments

Comments
 (0)