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

[fields] Always use props.value as the source of truth when defined #15875

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Dec 13, 2024

Part of #15530

We should now have a behavior coherent with the browser input and working well on range inputs as well.
Not sure if we should count that purely as a bug fix or as a breaking change.

Follow up

  • Always use the props.value as the source of truth in usePickerValue (should be a lot simpler)

@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module! labels Dec 13, 2024
@flaviendelangle flaviendelangle self-assigned this Dec 13, 2024
@mui-bot
Copy link

mui-bot commented Dec 13, 2024

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

Generated by 🚫 dangerJS against e4cb9a1

@flaviendelangle flaviendelangle changed the title [fields] Always use props.value as the source of truth when defined [fields] Always use props.value as the source of truth when defined Dec 14, 2024
@flaviendelangle flaviendelangle force-pushed the value-field-source-of-truth branch from 169db6a to 4c89824 Compare December 18, 2024 16:08
@flaviendelangle flaviendelangle force-pushed the value-field-source-of-truth branch from 4c89824 to 4a2952e Compare December 18, 2024 16:17
@flaviendelangle flaviendelangle marked this pull request as ready for review December 20, 2024 13:04
// For Day.js: "[Escaped] YYYY"
format: `${startChar}Escaped${endChar} ${adapter.formats.year}`,
enableAccessibleFieldDOMStructure: false,
value: null,
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 fixed a lot of tests that were switching from uncontrolled to controlled.

* Object used to access and update the active date (i.e: the date containing the active section).
* Mainly useful in the range fields where we need to update the date containing the active section without impacting the other one.
*/
interface FieldActiveDateManager<TValue extends PickerValidValue> {
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'm removing this concept because we don't need to update the reference value in multiple places anymore.
Instead I aligned the needed methods inside the field value manager.

/**
* Last value of the parameters used to generate the sections.
*/
lastSectionsDependencies: { format: string; isRtl: boolean; locale: any };
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'm storing those in state instead of using an effect to avoid a double re-render.
It's not strictly related to this PR but since I moved to this approach for the value update, I feared mis-synchronization if one update was in the render and another was in an effect.

@@ -659,12 +659,15 @@ const transferDateSectionValue = (
}

case 'weekDay': {
let dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes a bug highlighted by the new behavior but already here before.
For the E format of Luxon, the day of the week does not have leading zeroes, so dayInWeekStrOfActiveDate was equal to let's say 4and formattedDaysInWeek was ['1', '2, ...].
Which means dayInWeekOfNewSectionValue was equal to -1 and that messed up with the editing.

Before the bug was only visible on the value passed to onChange.
Now it's also visible on the value rendered.

So this PR also improves how we actually test all the tokens 👌

@@ -191,8 +191,10 @@ export interface MuiPickersAdapter<TLocale = any> {
value?: T,
timezone?: PickersTimezone,
): DateBuilderReturnType<T>;
// TODO v9: Remove.
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need it anymore, but it does not cost much to keep it so I'm deprecating it for next major.

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: pickers 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.

2 participants