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.

[react] Static Option on Listbox breaks keyboard accessibility

See original GitHub issue

Not sure if this is a bug or if I’m misunderstanding the feature, but we’re running into an issue with the focus trap when using the static property.

The goal is to have an always open select menu, so, my first instinct was to simply not render the button and make the menu static. Example: https://codesandbox.io/s/jovial-sanne-2x7iz?file=/src/App.js

This works great, except we realized that the focus trap is still present, regardless of state, so if you use the static option, you can’t tab past the menu. Example: https://codesandbox.io/s/modest-wiles-id8qu?file=/src/App.js

Is there a plan for this sort of thing already? Are we just abusing this component? I guess I’m just trying to figure out whether this is an opportunity to improve the Listbox, if there’s something on the roadmap already for this use case, or if we should be making our own component for this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
RobinMalfaitcommented, Jan 30, 2021

Hey! I am going to close this issue now, because I don’t think it will be a good idea to provide an option to disable the focus trap (because of the aforementioned reasons). Thanks!

1reaction
matt-morriscommented, Dec 2, 2020

Yeah, a radio button group is actually what we’ve gone with for now, but it’s not ideal for a couple of reasons. First, when the group has focus, although you can navigate through it with arrow keys, each option is actually selected as you move through it.

We’re using it to set a current filter for a list of items with an animated layout, so if a user arrows through options quickly, the reflows begin to look a little jarring.

radio-button-group-example-00

It’s not the end of the world, obviously, but it’s also not the best UX. It’s much smoother to be able to let the user navigate the options before selecting it.

The other reason we’re not thrilled with radio buttons is that it turns out there’s a surprising amount of cross-browser weirdness with them. I hadn’t ever realized until now how disjointed it actually is until I started looking into this issue. In Chrome, clicking one of the radio buttons focuses the group, but not in Safari or Firefox. Chrome and Firefox both cycle through the list while Safari stops at either end. Again, none of this is the absolute worst, but it’s enough to make think about a headless menu component where we can normalize and control this stuff.

The Listbox with a static menu is almost perfect for our use case, if we could just turn off the focus trap. No worries if that’s not in the cards right now. I just wanted to bring it up here. We’re very invested in the possibilities of this library, and so we’re looking to help out however we can. We build and manage hundreds of websites with similar content but different styles, so the headless approach is very freeing for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

9 tips for accessible React components (in 2022)
If you have a grid of interactive elements, tabbing from elements before the grid to after the grid will require a huge amount...
Read more >
useListBox – React Aria - React Spectrum Libraries
useListBox requires knowledge of the options in the listbox in order to handle keyboard navigation and other interactions. It does this using the....
Read more >
Building accessible Select component in React - Medium
This bug breaks a lot of otherwise accessible select elements showcased online, ... Reacting to the keyboard when the dropdown is closed.
Read more >
Frontend Handbook | / Accessibility - Infinum
Web accessibility encompass all disabilities that affect access to ... the key is a combination of Control and Option keys on a keyboard....
Read more >
Accessible Rich Internet Applications (WAI-ARIA) 1.1 - W3C
Users of alternate input devices need keyboard accessible content. ... the role combobox have an implicit aria-haspopup value of listbox .
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