-
Notifications
You must be signed in to change notification settings - Fork 240
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: add capslock to userEvent.type #507
Merged
kentcdodds
merged 6 commits into
testing-library:master
from
Sonic12040:pr/add-capslock-event
Nov 30, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e44292
feat: add capslock to userEvent.type
Sonic12040 007ce22
docs(type-modifier): Added CapsLock to the modifier key documentation
Sonic12040 6f1335b
fix: added a switch/case for the CapsLock key, in case there are othe…
Sonic12040 f56db31
fix: separate the CapsLock modifier from the regular modifier callbac…
Sonic12040 9cfbb8f
fix: inlined capslock functions
Sonic12040 f978e9e
Update README.md
kentcdodds File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,6 +353,39 @@ test('{shift}a{/shift}', () => { | |
`) | ||
}) | ||
|
||
test('{capslock}a{/capslock}', () => { | ||
const {element, getEventSnapshot} = setup('<input />') | ||
|
||
userEvent.type(element, '{capslock}a{/capslock}') | ||
|
||
expect(getEventSnapshot()).toMatchInlineSnapshot(` | ||
Events fired on: input[value="a"] | ||
|
||
input[value=""] - pointerover | ||
input[value=""] - pointerenter | ||
input[value=""] - mouseover: Left (0) | ||
input[value=""] - mouseenter: Left (0) | ||
input[value=""] - pointermove | ||
input[value=""] - mousemove: Left (0) | ||
input[value=""] - pointerdown | ||
input[value=""] - mousedown: Left (0) | ||
input[value=""] - focus | ||
input[value=""] - focusin | ||
input[value=""] - pointerup | ||
input[value=""] - mouseup: Left (0) | ||
input[value=""] - click: Left (0) | ||
input[value=""] - keydown: CapsLock (20) | ||
input[value=""] - keyup: CapsLock (20) | ||
input[value=""] - keydown: a (97) | ||
input[value=""] - keypress: a (97) | ||
input[value="a"] - input | ||
"{CURSOR}" -> "a{CURSOR}" | ||
input[value="a"] - keyup: a (97) | ||
input[value="a"] - keydown: CapsLock (20) | ||
input[value="a"] - keyup: CapsLock (20) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then this should keydown and keyup and disable the modifier state. I'm afraid this one isn't quite as simple as I thought at first. |
||
`) | ||
}) | ||
|
||
test('a{enter}', () => { | ||
const {element, getEventSnapshot} = setup('<input />') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this one is tricky. Basically for caps lock, it should keydown and keyup here, but preserve the modifier state. Hmmm...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do you think a PR will also be needed to fireEvent for the case of CapsLock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,
fireEvent
is all about dispatching individual events in complete isolation. It is not concerned about state. This will only need to happen here in user-event. It's possible we won't be able to re-use the existingcreateModifierCallbackEntries
for this one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that. Updated with a switch/case. I'm not sure if it's initially beneficial to write it that way, but I didn't know if other modifier keys might also require the behavior at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw the comment after. I can write a separate function for it if preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sonic12040, could you try removing the custom logic and inlining it for the caps lock. I think that will result in simpler code in this case. I'm worried that this is a hasty abstraction (AHA Programming) and I think the small amount of duplication will be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with a duplicate function that performs the CapsLock behavior.