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][base][material][joy] Fix not draggable on the edge when disableSwap={true} #35998

Merged
merged 20 commits into from
Jun 27, 2023

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jan 30, 2023

@mui-bot
Copy link

mui-bot commented Jan 30, 2023

Netlify deploy preview

https://deploy-preview-35998--material-ui.netlify.app/

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 0bfb2eb

@ZeeshanTamboli
Copy link
Member

For more context, see #25547

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 30, 2023

For more context, see #25547

got it, i'll fix it. according to this comment values should not be displayed on hover and that is missing in this PR #25547 (review).

@sai6855 sai6855 marked this pull request as draft January 31, 2023 10:56
@sai6855
Copy link
Contributor Author

sai6855 commented Feb 2, 2023

I'm kind of stuck here, According to this comment (#25547 (review)) When disableSwap is true, thumbs shouldn't show the value on hover, pointer-events: none is used to achieve this behavior, but pointer-events: none is making slider thumb undruggable when the thumb is at the edge.

I tried to make the thumb draggable and hide values on hover but couldn't do it without making significant changes. I guess only one of the behavior is achievable here.

@sai6855 sai6855 marked this pull request as ready for review February 2, 2023 14:28
@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] Fix Slider not draggable on disableSwap [Slider] Fix Slider not draggable on edges on disableSwap Feb 3, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] Fix Slider not draggable on edges on disableSwap [Slider] Fix Slider not draggable on edges when disableSwap Feb 3, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] Fix Slider not draggable on edges when disableSwap [Slider] Fix Slider not draggable on the edge when disableSwap Feb 3, 2023
@ZeeshanTamboli
Copy link
Member

@oliviertassinari Do you have any context to share on this?

@zannager zannager added the component: slider This is the name of the generic UI component, not the React module! label Feb 3, 2023
@oliviertassinari oliviertassinari changed the title [Slider] Fix Slider not draggable on the edge when disableSwap [Slider] Fix not draggable on the edge when disableSwap={true} Feb 5, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 5, 2023

I would go one step beyond:

diff --git a/packages/mui-material/src/Slider/Slider.js b/packages/mui-material/src/Slider/Slider.js
index 262741a6eb..9a06641a65 100644
--- a/packages/mui-material/src/Slider/Slider.js
+++ b/packages/mui-material/src/Slider/Slider.js
@@ -765,7 +765,8 @@ const Slider = React.forwardRef(function Slider(inputProps, ref) {
                 })}
                 style={{
                   ...style,
-                  pointerEvents: disableSwap && active !== index ? 'none' : undefined,
+                  // So the non active thumb doesn't show its label on hover.
+                  pointerEvents: active !== -1 && active !== index ? 'none' : undefined,
                   ...thumbProps.style,
                 }}
               >

I think that the current UX is broken, how does it make sense to see the label here?

Screen.Recording.2023-02-05.at.19.54.01.mov

https://mui.com/material-ui/react-slider/#range-slider

@@ -281,7 +282,6 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled<
})}
style={{
...style,
pointerEvents: disableSwap && active !== index ? 'none' : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this logic not inside getThumbProps() of useSlider? It seems that we have to fix 3 different places at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Feb 5, 2023
@sai6855 sai6855 requested review from ZeeshanTamboli and removed request for michaldudak February 13, 2023 10:50
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 22, 2023
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.

Why was this change not done in getThumbProps as pointed out by Olivier? We anyway provide there a style object that needs to be spreaded. Should we extend the getThumbProps to receive additional state other then event handlers? cc @michaldudak for thoughts.

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Feb 22, 2023

Why was this change not done in getThumbProps as pointed out by Olivier? We anyway provide there a style object that needs to be spreaded. Should we extend the getThumbProps to receive additional state other then event handlers?

It was done in 2e8d009, but it didn't look correct with style being callable. So I suggested a way in #35998 (comment) to access the index in hook, but thought it won't be worth it because of the computation involved.

@mnajdova
Copy link
Member

It was done in 2e8d009, but it didn't look correct with style being callable. So I suggested a way in #35998 (comment) to access the index in hook, but thought it won't be worth it because of the computation involved.

I now it was done, this is why I mentioned it again. We can provide an additional function in the useSlider hook either as a direct prop, or as part of the result of getThumbProps for calculating the thumb's style prop. cc @michaldudak for recommending which one would be preferred.

@CatchGus
Copy link

CatchGus commented Mar 30, 2023

What is the status of this PR? Can it be merged?

Currently manually overwriting styles to get this to work.

const CustomSlider = styled(Slider)({
  "& .MuiSlider-thumb": {
    pointerEvents: "auto!important",
  },
});

@siriwatknp siriwatknp added the on hold There is a blocker, we need to wait label Apr 4, 2023
@siriwatknp
Copy link
Member

put on hold here to wait for @mnajdova question.

@sai6855 sai6855 requested a review from michaldudak April 4, 2023 07:31
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 24, 2023
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 29, 2023
@michaldudak
Copy link
Member

@mnajdova @sai6855 From the point of view of the useSlider hook, the most elegant to me would be to have getThumbProps(index). But this would not play nicely with useSlotProps and require custom implementation in all the styled libraries.
That's why having a getThumbStyle(index) function returned by useSlider seems to be a better option.

@sai6855
Copy link
Contributor Author

sai6855 commented Jun 21, 2023

@michaldudak added getThumbStyle in the return value of useSlider hook

@ZeeshanTamboli ZeeshanTamboli added package: material-ui Specific to @mui/material package: base-ui Specific to @mui/base package: joy-ui Specific to @mui/joy and removed on hold There is a blocker, we need to wait labels Jun 23, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] Fix not draggable on the edge when disableSwap={true} [Slider][base][material][joy] Fix not draggable on the edge when disableSwap={true} Jun 27, 2023
@ZeeshanTamboli
Copy link
Member

Looks good!

@ZeeshanTamboli ZeeshanTamboli merged commit 1aa3205 into mui:master Jun 27, 2023
21 checks passed
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! package: base-ui Specific to @mui/base package: joy-ui Specific to @mui/joy package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[base][Slider] Not draggable on the edge when disableSwap={true}
9 participants