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] Set onChangeCommitted to receive the last argument passed to onChange #44795

Merged

Conversation

good-jinu
Copy link
Contributor

@good-jinu good-jinu commented Dec 17, 2024

Demo: https://codesandbox.io/p/sandbox/nice-ully-k38gjr

The value is determined by the mouse position at the time onChange and onChangeCommitted are called. The discrepancy in the mouse position between the last onChange call and the onChangeCommitted call led to different argument values.

To address this, I've modified onChangeCommitted to always receive the last argument passed to onChange.

Closes #41739

@mui-bot
Copy link

mui-bot commented Dec 17, 2024

Netlify deploy preview

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

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 54073f2

@mnajdova mnajdova added bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module! labels Dec 18, 2024
@mnajdova mnajdova requested a review from mj12albert December 18, 2024 12:25
@mj12albert mj12albert added the package: material-ui Specific to @mui/material label Dec 19, 2024
@good-jinu good-jinu force-pushed the slider-on-change-on-change-committed branch 3 times, most recently from 7e07151 to ab1e076 Compare December 20, 2024 00:55
- Add test case for differing values passed to onChange and onChangeCommitted in Slider
- Set onChangeCommitted callback in Slider to receive the last argument passed to onChange
@good-jinu good-jinu force-pushed the slider-on-change-on-change-committed branch from ab1e076 to 51f1489 Compare December 20, 2024 01:50
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 23, 2024
@good-jinu
Copy link
Contributor Author

Here's the list of devices which reproduce the issue for me.

  • MacBook wireless trackpad
  • Android

Before; with issue

codesandbox

2024-12-20.8.22.19.mov

After; with fix

cosesandbox

2024-12-20.8.26.31.mov

Any review please 🙏
or do I need more description for this?

@ZeeshanTamboli

This comment was marked as outdated.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 1, 2025
@mj12albert
Copy link
Member

Any review please 🙏
or do I need more description for this?

Looks good 👍

Thanks @DiegoAndai as well for finding an easier repro of the case that happens in the CSB iframe - this was the last thing on my mind about this issue - seems the way to repro is to drag the thumb outside the slider (the left edge) before releasing the pointer, then circling back to the slider on the other side (the right edge)

Before:

before.mov

After:

after.mov

Copy link
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

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

Great work @good-jinu 👍

Copy link
Contributor Author

@good-jinu good-jinu left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -1665,4 +1665,38 @@ describe('<Slider />', () => {
width: '10px',
});
});

describe('When the onMouseUp event occurs at a different location than the last onChange event', () => {
it('should pass onChangeCommitted the same value that was passed to the last onChange event', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on my findings, the root cause of this issue is that the last argument passed to onChange is different from the argument passed to onChangeCommitted. This happens when the slider slides fast quickly.

The event flow is as follows:

  1. MouseDown to 10 => onChange(event, 10)
  2. MouseMove to 15 => onChange(event, 15)
  3. MouseUp to 20 => onChangeCommit(event, 20)

I couldn't find any tests for this. So I propose this test case.

@mj12albert mj12albert merged commit d0eed6b into mui:master Jan 3, 2025
19 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: material-ui Specific to @mui/material
Projects
None yet
5 participants