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] onChange handler should be called only when value has changed #36706

Merged
merged 10 commits into from
Apr 20, 2023
Merged

[Slider] onChange handler should be called only when value has changed #36706

merged 10 commits into from
Apr 20, 2023

Conversation

gitstart
Copy link
Contributor

Description

Fixing handleChange being called even when value remains the same.

Closes #36614


This code was written and reviewed by GitStart Community. Growing great engineers, one PR at a time.

@mui-bot
Copy link

mui-bot commented Mar 30, 2023

Netlify deploy preview

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

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against f6ad0af

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 would need to update the two failing tests, as the event handlers are now not being invoked because of the change. We can set the value prop to some other initial value.

@@ -224,6 +224,12 @@ export default function useSlider(parameters: UseSliderParameters): UseSliderRet
name: 'Slider',
});

const isValueUnchanged = (newValue: number | Array<number>): boolean => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isValueUnchanged = (newValue: number | Array<number>): boolean => {
const areValuesEqual = (oldValue: number | Array<number>, newValue: number | Array<number>): boolean => {

Let's rename the util, it has negation in the name, and we use another negation when invoking. Also, let's change the signature and move it outside of the component.

Copy link
Contributor Author

@gitstart gitstart Apr 12, 2023

Choose a reason for hiding this comment

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

This has been implemented, please check again.

@gitstart gitstart marked this pull request as ready for review April 12, 2023 14:36
@gitstart
Copy link
Contributor Author

We would need to update the two failing tests, as the event handlers are now not being invoked because of the change. We can set the value prop to some other initial value.

Thanks for the suggestion @mnajdova, the tests are passing now.

@gitstart gitstart requested a review from mnajdova April 12, 2023 14:37
@zannager zannager added the component: slider This is the name of the generic UI component, not the React module! label Apr 13, 2023
@zannager zannager requested a review from ZeeshanTamboli April 13, 2023 06:32
@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] enable handleChange to be called only when value has changed [Slider] Fix onChange handler to be called only when value has changed Apr 19, 2023
@ZeeshanTamboli ZeeshanTamboli added the bug 🐛 Something doesn't work label Apr 19, 2023
packages/mui-base/src/useSlider/useSlider.ts Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.test.js Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.test.js Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.test.js Outdated Show resolved Hide resolved
packages/mui-material/src/Slider/Slider.test.js Outdated Show resolved Hide resolved
@gitstart gitstart requested a review from ZeeshanTamboli April 19, 2023 18:46
@gitstart
Copy link
Contributor Author

@ZeeshanTamboli your comments have been implemented, please check again.

@gitstart gitstart requested a review from ZeeshanTamboli April 20, 2023 10:52
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the work, @gitstart!

@ZeeshanTamboli ZeeshanTamboli changed the title [Slider] Fix onChange handler to be called only when value has changed [Slider] onChange handler should be called only when value has changed Apr 20, 2023
@ZeeshanTamboli ZeeshanTamboli merged commit 614cae5 into mui:master Apr 20, 2023
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Slider] onChange being called when value is not changing
5 participants