Skip to content
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

Can we avoid hijacking tab? #58

Closed
davidtheclark opened this issue Jul 15, 2018 · 1 comment
Closed

Can we avoid hijacking tab? #58

davidtheclark opened this issue Jul 15, 2018 · 1 comment

Comments

@davidtheclark
Copy link
Collaborator

davidtheclark commented Jul 15, 2018

Right now this library hijacks Tab. It relies on tabbable to determine the tabbable nodes within the focus-trap, and their order, then moves focus accordingly when you hit Tab, instead of letting the browser do its default thing.

There are a couple of issues with this approach:

  • tabbable does not (and probably cannot) perfectly match the browser's default behavior. The main symptoms of this are that tabbable is not going to pick up on iframes or shadow DOM — so in a focus-trap those elements won't receive focus; and it also can't handle radio sets.
  • It seems unfortunate: it would be nice if we didn't have to hijack default browser behavior but could somehow just rein it in a little.

If we could find an approach that fixes those issues and still works in all the ways focus-trap currently works — that would be great. I'm opening this issue to hear any ideas anyone has for solving this problem. Input welcome!


I tried experimenting a bit with an alternative approach today. I used tabbable only to grab the first and last tabbable nodes in the trap. Instead of listening to Tab events, I listened to focusout events: if event.relatedTarget comes before the previously focused node (so you're shift+tabbing), I'd focus the last tabbable node; if event.relatedTarget comes after, I'd focus the first tabbable node. I ran into 2 bad roadblocks:

  • This seemed promising on a few of the demos, but then crashed and burned with demo 3. When tabindex is deliberately set anywhere on the page it messes up the whole approach.
  • The first and last focusable items in the trap still need to be recognizable to tabbable.
@davidtheclark
Copy link
Collaborator Author

Closed by #59.

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

No branches or pull requests

1 participant