question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why the active tab panel has tabindex="0"?

See original GitHub issue

❓Question

I have a set of tabs and a set of corresponding tab panels. As in your basic example. I noticed that the active tab panel has tabindex="0" attribute. Why is this needed? This makes the active panel tabbable. So when I use tabs inside a dialog along with a focus lock that lets me tab through all the controls in the dialog, the active panel receives its own focus before all the controls in it, as I tab through the dialog. Is there a way to fix that? I use the same react-focus-lock library that you use internally, if this matters.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chaancecommented, Mar 8, 2021

@coreylight If you pass tabIndex to the panel it will override what we set internally. If you pass null it will remove the tabIndex altogether (TypeScript will complain, but you can cast as any or ignore the line if you’d like).

I don’t think this is a great idea because of the aforementioned accessibility requirements. Another option would be to use onFocus and onPointerDown to figure out if the user is interacting with the scroller and, if so, re-focusing the input in that case. This is similar to how we manage focus in combobox when the user interacts with options in the popover.

0reactions
IanVScommented, Aug 27, 2021

I had this question as well, why tab panels are a tab target. In a normal document flow, static content does not receive focus, and pressing tab jumps from one interactive element to another. I’m trying to learn more about accessibility, and am not proficient with assistive technologies. Is the reason the panel should be a target because it might have been hidden when the page first loaded, and therefore the tech won’t necessarily know it’s there unless it gets focus?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ARIA: tab role - Accessibility - MDN Web Docs - Mozilla
All of the tabpanel elements have tabindex="0" to make them tabbable, and all but the currently active one have the hidden attribute.
Read more >
Keyboard Accessibility - Tabindex - WebAIM
tabindex="0" allows elements besides links and form elements to receive keyboard focus. It does not change the tab order, but places the element ......
Read more >
Control focus with tabindex - web.dev
Using a tabindex greater than 0 is considered an anti-pattern because screen readers navigate the page in DOM order, not tab order. If...
Read more >
How and when to use the tabindex attribute - bitsofcode
A tabindex of zero is typically used either to add focus back to elements that it was programatically removed from. Another good use...
Read more >
How-to: Use the tabindex attribute - The A11Y Project
When tabindex 's value is set to zero or a positive number, the element can be navigated to via the keyboard's Tab key....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found