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

[docs][material-ui] Slider in color customization playground twitches when sliding #42019

Open
yassinmars opened this issue Apr 25, 2024 · 4 comments
Assignees
Labels
docs Improvements or additions to the documentation package: material-ui Specific to @mui/material

Comments

@yassinmars
Copy link

yassinmars commented Apr 25, 2024

Steps to reproduce

Link to live example: (required)

slider.problem.issue.mp4

Steps:
1.Go to Settings
2.Click on "Edit documentation colors"
3.Slide the toggle from left to right.
4.Observe the behavior as it passes the 100 and 50 marks and the marks after that.

Current behavior

When sliding the Slider component's toggle from left to right, a noticeable twitch occurs around the 100 and 50 marks.
The marks for A700 and A400 are not displayed when the slider moves from left to right.
These issues do not occur when sliding from right to left.

Expected behavior

The Slider should move smoothly without any twitching at any point along the track.
All marks, including A700 and A400, should be visible when sliding from left to right.

Context

I am attempting to provide a seamless user experience when using the slider. This twitching effect is causing confusion and a less satisfactory user interaction.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: Slider, twitch, A700, A400, marks, animation issue

@yassinmars yassinmars added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 25, 2024
@yassinmars yassinmars changed the title Slider component twitching near 100 and 50 marks and A700/A400 marks not visible when sliding [material-ui]Slider component twitching near 100 and 50 marks and A700/A400 marks not visible when sliding Apr 25, 2024
@yassinmars yassinmars changed the title [material-ui]Slider component twitching near 100 and 50 marks and A700/A400 marks not visible when sliding [material-ui] Slider component twitching near 100 and 50 marks and A700/A400 marks not visible when sliding Apr 25, 2024
@zannager zannager added component: slider This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Apr 25, 2024
@mj12albert
Copy link
Member

Thanks for reporting this - I think this could be an issue with the playground and not the Slider component itself, as it doesn't repro in the Slider demos here

The component for the playground is here - would you be interested in investigating this further? @yassinmars

@mj12albert mj12albert changed the title [material-ui] Slider component twitching near 100 and 50 marks and A700/A400 marks not visible when sliding [docs][material-ui] Slider in color customization playground twitches when sliding Apr 29, 2024
@mj12albert mj12albert added docs Improvements or additions to the documentation and removed component: slider This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 29, 2024
@yassinmars
Copy link
Author

Thank you for your response and guidance @mj12albert - yes absolutely i would like to investigate the issue further, i have already located the code for the playground and I'm currently looking through it to pinpoint the exact cause of the twitching issue. I'll share my findings as soon as I have something concrete.

@yassinmars
Copy link
Author

@mj12albert, I believe I've identified potential areas that could be causing the twitching issue with the Slider component. Here are my key observations:

-State Management in handleChangeShade:
This function updates several state variables simultaneously ([name]Shade, [name], and [name]Input). The frequency and scope of these updates might be causing the component to rerender inefficiently, leading to the twitching observed, particularly near the 100 and 50 marks. Here's code for reference:

image

-Dynamic Styling Calculations:
The Slider's sx property involves dynamic calculations that might be affecting its rendering performance. Reducing complexity in these style calculations could potentially improve performance. Here’s the relevant code:

image

I'm currently exploring optimizations in the handleChangeShade function to reduce the number of state updates and simplify the dynamic style calculations. These changes might help in achieving smoother interactions with the Slider.

@yassinmars
Copy link
Author

@mj12albert, I've implemented several optimizations based on the initial observation to address the issue. Here are the changes and the solutions i came up with:

  1. Optimized State Management in handleChangeShade:

I refactored the handleChangeShade function to minimize the number of state updates and potential re-renders. By consolidating the state updates into a single setState call, we reduce the overhead and improve the slider's responsiveness. Here's the revised code snippet:

image

  1. Simplified and Improved Slider Styling:

To further enhance performance, I simplified the Slider's dynamic styling by moving the style calculations outside of the component render method. This approach minimizes recalculations and leverages CSS for better performance. The updated styling I applied is as follows:

image

  1. Integrated Changes within colorPicker Function:

I ensured that these changes were integrated smoothly within the colorPicker function, keeping in mind the overall component structure and existing functionality. The focus was on ensuring that the modifications did not introduce any new issues or regressions.
Here's how the modified section looks now:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

3 participants