-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
KeyboardEvents not firing of handlers #122
Comments
It's because you need to set the This is why I recommend you use Good luck. |
The onChange callback on |
See the README. For checkboxes you should fire the click event, not the change event. |
But i am not firing the change event. I want to test keyboard interactions. In this case, i want to test the spacebar keydown. |
Ah, I see what you mean. You want this: testing-library/dom-testing-library#107 |
Don't know if i followed the thread correctly. Does it mean that to make the checkbox change state based on keyboard spacebar press, i need to fire a combination of events? What is the best way to test accessibility related keyboard scenarios? E.g. tab to focus an element and then press |
I'm honestly not sure. For your specific example, I think you should be able to rely on the way that browsers deal with checkboxes and use |
Hmm. I was trying to add these tests because we ran into a situation where a coworker of mine wrote a component and thought it was accessible but didn't test it for keyboard interactions manually. I caught it in code review but was wondering if we could make keyboard interaction tests a norm. Will try to add those tests at selenium level for now. Thanks for your time! |
Hmmm... Are you sure it was a checkbox? How did they make a checkbox that didn't work with the space bar? |
It was a switch which had a checkbox underneath so that we could use the checkbox onChange and focus browser functionality. The switch was implemented by styling the accompanying label but the |
Ah, I see, so you don't want to test the keyup on the input, you want to test it on the switch... |
Yes, that's correct. I tried all combinations - on the input, the switch container, document and document.body. No luck. |
So when the user's actually using the component, where are they focused when they hit the space bar? |
I removed the Now i can hit 'Tab' and the focus moves to the switch. On pressing space bar, the switch toggles between on/off, just like a checkbox. |
You may consider doing the CSS like bootstrap's I know that some screen readers will skip elements that aren't visible unless it's done in a certain way. |
Here's the CSS for position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0; I can't find the css for |
Thanks!
Had no idea there was so much css involved to have an element hidden behind another one but still be present in the DOM :) |
Closes testing-library#122 **What**: `getByText` section in the readme. **Why**: The current example is not accurate. **How**: Since the `exact` option is true by default, I use a regular exception with ignore case to find the desired element by text. **Checklist**: - [X] Documentation - [ ] Tests N/A - [X] Ready to be merged - [X] Added myself to contributors table
react-testing-library
version: 4.0.1react
version: 16.4.1node
version: 8.9.4npm
(oryarn
) version: (yarn 1.7.0)Relevant code or config:
What you did:
I am trying to simulate keyboard events to validate my input component. To do that I tried to use
fireEvent
function withkeydown
andkeyDown
types but neither worked.What happened:
Event handlers are not getting called
Reproduction:
https://codesandbox.io/s/n32nmp18rl
Problem description:
I can't simulate any input via keyboard
Suggested solution:
When i tried to simulate events using reacts
ref
andreact-dom/test-utils
Simulate
class it seemed to work.The text was updated successfully, but these errors were encountered: