Skip to content

Conversation

@DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Jun 19, 2023

Material Next Slider issue: #37527

Summary

This PR implements improvements that required a restructuring of the Slider Thumb and Value Label structure. The original PR introducing material-next's Slider is #37520

The improvements are:

Thumb restructure

Address this comment. Restructure the Thumb and value label to a simpler structure, like the one in Joy's Slider. This removes the need for a separate ValueLabel component and types file, so those were removed.

Thumb and value label overlap

Implement the overlap border specification from Material You.

To do so I introduced the useSliderElementsOverlap hook that handles the logic of detecting overlaps for thumbs and value labels.

Screen.Recording.2023-06-19.at.14.22.47.mov

@mui-bot
Copy link

mui-bot commented Jun 19, 2023

Netlify deploy preview

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

@mui/material-next: parsed: +57.44% , gzip: +59.19%

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 6ad5568

@DiegoAndai DiegoAndai marked this pull request as ready for review June 26, 2023 22:06
@DiegoAndai DiegoAndai requested a review from mnajdova June 26, 2023 22:06
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.

Overall it looks great! Left some comments for improvements.

import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';

function getSliderElementsOverlap(elements: HTMLElement[], axis: Axis, margin: number) {
if (elements.length === 2) {
Copy link
Member

Choose a reason for hiding this comment

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

if we accept an array, let's make the hook considering all elements in the array, it shouldn't be much change.

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 agree! But rather than considering all elements, I modified it to only accept two at most. I think this makes more sense as the slider thumb and value label elements should be two at most as well.

@DiegoAndai
Copy link
Member Author

Hey @mnajdova, thanks for the review! I addressed your comments and also I added the v6 components migration guide, that way we can begin documenting breaking changes alongside PRs, with this PR introducing the first.

@DiegoAndai DiegoAndai requested a review from mnajdova June 29, 2023 21:20
@@ -0,0 +1,38 @@
# Breaking changes in v6: core components
Copy link
Member

Choose a reason for hiding this comment

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

Instead of page, can we please add readme file in the @mui/material-next package? Maybe with name migration.md next to readme. We can add info in the readme, that they should follow the migraiton.md guidelines.

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.

The changes look good to me, I left one suggestion for the migration location, as we anyway don't want to add a page on the docs just yet. @DavidCnoops can you review the design-related changes?

@DavidCnoops DavidCnoops self-requested a review July 3, 2023 14:39
Copy link
Contributor

@DavidCnoops DavidCnoops left a comment

Choose a reason for hiding this comment

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

Overall this looks really good to me! It's a great solution to a tricky UI problem.

I have one very tiny nitpick: when valueLabelDisplay is set to auto and the 2 thumbs/values are about to overlap, the underlying value very briefly pops up. Also, when sliding the upper thumb over the lower one (i.e. when they completely overlap) its value seems to briefly disappear. It's -extremely- subtle so definitely not a big or blocking issue, but a 100% perfect solution would be to keep the lower value constantly hidden and the upper value constantly visible.

slider.webm

@DiegoAndai DiegoAndai force-pushed the material-you-slider-restructure branch from 960fdba to 91b6a95 Compare July 3, 2023 15:25
@DiegoAndai DiegoAndai force-pushed the material-you-slider-restructure branch from 91b6a95 to b166d5f Compare July 3, 2023 15:28
@DiegoAndai DiegoAndai added the breaking change Introduces changes that are not backward compatible. label Jul 3, 2023
@DiegoAndai
Copy link
Member Author

Hey @DavidCnoops! thanks for reviewing 😊

What you reported was indeed a bug:

  • The active thumb's z-index should be higher than the other thumb to avoid the inactive one triggering hover states when dragging the active one, this fixes the "about to overlap issue"
  • The transform animation should be disabled for the value label when dragging the thumb, this fixes the "briefly disappear when overlapping" issue

Thanks for catching the issues 🚀

@DiegoAndai DiegoAndai requested a review from mnajdova July 3, 2023 16:52
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.

We have a demo of a Slider with three thumbs - http://localhost:3000/material-ui/react-slider/#removed-track, also as far as I remember we updated the Base UI Slider and useSlider to support more than two thumbs. I would propose making this scenario works too.

@DiegoAndai
Copy link
Member Author

DiegoAndai commented Jul 5, 2023

Hey @mnajdova thanks for the feedback, I included your changes in the last commit:

  • Improve naming and code structure in the useSliderElementsOverlap.ts file
  • Support more than 2 values for the overlap style
  • Added debounce function to onThumbMoved callback to reduce unnecessary overlap calculation. I tested and a debounce of 50ms felt the best UX-wise while also reducing the calculations by a factor of 10.

@DiegoAndai DiegoAndai force-pushed the material-you-slider-restructure branch from f7f27c7 to 6ad5568 Compare July 5, 2023 19:10
@DiegoAndai DiegoAndai requested a review from mnajdova July 5, 2023 19:27
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.

Looks much better 👍 I would recommend for PRs that include fixes like this to share a codesandbox for easily verifying the fix. It would help a lot with the reviews :)

@DiegoAndai DiegoAndai merged commit f3bdfbd into mui:master Jul 10, 2023
@DiegoAndai DiegoAndai deleted the material-you-slider-restructure branch July 10, 2023 15:15
@DiegoAndai DiegoAndai added v7.x and removed v6.x labels Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. design: material you scope: slider Changes related to the slider. v7.x

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants