Skip to content

Commit

Permalink
fix: avoid SimpleBar to be instantiated twice on the same node
Browse files Browse the repository at this point in the history
  • Loading branch information
Grsmto committed Apr 11, 2019
1 parent 56ca2c9 commit 3bb3f81
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/simplebar/src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export default class SimpleBar {
this.scrollbarWidth;
this.minScrollbarWidth = 20;
this.options = { ...SimpleBar.defaultOptions, ...options };
this.classNames = { ...SimpleBar.defaultOptions.classNames, ...this.options.classNames };
this.classNames = {
...SimpleBar.defaultOptions.classNames,
...this.options.classNames
};
this.isRtl;
this.axis = {
x: {
Expand Down Expand Up @@ -50,6 +53,11 @@ export default class SimpleBar {
}
};

// Don't re-instantiate over an existing one
if (this.el.SimpleBar) {
return;
}

this.recalculate = throttle(this.recalculate.bind(this), 64);
this.onMouseMove = throttle(this.onMouseMove.bind(this), 64);
this.hideScrollbars = debounce(
Expand Down Expand Up @@ -124,7 +132,7 @@ export default class SimpleBar {
horizontal: 'simplebar-horizontal',
vertical: 'simplebar-vertical',
hover: 'simplebar-hover',
dragging: 'simplebar-dragging',
dragging: 'simplebar-dragging'
},
scrollbarMinSize: 25,
scrollbarMaxSize: 0,
Expand All @@ -141,7 +149,7 @@ export default class SimpleBar {
mutations.forEach(mutation => {
Array.prototype.forEach.call(mutation.addedNodes, addedNode => {
if (addedNode.nodeType === 1) {
if (addedNode.hasAttribute('data-simplebar')) {
if (addedNode.dataset.simplebar) {
!addedNode.SimpleBar &&
new SimpleBar(addedNode, SimpleBar.getElOptions(addedNode));
} else {
Expand Down Expand Up @@ -466,8 +474,10 @@ export default class SimpleBar {
this.axis.y.isOverflowing =
this.elStyles.overflowY === 'hidden' ? false : this.axis.y.isOverflowing;

this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
this.axis.x.forceVisible =
this.options.forceVisible === 'x' || this.options.forceVisible === true;
this.axis.y.forceVisible =
this.options.forceVisible === 'y' || this.options.forceVisible === true;

this.axis.x.scrollbar.size = this.getScrollbarSize('x');
this.axis.y.scrollbar.size = this.getScrollbarSize('y');
Expand Down

0 comments on commit 3bb3f81

Please sign in to comment.