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] Replace SliderUnstyled with useSlider hook #35770

Conversation

ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli commented Jan 9, 2023

Motivation:

See #35398.


Move the logic of valueLabelDisplay prop to Material UI. To do this, we migrate the Material UI Slider component to use useSlider hook to get access to the states. This has the advantage of how the Slider's component structure is rendered by Material UI. We are able to have the valueLabelDisplay logic controlled which is not needed in MUI Base and does not work as expected there. We also create the SliderValueLabel component in Material UI for value label.

We also did this since Material UI's Slider was dependent on SliderUnstyled and there are changes (improvements) in SliderUnstyled in ZeeshanTamboli#2.

The JSX structure is kept intact like the SliderUnstyled.

There should be no breaking changes.

Previously created PR: #35479 where we decided to split it in two PRs.

Follow up PR: ZeeshanTamboli#2

@ZeeshanTamboli ZeeshanTamboli added component: slider This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature labels Jan 9, 2023
@mui-bot
Copy link

mui-bot commented Jan 9, 2023

Messages
📖 Netlify deploy preview: https://deploy-preview-35770--material-ui.netlify.app/

@material-ui/core: parsed: -0.17% 😍, gzip: -0.19% 😍

Details of bundle changes

Generated by 🚫 dangerJS against 018c2a9

@ZeeshanTamboli ZeeshanTamboli added the package: material-ui Specific to @mui/material label Jan 9, 2023
@ZeeshanTamboli ZeeshanTamboli marked this pull request as ready for review January 9, 2023 10:19
Signed-off-by: Zeeshan Tamboli <zeeshan.tamboli@gmail.com>
packages/mui-material/src/Slider/SliderValueLabel.tsx Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/SliderValueLabel.tsx Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.js Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.js Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/SliderValueLabel.tsx Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/SliderValueLabel.tsx Outdated Show resolved Hide resolved
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment, I will test out later/tomorrow and provide the final review. Overall looks good 👍

packages/mui-material/src/Slider/SliderValueLabel.types.ts Outdated Show resolved Hide resolved
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! I do have one comment, but aside from that is looks great.

},
ownerState: {
...ownerState,
...rootSlotProps?.ownerState,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what could be the use case for providing ownerState in slotProps.*. I can't think of any scenarios that would require overriding the state, so if you have anything in mind, please share.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have anything in mind or a use case in mind. I had wondered the same while adding this. I later thought that I didn't want to introduce any breaking changes, so let's keep it.

I don't quite know the context of why it was added. We can remove it in v6.

@ZeeshanTamboli
Copy link
Member Author

@michaldudak Ready for further review.

@ZeeshanTamboli ZeeshanTamboli merged commit 69edfae into mui:master Jan 12, 2023
@ZeeshanTamboli ZeeshanTamboli deleted the slider/replace-SliderUnstyled-with-useSlider-hook branch January 12, 2023 07:08
>
<ThumbSlot
data-index={index}
data-focusvisible={focusedThumbIndex === index}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this data-focusvisible attribute for? It doesn't seem used anywhere. I see that it was added in https://github.com/mui/material-ui/pull/33132/files#diff-975fc00fa1f3f65ac56ee8a55c1b67cb95fc72bf7dcfa6669ffd3f3dc4ef6b74R269.

I believe that we already have a class name for this problem .Mui-focusVisible, so better maximum the learning transferability between components.

Suggested change
data-focusvisible={focusedThumbIndex === index}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Looks unnecessarily added. Created PR: #36091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: slider This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants