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

[pickers][DateTimePicker] Controlled DateTimePicker does not always show current Date state being passed in #13961

Closed
CciMichael opened this issue Jul 23, 2024 · 5 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists regression A bug, but worse

Comments

@CciMichael
Copy link

CciMichael commented Jul 23, 2024

Steps to reproduce

Link to live example: Codesandbox Link

When trying to implement a controlled DateTimePicker with react state, the picker does not reflect the actual state (for example if you wanted to implement some extra validation in the onChange function) unless you manually change the state being passed into it, forcing it to re-render.

I created an example of what I mean here, basically I want to have 2 separate DateTimePickers, one with a "Start" date and one with an "End" date. If the user types in a "Start" date AFTER the "End" Date, i want to force the state to revert to the last correct date, however, unless you change the date object to be different from what it is currently set at (as you can see me doing in the example with the second flipping), then the picker will reflect a time that is not what the state being passed in is at. (you can uncomment the // return moment(startDateVal); to see what I mean in both examples)

Current behavior

When trying to implement a controlled DateTimePicker with react state, the picker does not reflect the actual state (for example if you wanted to implement some extra validation in the onChange function) unless you manually change the state being passed into it, forcing it to re-render.

Expected behavior

The DateTimePicker should reflect the date state of the value={} being passed in to allow custom validation

Context

I created an example of what I mean here, basically I want to have 2 separate DateTimePickers, one with a "Start" date and one with an "End" date. If the user types in a "Start" date AFTER the "End" Date, i want to force the state to revert to the last correct date, however, unless you change the date object to be different from what it is currently set at (as you can see me doing in the example with the second flipping), then the picker will reflect a time that is not what the state being passed in is at. (you can uncomment the // return moment(startDateVal); to see what I mean in both examples)

Your environment

N/A, use the codesandbox

Search keywords: [pickers][DateTimePicker]

@CciMichael CciMichael added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 23, 2024
@arthurbalduini arthurbalduini added the component: pickers This is the name of the generic UI component, not the React module! label Jul 24, 2024
@michelengelen
Copy link
Member

Hey @CciMichael, thanks for bringing this up!

I understand there's a consistency issue between the date fields and the date picker. Currently, the fields show an error for invalid dates, while the picker disables them. It's a bit tricky because even with your example, there's a brief flash of the invalid field state before the component updates

I'm not sure if we can achieve the behavior you're looking for with our current setup. @LukasTy might have some ideas on how to approach this. Let's see what he thinks!

@michelengelen
Copy link
Member

We do this to optimize performance by avoiding unnecessary re-renders, primarily through the areDatesEqual method in the value manager. Right @LukasTy?

@LukasTy LukasTy added the duplicate This issue or pull request already exists label Jul 31, 2024
@LukasTy
Copy link
Member

LukasTy commented Jul 31, 2024

@michelengelen This looks like a duplicate of #10424.
@CciMichael thank you for a great example.
I've tested a native date input and it does not have this behavior.

We need to re-evaluate if and when the equality check is needed because this behavior is a regression compared to previous versions and is also inconsistent compared with other components.

@flaviendelangle Do you recall if the areValuesEqual check was needed in so many places? 🤔

@LukasTy LukasTy added regression A bug, but worse and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 31, 2024
@LukasTy
Copy link
Member

LukasTy commented Jul 31, 2024

I'm closing this issue as a duplicate, we can keep the discussions in #10424.

@LukasTy LukasTy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2024
Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@CciMichael: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! duplicate This issue or pull request already exists regression A bug, but worse
Projects
None yet
Development

No branches or pull requests

4 participants