[Pickers] Ensure input value is reset in the same commit as the value #25972
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The re-computation of state in
useEffect
was suspicious to me.It seems to me that the "input value" (named
innerInputValue
) was supposed to be what the user inputs. The implementation made sure that this value is reset if the actual date value changed. But only if the textbox isn't focused to avoid interrupting the user while typing. This created some weird states where outside value updates were dropped during input or when the textbox was still focused but the user is idle.This requires some logic that leads to tearing (state updates in useEffect). The new implementation is a bit more verbose but is hopefully clearer in its intent. It's probably better to re-implement this by controlling the
rawValue
inusePickerState
and then deciding whether we want to expose controlled vs uncontrolled input values.Manual testing: https://deploy-preview-25972--material-ui.netlify.app/components/date-picker/#basic-usage