Skip to content

Commit 6c248f9

Browse files
committed
Default styles fix for RTL direction;
1 parent e894067 commit 6c248f9

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

dist/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,25 @@ function (_React$Component) {
345345
!(0, _utilities.isset)(isRtl) && (isRtl = rtlAutodetect ? getComputedStyle(_this.content).direction === "rtl" : _this.isRtl || false);
346346

347347
if (forced || _this.isRtl !== isRtl) {
348-
_this.holder.classList.toggle("ScrollbarsCustom-RTL", isRtl);
349-
350348
_this.isRtl = isRtl;
349+
350+
_this.holder.classList.toggle("ScrollbarsCustom-RTL", _this.isRtl);
351351
}
352352

353353
if (forced) {
354354
var browserScrollbarWidth = (0, _utilities.getScrollbarWidth)(),
355355
fallbackScrollbarWidth = _this.props.fallbackScrollbarWidth;
356356

357357
if (verticalScrollNotBlocked) {
358-
_this.content.style.marginLeft = isRtl ? -(browserScrollbarWidth || fallbackScrollbarWidth) + "px" : null;
359-
_this.content.style.paddingLeft = isRtl ? (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px" : null;
360-
_this.content.style.marginRight = isRtl ? null : -(browserScrollbarWidth || fallbackScrollbarWidth) + "px";
361-
_this.content.style.paddingRight = isRtl ? null : (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px";
358+
_this.content.style.marginLeft = _this.isRtl ? -(browserScrollbarWidth || fallbackScrollbarWidth) + "px" : null;
359+
_this.content.style.paddingLeft = _this.isRtl ? (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px" : null;
360+
_this.content.style.marginRight = _this.isRtl ? null : -(browserScrollbarWidth || fallbackScrollbarWidth) + "px";
361+
_this.content.style.paddingRight = _this.isRtl ? null : (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px";
362+
363+
if (_this.props.defaultStyles) {
364+
_this.trackVertical.style.left = _this.isRtl ? 0 : null;
365+
_this.trackVertical.style.right = _this.isRtl ? null : 0;
366+
}
362367
} else {
363368
_this.content.style.marginLeft = _this.content.style.paddingLeft = _this.content.style.marginRight = _this.content.style.paddingRight = null;
364369
}
@@ -429,7 +434,7 @@ function (_React$Component) {
429434
}, {
430435
key: "componentDidUpdate",
431436
value: function componentDidUpdate(prevProps, prevState, snapshot) {
432-
if (prevProps.noScroll !== this.props.noScroll || prevProps.noScrollY !== this.props.noScrollY || prevProps.noScrollX !== this.props.noScrollX || prevProps.rtl !== this.props.rtl || prevProps.permanentScrollbars !== this.props.permanentScrollbars || prevProps.permanentScrollbarX !== this.props.permanentScrollbarX || prevProps.permanentScrollbarY !== this.props.permanentScrollbarY) {
437+
if (prevProps.noScroll !== this.props.noScroll || prevProps.noScrollY !== this.props.noScrollY || prevProps.noScrollX !== this.props.noScrollX || prevProps.rtl !== this.props.rtl || prevProps.defaultStyles !== this.props.defaultStyles || prevProps.permanentScrollbars !== this.props.permanentScrollbars || prevProps.permanentScrollbarX !== this.props.permanentScrollbarX || prevProps.permanentScrollbarY !== this.props.permanentScrollbarY) {
433438
this.update(true, prevProps.rtl !== this.props.rtl);
434439
}
435440

src/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ export default class Scrollbar extends React.Component
134134
}
135135

136136
componentDidUpdate(prevProps, prevState, snapshot) {
137-
if (prevProps.noScroll !== this.props.noScroll || prevProps.noScrollY !== this.props.noScrollY || prevProps.noScrollX !== this.props.noScrollX || prevProps.rtl !== this.props.rtl
137+
if (prevProps.noScroll !== this.props.noScroll || prevProps.noScrollY !== this.props.noScrollY || prevProps.noScrollX !== this.props.noScrollX
138+
|| prevProps.rtl !== this.props.rtl || prevProps.defaultStyles !== this.props.defaultStyles
138139
|| prevProps.permanentScrollbars !== this.props.permanentScrollbars || prevProps.permanentScrollbarX !== this.props.permanentScrollbarX || prevProps.permanentScrollbarY !== this.props.permanentScrollbarY) {
139140
this.update(true, prevProps.rtl !== this.props.rtl);
140141
}
@@ -526,20 +527,25 @@ export default class Scrollbar extends React.Component
526527
!isset(isRtl) && (isRtl = rtlAutodetect ? getComputedStyle(this.content).direction === "rtl" : this.isRtl || false);
527528

528529
if (forced || this.isRtl !== isRtl) {
529-
this.holder.classList.toggle("ScrollbarsCustom-RTL", isRtl);
530-
531530
this.isRtl = isRtl;
531+
this.holder.classList.toggle("ScrollbarsCustom-RTL", this.isRtl);
532+
532533
}
533534

534535
if (forced) {
535536
const browserScrollbarWidth = getScrollbarWidth(),
536537
fallbackScrollbarWidth = this.props.fallbackScrollbarWidth;
537538

538539
if (verticalScrollNotBlocked) {
539-
this.content.style.marginLeft = isRtl ? -(browserScrollbarWidth || fallbackScrollbarWidth) + "px" : null;
540-
this.content.style.paddingLeft = isRtl ? (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px" : null;
541-
this.content.style.marginRight = isRtl ? null : -(browserScrollbarWidth || fallbackScrollbarWidth) + "px";
542-
this.content.style.paddingRight = isRtl ? null : (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px";
540+
this.content.style.marginLeft = this.isRtl ? -(browserScrollbarWidth || fallbackScrollbarWidth) + "px" : null;
541+
this.content.style.paddingLeft = this.isRtl ? (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px" : null;
542+
this.content.style.marginRight = this.isRtl ? null : -(browserScrollbarWidth || fallbackScrollbarWidth) + "px";
543+
this.content.style.paddingRight = this.isRtl ? null : (browserScrollbarWidth ? null : fallbackScrollbarWidth) + "px";
544+
545+
if (this.props.defaultStyles) {
546+
this.trackVertical.style.left = this.isRtl ? 0 : null;
547+
this.trackVertical.style.right = this.isRtl ? null : 0;
548+
}
543549
}
544550
else {
545551
this.content.style.marginLeft =

0 commit comments

Comments
 (0)