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 33 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 245f6bf

@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.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 30, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 30, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 2, 2025
Copy link

github-actions bot commented Jan 2, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

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

LukasTy commented Jan 24, 2025

I've tested the behaviors and issues that were closed as duplicates in favor of the original issue, and it seems there are still some behaviors missing.
I've created a sandbox with the various behaviors: https://codesandbox.io/p/sandbox/jolly-forest-lqtsfy

@LukasTy LukasTy added the regression A bug, but worse label Jan 24, 2025
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.

Besides, correct me if I'm wrong, but it looks like this PR changes the value lifecycle.
We no longer have an intermediary Invalid date. 🙈
This is quite a massive BC. Is it necessary to solve the underlying issue? 🤔

@flaviendelangle
Copy link
Member Author

We no longer have an intermediary Invalid date. 🙈

Indeed
Is it required? To have the same behavior as the browser input yes I think it is.
It all depends how similar to it we want to be. With the new approach I felt like it made sense.

@flaviendelangle
Copy link
Member Author

I've created a sandbox with the various behaviors: https://codesandbox.io/p/sandbox/jolly-forest-lqtsfy

Your demos use DatePicker but this PR only focuses on DateField, I did not fix the control layer of the picker yet.
Did you reproduce those issues with the standalone fields?

@LukasTy
Copy link
Member

LukasTy commented Jan 27, 2025

I've created a sandbox with the various behaviors: https://codesandbox.io/p/sandbox/jolly-forest-lqtsfy

Your demos use DatePicker but this PR only focuses on DateField, I did not fix the control layer of the picker yet. Did you reproduce those issues with the standalone fields?

Indeed, sorry for missing that. 🙈
The same problems on DateField instead seem resolved. 👌 🎉


We no longer have an intermediary Invalid date. 🙈

Indeed Is it required? To have the same behavior as the browser input yes I think it is. It all depends how similar to it we want to be. With the new approach I felt like it made sense.

Maybe not required, but I feel like it's a separate topic. If it can be extracted—I'd prefer to discuss it and deliver separately with more visibility and naturally, no way of cherry-picking. 🙈

I think that having the intermediate "Invalid date" step doesn't hurt and we create the "error" state, while we are entering data.
IMHO, this release is going to have many BCs as it is, I feel like it would be best to omit it at least from v8 if it's not essential. 🤷
WDYT? 🤔

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! regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants