-
Notifications
You must be signed in to change notification settings - Fork 249
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.clear
behavior
#778
Comments
@kentcdodds Any opinion on this? |
I like this, but one challenge is this is inconsistent against all clients. On a Mac it's Cmd+A 😬 but maybe that's no big deal? |
Good point. Maybe this is a good argument for variant 2. If someone wants to simulate the keyboard/mouse events, they could still call those APIs directly. Could you however record the events for that key combination on Mac? https://vtdcc.csb.app/ |
Sure! Here's what I got when I clicked into the input, pressed cmd+a, and then hit "delete" (which is the backspace button on regular keyboards but Apple likes to be special and calls it "delete" instead).
|
🎉 This issue has been resolved in version 14.0.0-alpha.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem description:
The current implementation of
userEvent.clear
mixes user interactions with magicis only supported for
input
andtextarea
and currently translates to:element.type
totext
if element isn't atextarea
[MouseLeft]
selectionStart
reset the selection to what it was before the click{selectall}
input, not subject to event handling)[Delete]
and remove value subject to event handlingelement.type
back to the original valueThis is a mess of user input and magic which we certainly don't want to encourage.
And this behavior is not obvious to our users: #755
The
specialChar
{selectall}
will be removed inuser-event@14
as it is the only input fortype
/keyboard
which does not describe a key stroke. This means there will a breaking change touserEvent.clear()
anyway.Suggested solution:
Either
clear
a convenience wrapper forCtrl+A
, then delete content.Handle every step as if it was triggered by browser menu/screen reader - without any pointer/mouse/key events.
Mysteriously set focus and select all children of the element which seems to be expected by our users but is not possible in UI.
Then remove elements/text per one of the options above or just also mysteriously clear them from the DOM.
The text was updated successfully, but these errors were encountered: