Skip to content

Commit 732650d

Browse files
committed
add option for "pushy" ranges
- allows selected range handle to "push" the dormant one along if it goes past the value of the dormant handle
1 parent 0087ca9 commit 732650d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ prop | type | default | description
8787
**max** | `Number` | `100` | Maximum value for the slider
8888
**step** | `Number` | `1` | Every `nth` value to allow handle to stop at
8989
**range** | `Boolean`/`String` | `false` | Whether to style as a range picker. Use `range='min'` or `range='max'` for min/max variants
90+
**pushy** | `Boolean` | `false` | If `range` is `true`, then this boolean decides if one handle will push the other along
9091
**float** | `Boolean` | `false` | Set true to add a floating label above focussed handles
9192
**vertical** | `Boolean` | `false` | Make the slider render vertically
9293
**pips** | `Boolean` | `false` | Whether to show pips/notches on the slider

src/RangeSlider.svelte

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
// range slider props
66
export let range = false;
7+
export let pushy = false;
78
export let min = 0;
89
export let max = 100;
910
export let step = 1;
@@ -269,12 +270,22 @@
269270
* @return {number} the value that was moved to (after alignment/clamping)
270271
**/
271272
function moveHandle(index, value) {
273+
if (range) {
272274
// restrict the handles of a range-slider from
273-
// going past one-another
274-
if (range && index === 0 && value > values[1]) {
275+
// going past one-another unless "pushy" is true
276+
if (index === 0 && value > values[1]) {
277+
if (pushy) {
278+
values[1] = value;
279+
} else {
275280
value = values[1];
276-
} else if (range && index === 1 && value < values[0]) {
281+
}
282+
} else if (index === 1 && value < values[0]) {
283+
if (pushy) {
284+
values[0] = value;
285+
} else {
277286
value = values[0];
287+
}
288+
}
278289
}
279290
// set the value for the handle, and align/clamp it
280291
values[index] = value;

test/src/App.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
let day = [3];
77
let hue = [244];
88
let dynamic = [0,50];
9+
let pushy = [30,60]
910
const formatter = v => {
1011
return num.format(v);
1112
};
@@ -65,7 +66,8 @@
6566
<RangeSlider float pips first="label" last="label" />
6667
<RangeSlider float pips first="label" last="label" rest="label" />
6768
<br>
68-
<RangeSlider range values={[35,65]} pips all="label" float />
69+
<RangeSlider range bind:values={pushy} float />
70+
<RangeSlider range pushy bind:values={pushy} pips all="label" float />
6971
<RangeSlider range="min" values={[65]} pips all="label" float />
7072
<RangeSlider range="max" values={[35]} pips all="label" float />
7173
<br>

0 commit comments

Comments
 (0)