Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Keyboard focus on child components #24

Open
kharrop opened this issue Dec 31, 2018 · 2 comments
Open

Keyboard focus on child components #24

kharrop opened this issue Dec 31, 2018 · 2 comments
Labels

Comments

@kharrop
Copy link

kharrop commented Dec 31, 2018

I'm unable to use "tab" or keyboard navigation to change my focus to my newly triggered object. I have to tab through the rest of my nav in order to get focus on the object that's positioned closest to my trigger.

Current behavior: I tab to the first main nav item, and then tabbing goes to the next main nav item
Expected behavior: I tab to the first main nav item which triggers my sub nav and I am able to tab to those sub-items.

@kharrop kharrop changed the title Keyboard focus on child components Keyboard focus on child components (Accessibility) Dec 31, 2018
@sunify
Copy link
Owner

sunify commented Feb 1, 2019

Thanks for report and sorry for long response. Will take a look

@sunify sunify changed the title Keyboard focus on child components (Accessibility) Keyboard focus on child components Feb 2, 2019
@sunify sunify added the a11y label Feb 2, 2019
@slafleche
Copy link

slafleche commented Jul 24, 2020

The problem is this component doesn't know what triggers the portal and doesn't know what's inside. So it's not really its responsibility. Depending on how you use it, you may need different solutions.

Here's what i would do if it's just a dropdown triggered by a button:

First it needs to be a proper accessible button menu https://www.w3.org/TR/wai-aria-practices-1.1/#menubutton

If you only have text inside the menu, and there's nothing to click/focus on, then just add a role="alert" on the contents of the portal.

If there is, then it's more complicated:

You need to also add an onKeyDown handler on your button to listen for a "tab" press.

If there is a tab press and the dropdown contents are visible, you need to set to the focus on the first tabbable element in the dropdown.

The first and last tabbable elements of the dropdown need to listen for tab press as well. The first needs to set the tab back to the button if you shift+tab out of the portal. The last needs to close the dropdown contents and set the focus on the element AFTER the button.

If you work with dynamic UI, i strongly suggest using https://github.com/davidtheclark/tabbable to handle the tab order. It's excellent.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants