Skip to content

[pickers] Always use props.value as the source of truth when defined #16853

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

Merged
merged 11 commits into from
Mar 17, 2025

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Mar 7, 2025

Closes #15530
Follow up on #15875

@flaviendelangle flaviendelangle self-assigned this Mar 7, 2025
@flaviendelangle flaviendelangle added regression A bug, but worse component: pickers This is the name of the generic UI component, not the React module! labels Mar 7, 2025
@flaviendelangle flaviendelangle force-pushed the picker-value-controlled branch from bf91819 to 37abb52 Compare March 7, 2025 08:36
@mui-bot
Copy link

mui-bot commented Mar 7, 2025

Deploy preview: https://deploy-preview-16853--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 4603890

@flaviendelangle flaviendelangle force-pushed the picker-value-controlled branch from d7aec39 to 7714139 Compare March 7, 2025 14:05
@flaviendelangle flaviendelangle changed the title [pickers] Always use props.value as the source of truth when defined [pickers] Always use props.value as the source of truth when defined Mar 10, 2025
@flaviendelangle flaviendelangle force-pushed the picker-value-controlled branch from 804a8f1 to 1977df2 Compare March 11, 2025 06:54
@flaviendelangle flaviendelangle marked this pull request as ready for review March 11, 2025 07:06
@flaviendelangle flaviendelangle requested a review from LukasTy March 11, 2025 07:06
Copy link
Member

@LukasTy LukasTy 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! 👏 💙
Thank you for taking care of it. 🙏

I've updated my example with use cases that I checked in the original (fields) related PR.
Everyhing seems to check out. 👌

onError: props.onError,
});

const timezoneFromDraftValue = valueManager.getTimezone(utils, state.draft);
if (previousTimezoneProp !== timezoneProp) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice cleanup allowed by refactor. 🙌 💙

if (selectionState === 'shallow') {
setState((prev) => ({
...prev,
draft: newValue,
clockShallowValue: newValue,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah... The Time Clock could really use a value management refactor. 🙈
Now, its behavior has to be "declared" in the common state management. 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK, the only reason why we can't just keep those "shallow" value inside the clock state, is to update the value in the toolbar while dragging, but without calling onChange.

If we decide that we are fine either:

A. Calling onChange during the drag
B. Not updating the toolbar during the drag

Then we could get rid of this state altogether.

Copy link
Member

Choose a reason for hiding this comment

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

B. Not updating the toolbar during the drag

Personally, I don't think it's such a bad idea. 🤔
What do you think? 🤔
It might even be more transparent to the user, that they are only selecting (not have already selected) the new value, while dragging.

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 think it's very subjective tbh 😆
Given that the clock is used by way less people than before, maybe going for the simpler option makes sense here.
And I agree that it may clear out the expectations.

@flaviendelangle flaviendelangle merged commit bca4de0 into mui:master Mar 17, 2025
22 checks passed
@flaviendelangle flaviendelangle deleted the picker-value-controlled branch March 17, 2025 11:07
@hrithiksawhney
Copy link

Hi @flaviendelangle
Can you please cherry-pick this fix on top of v6.x branch and give a release?

@flaviendelangle
Copy link
Member Author

Hi,
This is a potential breaking change so I can't backport it to previous versions 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] Always use props.value as the source of truth when defined
4 participants