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

feat(userEvent): Add paste API (fixes #640) #645

Closed
wants to merge 4 commits into from

Conversation

nickmccurdy
Copy link
Member

@nickmccurdy nickmccurdy commented Jun 15, 2020

Migrated from testing-library/user-event#343

What: Add paste API (fixes #640)

Why: The allAtOnce option of type doesn't represent real user interaction intuitively, and we need to fire paste events with the relevant clipboardData

How:

  • Extract paste event from old code for type's allAtOnce option
  • Implement clipboardData support Support clipboardData like dataTransfer. #585
  • Add events
    • paste with clipboardData
    • input with matching value
    • focus
  • DataTransfer mock objects

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • Typescript definitions updated N/A
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 15, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

I left some comments, but I just had a thought... What if instead we make a {paste} modifier inside type? This would simplify the implemention quite a bit and honestly makes plenty of sense as an API to me personally.

src/user-event/paste.js Show resolved Hide resolved
src/user-event/paste.js Outdated Show resolved Hide resolved
@nickmccurdy
Copy link
Member Author

nickmccurdy commented Jun 15, 2020

What if instead we make a {paste} modifier inside type? This would simplify the implemention quite a bit and honestly makes plenty of sense as an API to me personally.

Shouldn't the typing modifiers be primarily for individual key presses and modifiers? I feel like pasting has different enough responsibilities from typing semantically to be a separate function, just like how clear and tab are functions rather than modifiers. Either way, I'm interested if we could maybe make paste use type more directly to simplify the architecture, as I originally though that wouldn't be possible after removing the allAtOnce option.

@kentcdodds
Copy link
Member

Shouldn't the typing modifiers be primarily for individual key presses and modifiers?

Not really. We already have {selectall}. I think type is for anything that the user would do with their keyboard which we feel they do enough to justify having a feature for it. I think it would be reasonable to support {paste} and also have a shortcut userEvent.paste which simply calls into it (similar in some ways to userEvent.clear.

@nickmccurdy
Copy link
Member Author

It still feels like a different kind of user interaction to me. At least {selectall} is directly related to editing some existing text, but users often paste without typing anything else, and as far as I understand this would be the only command that would input many characters immediately.

@kentcdodds
Copy link
Member

Fair point 👍 ok, let's proceed with sharing code instead.

@kentcdodds
Copy link
Member

Ok, because of the decision to not merge user-event right now, I've back-ported all my improvements to user-event into testing-library/user-event#348, and I included this as well. I hope you don't mind 😬

Thanks!

@kentcdodds kentcdodds closed this Jun 15, 2020
@kentcdodds kentcdodds deleted the pr/user-event-paste branch June 15, 2020 21:39
@nickmccurdy
Copy link
Member Author

This wasn't ready to release, can we revert it?

@kentcdodds
Copy link
Member

I made it ready 😁

@nickmccurdy
Copy link
Member Author

Tracking followup work back in testing-library/user-event#355

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.

None yet

2 participants