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

[Slider] Warn when min is not less than max #1475

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

mj12albert
Copy link
Member

Fixes #1471

Log a console warning when min is not less than max and don't update the state. When min/max are the same something divides by zero internally and causes a loop.

@mj12albert mj12albert added component: slider This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work labels Feb 24, 2025
Copy link

netlify bot commented Feb 24, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit ee64d55
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67c016dfc0ff940008a6ee4c
😎 Deploy Preview https://deploy-preview-1475--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mj12albert mj12albert changed the title [Slider] Handle min not less than max [Slider] Warn when min is not less than max Feb 25, 2025
@mj12albert mj12albert marked this pull request as ready for review February 25, 2025 06:27
@mj12albert
Copy link
Member Author

https://codesandbox.io/p/sandbox/slider-bug-min-and-max-the-same-forked-kz8xgy

It doesn't crash and logs a warning, I think this should be enough

@michaldudak
Copy link
Member

I can imagine a case where the min/max values are set based on some state set in other parts of the application (i.e., not hardcoded), and with certain conditions, the Slider could allow just a single value. IMO we should support such a scenario.

@mj12albert
Copy link
Member Author

mj12albert commented Feb 25, 2025

with certain conditions, the Slider could allow just a single value

All we could do differently though is not warn if min/max/value are the same? If min/max/value are all the same, it's still not possible to determine a position on the track @michaldudak

@mj12albert mj12albert force-pushed the fix/slider-invalid-bounds branch from 7da0a5b to ee64d55 Compare February 27, 2025 07:40
@michaldudak
Copy link
Member

Yeah, ignore what I wrote. For some reason I thought min/max restricts the slider position within the track (that the track renders the full range, but you're not allowed to slide the thumb across the whole track).

@mj12albert mj12albert merged commit b0defb4 into mui:master Feb 27, 2025
22 checks passed
@mj12albert mj12albert deleted the fix/slider-invalid-bounds branch February 27, 2025 12:46
atomiks pushed a commit to atomiks/base-ui that referenced this pull request Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Slider] Maximum depth exceeded bug when min and max is 1
2 participants