-
Notifications
You must be signed in to change notification settings - Fork 668
Test keyboard navigation for accessibility #966
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
Comments
It sounds like this more towards the end to end test side of things... I sense a real browser (not the usual In the case that this is something
Or instead of the last line, require the user to create their own event with I have a feelling this is more to do with SDOM thing rather than I am not sure if this will work in JSDOM, but in a browser you can emulate the tab event like this: var ev = document.createEvent('Events');
ev.initEvent('keydown', true, true);
ev.keyCode = 9;
ev.which = 9;
ev.charCode = 0;
ev.key = 'Tab'
ev.code = 'Tab'
const wrapperEl = wrapper.find('input')
wrapperEl.focus() // or wrapperEl.element.focus() ?
el.dispatchEvent(ev) // or maybe wrapperEl.element.dispatchEvent(ev) ?
expect(document.activeElement).toBe(wrapperEl.element) I did not test this code so it might not work as is, but something along those lines certainly should work, assuming JSDOM implements all of the required spec. |
I met the same problem these days. And I found a discussion: jsdom/jsdom#2102 seems that JSDOM doesn't support TAB navigation. That might be really difficult to do this in Vue Test Utils expect JSDOM makes it happen. Thanks. |
As @Jinjiang says, this is because the feature is not implemented by JSDOM. We won't add a workaround to Vue Test Utils |
What problem does this feature solve?
When testing a component such as a dropdown, it's important to test if it works properly with the keyboard. For example, when opening a dropdown, by using the
Tab
key the user should not be able to leave the popover (trapped focus), up/down arrows should navigate through the options, pressingEsc
should close it, etc.I cannot seem to find any way to test for this. A similar issue was brought up already, but it was quickly dismissed. It looks like the docs mention the keyboard but it seems like that only applies to actual listeners. For example, if I have a button like
and I try to do
that doesn't register (I think) because I never explicitly do
This means that I'm unable to test the
Tab
key properly, which is crucial for keyboard navigation. The same with.focus()
.What does the proposed API look like?
Something like
wrapper.keyboard.press('tab')
andwrapper.focus()
?The text was updated successfully, but these errors were encountered: