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

Implement key press functionality from a user perspective #371

Closed
wants to merge 1 commit into from

Conversation

juanca
Copy link
Collaborator

@juanca juanca commented Jun 20, 2020

What: Implement user interaction of pressing a single key with some modifiers

Why: This is especially useful for testing accessibility interactions (keyboard interactions) on UI elements.

How:

  • Interaction is solely on the active element because a user will always be on some element
  • Any key is "pressable" given the key name
  • The 4 popular modifiers (alt, ctrl, meta, shift) are implemented and fired around the pressed key
    • Looks like there might be more key to implement but I think we can work on these in the future

Checklist:

  • Documentation
  • Tests
  • Typings
  • Ready to be merged

Closes #354

A couple of notes:

  • The event is always fired on the active element since a user will always perform an interaction on the active element
  • Event which key is not implement because it is deprecated
  • Event code / keyCode key is not implement because it can vary on type of key (KeyA, Digit1, AltLeft, etc), opting for a more simple interface

This is especially useful for testing accessibility interactions (keyboard interactions) on UI elements.

A couple of notes:

- The event is always fired on the active element since a user will always perform an interaction on the active element
- Event `which` key is not implement because it is deprecated
- Event `code` / `keyCode` key is not implement because it can vary on type of key (`KeyA`, `Digit1`, `AltLeft`, etc), opting for a more simple interface
@codecov
Copy link

codecov bot commented Jun 20, 2020

Codecov Report

Merging #371 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #371   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        13    +1     
  Lines          376       390   +14     
  Branches       109       118    +9     
=========================================
+ Hits           376       390   +14     
Impacted Files Coverage Δ
src/index.js 100.00% <ø> (ø)
src/key-press.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4eae9c...d0d3d96. Read the comment docs.

@juanca
Copy link
Collaborator Author

juanca commented Jun 20, 2020

I can whip up documentation if we're okay with this new API.

I am not sure what to do with typings. Is there some work I need for that particular checklist item?

@kentcdodds
Copy link
Member

I'd prefer this functionality be built in via the type utility. So: type(input, '{ArrowDown})...

@nickmccurdy
Copy link
Member

For reference: #354

@juanca
Copy link
Collaborator Author

juanca commented Jun 22, 2020

I started digging into this and I think I discovered unplanned features:

I am thinking the PR will add support for navigation keys. It's pretty simple if I am only concerned about keyboard navigation for accessibility (simple keydown + keyup). However, it gets more complex: the type method involves managing the value and cursor/selection state in various elements; the navigation keys also have a side effect of changing the cursors or selection range.

I'll give it another go on Friday.

@juanca juanca closed this Jun 22, 2020
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.

arrow keys?
3 participants