-
Couldn't load subscription status.
- Fork 255
Closed
Milestone
Description
Problem description:
The current implementation of userEvent.paste(element, text, init, options) does:
- Throw error if element is neither editable input nor textarea.
- Do nothing on disabled.
- Focus element without properly updating selection.
- If element supports selection range and selection is
0,0set selection sooptions.initialSelectionStart, options.initialSelectionEndif given,element.value.length, element.value.lengthotherwise. - Fire
pasteevent with user supplied EventInitinit. - Return on readonly element
- Input (
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:
- If
clipboardDatais a string, create aDataTransferobject with it. - If
clipboardDatais undefined, try to read data from Clipboard API if available. (This step requires the new implementation to be async.) - If
clipboardDatais undefined and data could not be retrieved from Clipboard, reject. - Dispatch
pasteevent. - If in editable context, insert the data into DOM and dispatch an
inputevent.
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.
danny-pflughoeft, JRagone, chinmayjoshi195 and zachequi
Metadata
Metadata
Assignees
Labels
No labels