edenspiekermann / a11y-toggle

A tiny script for accessible content toggles.
https://edenspiekermann.github.io/a11y-toggle/
MIT License
304 stars 21 forks source link

Feature request: Focus management #33

Open joe-watkins opened 7 years ago

joe-watkins commented 7 years ago

Hello :) Great work here!

I'd like to recommend the idea of focus management for your plugin. It would look something like this:

  1. User clicks on toggle.
  2. After the target is expanded send focus to the target element. May have to add tabindex="-1" to target so it can receive focus.
  3. If the target is already visible, maintain focus on the toggle and hide target.

What ya think?

KittyGiraudel commented 7 years ago

I like the idea, I just wonder if it’s a good one (in the sense that I wonder if focus change would be expected). Ping @heydon & @ffoodd.

joe-watkins commented 7 years ago

@HugoGiraudel Tnx :) Maybe an optional feature might be the way to go?

Here's an example pattern from W3C WAI-ARIA

ffoodd commented 7 years ago

Hi there,

My two cents: I think it's a good idea as an option.

The most common way to use a toggle is that hidden content follows the trigger (DOM speaking). This way, appearing content becomes next content in the flow — and if any focusable element inside, it naturally appears in the focus flow too.

But if for any reason the toggled content is anywhere else in the DOM, I think it's better to move focus to the toggled content (same arguments than with the dialog pattern) as recommended by @joe-watkins.

dennisfrank commented 6 years ago

Hi. Sorry, I am not a bigger help right now. But this would be the number one feature addition I would love to see! :)