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

[EuiSuperDatePicker] Fix duplicate value when pasting absolute value #8311

Merged

Conversation

mgadewoll
Copy link
Contributor

@mgadewoll mgadewoll commented Feb 7, 2025

Summary

Related Kibana issue: elastic/kibana#205633

This PR fixes an issue on EuiSuperDatePicker where pasting a date would sometimes result in the date being appended instead of being replaced.
The issue was that the onPaste event would trigger the onChange event on the EuiFieldText input which clashed with the controlled value update. This seemed to be a race condition as depending on application this resulted either in a duplicated value or not, depending on which state was updated first.

This behavior is not reproducible on EUI (neither docs not Storybook), but it can be observed by checking the value of the internally used EuiFieldText which showed the duplication.

The solution is to preventDefault on onPaste and just let the controlled value update the input.

before

Screen.Recording.2025-02-07.at.10.40.18.mov

after

Screen.Recording.2025-02-07.at.10.36.00.mov

QA

  • the updated unit test passes
    • (optional) comment out the added event.preventDefault and manually run the test locally (the test should fail)
  • manually verify non-duplicated input value:
    • checkout this PR
    • comment out the update adding event.preventDefault on the onPaste event
    • console log the event.target.value on the onChange event of the EuiFieldText
      • the onChange event is not triggered on pasting
      • the input value updates correctly
      • validation for the date picker works correctly

EuiFieldText` value before the fix

Screen.Recording.2025-02-07.at.10.48.26.mov

EuiFieldText` value after the fix

Screen.Recording.2025-02-07.at.10.49.32.mov

General checklist

@mgadewoll mgadewoll self-assigned this Feb 7, 2025
@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @mgadewoll

@mgadewoll mgadewoll marked this pull request as ready for review February 7, 2025 05:46
@mgadewoll mgadewoll requested a review from a team as a code owner February 7, 2025 05:46
@acstll acstll self-requested a review February 7, 2025 09:13
Copy link
Contributor

@acstll acstll left a comment

Choose a reason for hiding this comment

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

Awesome work 🙇

@mgadewoll mgadewoll merged commit aea27cd into elastic:main Feb 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants