Skip to content

Commit 3e5c5a8

Browse files
committed
Allow negative numbers
1 parent 5b8dbf2 commit 3e5c5a8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
103103
<input type="text" data-range-slider-target="inputMin" value="5">
104104
</div>
105105

106+
<!-- Single Range Slider with Labels, negavtive numbers and markers -->
107+
<div data-controller="range-slider" data-range-slider-values-value="-5..5" data-range-slider-labels-value="true"
108+
data-range-slider-markers-value="true">
109+
<label class="block mb-2 text-sm font-medium text-gray-700">Example of single range slider with
110+
labels and markers</label>
111+
112+
<input type="text" data-range-slider-target="inputMin" value="0">
113+
</div>
114+
106115
<!-- Single Range Slider with Labels and Step -->
107116
<div data-controller="range-slider" data-range-slider-values-value="0..150" data-range-slider-labels-value="true"
108117
data-range-slider-step-value="10">

src/range_slider.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,8 @@ export default class extends Controller {
452452
parseRange(min, max, step) {
453453
if (!max || !step) return null;
454454

455-
return Array.from(
456-
{ length: Math.ceil((max - min + 1) / step) },
457-
(_, i) => min + i * step
458-
);
455+
const count = Math.floor((max - min) / step) + 1;
456+
return Array.from({ length: count }, (_, i) => min + i * step);
459457
}
460458

461459
createElement(el, klass, dataAttr) {

0 commit comments

Comments
 (0)