Skip to content

Commit d0bf770

Browse files
authored
Fix/reenable allow overlap for large sliders (ptomasroos#209)
* fix: Reenable allowOverlap for large sliders If your slider goes from, let's say, 0 to 10: - `this.optionsArray = [0, 1, ... 10];` => its length is 11 - however, `this.props.sliderLength` should only be divided by 10 (representing the 10 sections `0-1`, `1-2`, ..., `9-10`) The fix is then simply to replace L56 by ` this.stepLength = this.props.sliderLength / (this.optionsArray.length - 1);` * docs: Explicit the unit used by minMarkerOverlapDistance for more clarity One could think it was about steps
1 parent b494955 commit d0bf770

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

MultiSlider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class MultiSlider extends React.Component {
5454
this.optionsArray =
5555
this.props.optionsArray ||
5656
createArray(this.props.min, this.props.max, this.props.step);
57-
this.stepLength = this.props.sliderLength / this.optionsArray.length;
57+
this.stepLength = this.props.sliderLength / (this.optionsArray.length - 1);
5858

5959
var initialValues = this.props.values.map(value =>
6060
valueToPosition(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ Feel free to contribute to this part of the documentation.
9999
| markerOffsetX | 0 | number | Offset the cursor(s) on the X axis |
100100
| markerOffsetY | 0 | number | Offset the cursor(s) on the Y axis |
101101
| markerSize | 0 | number | It determines the marker margin from the edges of the track, useful to avoid the markers to overflow out of the track. |
102-
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other. This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. |
102+
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. |
103103
| imageBackgroundSource | undefined | string | Specifies the source as required by [ImageBackground](https://facebook.github.io/react-native/docs/imagebackground)|

0 commit comments

Comments
 (0)