-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Narrow onChange value type #44777
base: master
Are you sure you want to change the base?
Conversation
- Change value and onChange value param type from `number | number[]` to generic `Value`
Netlify deploy previewhttps://deploy-preview-44777--material-ui.netlify.app/ Bundle size reportBundle size will be reported once CircleCI build #782215 finishes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@good-jinu Looks good. Can you add a type test in Slider.spec.tsx
file?
No work was done on the code snippets in the docs.
We need to update the type in demos. For example in ContinuousSlider demo:
--- a/docs/data/material/components/slider/ContinuousSlider.tsx
+++ b/docs/data/material/components/slider/ContinuousSlider.tsx
@@ -8,8 +8,8 @@ import VolumeUp from '@mui/icons-material/VolumeUp';
export default function ContinuousSlider() {
const [value, setValue] = React.useState<number>(30);
- const handleChange = (event: Event, newValue: number | number[]) => {
- setValue(newValue as number);
+ const handleChange = (event: Event, newValue: number) => {
+ setValue(newValue);
};
return (
Same in other demos.
Thanks for your specific comment! @ZeeshanTamboli |
- Change value and onChange value param type from `number | number[]` to generic `Value`
03024f7
to
8acb178
Compare
… into slider-value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@good-jinu I have pushed few commits to cleanup the code. But there's an issue. The component
prop is no longer available on Slider after removing OverridableComponent
type from the Slider type. It should be available. Additionally, TypeScript doesn't catch arbitrary props, allowing any prop without error detection.
PR CodeSandbox: https://codesandbox.io/p/sandbox/material-ui-cra-ts-forked-zm74j4
Master: https://codesandbox.io/p/sandbox/material-ui-cra-ts-forked-4ch62x
Thanks for working on this @good-jinu. This is a difficult problem, we've tried to solve it a couple of times in the past, so expect more back and forth than usual PRs. As additional context, Base UI has not implemented this: https://github.com/mui/base-ui/blob/master/packages/react/src/slider/root/useSliderRoot.ts. It makes me wonder if we should do it, given that we're going to use Base UI soon. @aarongarciah what do you think? |
Thank you @DiegoAndai for providing the context! This issue turned out to be more complex and challenging than I initially thought. As you mentioned, if we resolve this problem using Base UI, I hope a better solution will emerge in the future instead of this PR. |
number | number[]
to genericValue
Closes #37854
Inspired by #38753
What's different from PR #38753