Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] RangeSlider maxRange Property #2998

Merged
merged 2 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@
.idea/
.vscode/
.nova/
.gitpod.yml

# node
node_modules/
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/core/Tabs.mdx
Expand Up @@ -47,7 +47,7 @@ function Demo() {

## Uncontrolled Tabs

If you do need to subscribe to Tabs state changes use `defaultValue`:
If you do not need to subscribe to Tabs state changes use `defaultValue`:

```tsx
import { Tabs } from '@mantine/core';
Expand Down
12 changes: 12 additions & 0 deletions src/mantine-core/src/Slider/RangeSlider/RangeSlider.tsx
Expand Up @@ -45,6 +45,9 @@ export interface RangeSliderProps
/** Minimal range interval */
minRange?: number;

/** Maximum range interval */
maxRange?: number;

/** Number by which value will be incremented/decremented with thumb drag and arrows */
step?: number;

Expand Down Expand Up @@ -141,6 +144,7 @@ export const RangeSlider = forwardRef<HTMLDivElement, RangeSliderProps>((props,
min,
max,
minRange,
maxRange,
step,
precision,
defaultValue,
Expand Down Expand Up @@ -206,6 +210,10 @@ export const RangeSlider = forwardRef<HTMLDivElement, RangeSliderProps>((props,
if (val > (max - (minRange - 0.000000001) || min)) {
clone[index] = valueRef.current[index];
}

if (clone[1] - val > maxRange) {
clone[1] = val + maxRange;
}
}

if (index === 1) {
Expand All @@ -216,6 +224,10 @@ export const RangeSlider = forwardRef<HTMLDivElement, RangeSliderProps>((props,
if (val < clone[0] + minRange) {
clone[index] = valueRef.current[index];
}

if (val - clone[0] > maxRange) {
clone[0] = val - maxRange;
}
}

_setValue(clone);
Expand Down
15 changes: 15 additions & 0 deletions src/mantine-core/src/Slider/Slider.story.tsx
Expand Up @@ -73,3 +73,18 @@ export function MinRangeWithNegativeValues() {
</div>
);
}

export function MinMaxSliderDistance() {
return (
<div style={{ maxWidth: 400, padding: 40 }}>
<RangeSlider
min={0}
max={100}
minRange={5}
maxRange={20}
step={0.5}
defaultValue={[0, 100]}
/>
</div>
);
}