Skip to content

Commit 3bb3f81

Browse files
committed
fix: avoid SimpleBar to be instantiated twice on the same node
1 parent 56ca2c9 commit 3bb3f81

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/simplebar/src/simplebar.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export default class SimpleBar {
1919
this.scrollbarWidth;
2020
this.minScrollbarWidth = 20;
2121
this.options = { ...SimpleBar.defaultOptions, ...options };
22-
this.classNames = { ...SimpleBar.defaultOptions.classNames, ...this.options.classNames };
22+
this.classNames = {
23+
...SimpleBar.defaultOptions.classNames,
24+
...this.options.classNames
25+
};
2326
this.isRtl;
2427
this.axis = {
2528
x: {
@@ -50,6 +53,11 @@ export default class SimpleBar {
5053
}
5154
};
5255

56+
// Don't re-instantiate over an existing one
57+
if (this.el.SimpleBar) {
58+
return;
59+
}
60+
5361
this.recalculate = throttle(this.recalculate.bind(this), 64);
5462
this.onMouseMove = throttle(this.onMouseMove.bind(this), 64);
5563
this.hideScrollbars = debounce(
@@ -124,7 +132,7 @@ export default class SimpleBar {
124132
horizontal: 'simplebar-horizontal',
125133
vertical: 'simplebar-vertical',
126134
hover: 'simplebar-hover',
127-
dragging: 'simplebar-dragging',
135+
dragging: 'simplebar-dragging'
128136
},
129137
scrollbarMinSize: 25,
130138
scrollbarMaxSize: 0,
@@ -141,7 +149,7 @@ export default class SimpleBar {
141149
mutations.forEach(mutation => {
142150
Array.prototype.forEach.call(mutation.addedNodes, addedNode => {
143151
if (addedNode.nodeType === 1) {
144-
if (addedNode.hasAttribute('data-simplebar')) {
152+
if (addedNode.dataset.simplebar) {
145153
!addedNode.SimpleBar &&
146154
new SimpleBar(addedNode, SimpleBar.getElOptions(addedNode));
147155
} else {
@@ -466,8 +474,10 @@ export default class SimpleBar {
466474
this.axis.y.isOverflowing =
467475
this.elStyles.overflowY === 'hidden' ? false : this.axis.y.isOverflowing;
468476

469-
this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
470-
this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
477+
this.axis.x.forceVisible =
478+
this.options.forceVisible === 'x' || this.options.forceVisible === true;
479+
this.axis.y.forceVisible =
480+
this.options.forceVisible === 'y' || this.options.forceVisible === true;
471481

472482
this.axis.x.scrollbar.size = this.getScrollbarSize('x');
473483
this.axis.y.scrollbar.size = this.getScrollbarSize('y');

0 commit comments

Comments
 (0)