Skip to content

Commit 67741ba

Browse files
authored
Slider - adjust the thumb position more smoothly (#1873)
1 parent ccfbf24 commit 67741ba

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/components/slider/index.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,9 @@ export default class Slider extends PureComponent<SliderProps, State> {
302302
if (this.thumb) {
303303
const {disableRTL} = this.props;
304304
const {trackSize} = this.state;
305-
const _x = Constants.isRTL && disableRTL ? trackSize.width - x : x;
306-
const position = _x - this.initialThumbSize.width / 2;
307-
const deviation = 3;
308-
309-
if (position + deviation < 0) {
310-
this._thumbStyles.left = 0;
311-
} else if (position - deviation > trackSize.width - this.initialThumbSize.width) {
312-
this._thumbStyles.left = trackSize.width - this.initialThumbSize.width;
313-
} else {
314-
this._thumbStyles.left = position;
315-
}
316-
305+
const nonOverlappingTrackWidth = trackSize.width - this.initialThumbSize.width;
306+
const _x = Constants.isRTL && disableRTL ? nonOverlappingTrackWidth - x : x; // adjust for RTL
307+
this._thumbStyles.left = trackSize.width === 0 ? _x : (_x * nonOverlappingTrackWidth) / trackSize.width; // do not render above prefix\suffix icon\text
317308
this.thumb.setNativeProps(this._thumbStyles);
318309
}
319310

0 commit comments

Comments
 (0)