-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Correctly handle events with a complete value insertion #9896
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9896--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
const eventData = (event.nativeEvent as InputEvent).data; | ||
// Calling `.fill(04/11/2022)` in playwright will trigger a change event with the requested content to insert in `event.nativeEvent.data` | ||
// usual changes have only the currently typed character in the `event.nativeEvent.data` | ||
const useEventData = eventData && eventData.length > 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure it can not be more than one character? I'm thinking about special keyboards or some auto-completion
I don't see issues, it's just to share a point of attention. I first thought about #9465 but it's not the same problem since IME keyboard calls multiple times the onChange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure it can not be more than one character? I'm thinking about special keyboards or some auto-completion
I'm definitely not sure that there wouldn't be any edge cases, but autocompletion is turned off, although, if any extension hacks it's way into this, I'd imagine that this change could only fix it and not break because it would probably use a similar API of emitting a change event with the full value string. 🤔
Signed-off-by: Lukas <[email protected]>
packages/x-date-pickers/src/internals/hooks/useField/useField.ts
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/internals/hooks/useField/useField.ts
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/internals/hooks/useField/useField.ts
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/internals/hooks/useField/useField.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Flavien DELANGLE <[email protected]> Signed-off-by: Lukas <[email protected]>
This fix resolves the issue mentioned here: #9165 (comment)
Calling
fill('04/11/2022')
(in playwright and possibly other e2e frameworks) on the pickers field does nothing because we explicitly check only theevent.target.value
.In such case
event.target.value
will equal04/11/2022/MM/YYYY
, which is not valid as per our code and nothing happens.With the change done here, we'd use the
event.nativeEvent.data
, which would contain the whole04/11/2022
and update the value using it, instead of the regular section updating process.When using regular editing by typing characters with the keyboard results in
event.nativeEvent.data
having only the changed character.