Skip to content

Commit

Permalink
[@mantine/core] RangeSlider: Fix incorrect minRange handling for nega…
Browse files Browse the repository at this point in the history
…tive values (#2897)
  • Loading branch information
rtivital committed Nov 12, 2022
1 parent d1e2519 commit 1fd3f3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/mantine-core/src/Slider/RangeSlider/RangeSlider.tsx
Expand Up @@ -199,11 +199,11 @@ export const RangeSlider = forwardRef<HTMLDivElement, RangeSliderProps>((props,
clone[index] = val;

if (index === 0) {
if (val > clone[1] - minRange) {
if (val > clone[1] - (minRange - 0.000000001)) {
clone[1] = Math.min(val + minRange, max);
}

if (val > (max - minRange || min)) {
if (val > (max - (minRange - 0.000000001) || min)) {
clone[index] = valueRef.current[index];
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/mantine-core/src/Slider/Slider.story.tsx
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Slider } from './index';
import { Slider, RangeSlider } from './index';

export default { title: 'Slider' };

Expand Down Expand Up @@ -65,3 +65,11 @@ export function DecimalValues() {
</div>
);
}

export function MinRangeWithNegativeValues() {
return (
<div style={{ maxWidth: 400, padding: 40 }}>
<RangeSlider min={-10} max={10} defaultValue={[-10, 0]} />
</div>
);
}

0 comments on commit 1fd3f3f

Please sign in to comment.