-
Notifications
You must be signed in to change notification settings - Fork 241
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
Redefine userEvent.paste
behavior
#782
Comments
@kentcdodds @nickmccurdy Any opinion on this? |
Looks pretty good to me! One thing, what about disabled elements? |
The (I say |
Makes sense! Sounds great! |
Problem description:
The current implementation of
userEvent.paste(element, text, init, options)
does:0,0
set selection sooptions.initialSelectionStart, options.initialSelectionEnd
if given,element.value.length, element.value.length
otherwise.paste
event with user supplied EventInitinit
.inputType: 'insertFromPaste')
text` at current range.This does not reflect an interaction a user could perform.
It does not support contenteditable or properly honor selection range.
It does not support paste events outside of editable context.
Suggested solution:
Replace API with
userEvent.paste(clipboardData?: DataTransfer | string)
that:clipboardData
is a string, create aDataTransfer
object with it.clipboardData
is undefined, try to read data from Clipboard API if available. (This step requires the new implementation to be async.)clipboardData
is undefined and data could not be retrieved from Clipboard, reject.paste
event.input
event.This would allow
a) the user to paste outside of input/textarea.
b) the user to test workflows using Clipboard API if it is available. (Clipboard API could also be mocked in Jsdom.)
c) the user to paste non-text elements.
d) us to implement copy/paste of DOM elements in contenteditable later.
The text was updated successfully, but these errors were encountered: