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

Popover (and Dropdown) needs a way to set initial focus depending on its usage or content #4620

Closed
afercia opened this issue Jan 21, 2018 · 4 comments
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).

Comments

@afercia
Copy link
Contributor

afercia commented Jan 21, 2018

Let's consider, for example, the "Content Structure" component (formerly "Table of Contents"). When clicking the toggle button that opens it, focus is moved to the first heading in the Document Outline. However, posts may have no headings at all:

screen shot 2018-01-21 at 17 24 59

In this case, there's no element to move focus to and a focus loss occurs. Press Tab again and focus fallbacks to the document root:

screen shot 2018-01-21 at 17 25 09

Additionally, even if there were headings, all the first part of the content (the "counts") is skipped and users of assistive technologies would have to explore content backwards to get the counts.

In this specific case, the initial focus should probably be moved to the Popover container, and the container should be properly labeled.

However, initial focus really depends on the content of the component. There might be cases where it would make sense to set the initial focus on a different element, for example an input field in a form with a very specific task to accomplish.

Since we can't predict which kind of content this component will be used for, the initial focus should be different depending on the specific component usage. I'd rather consider a way to set the initial focus via a prop, to pass in some way the element that should receive focus.

@afercia afercia added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jan 21, 2018
@grahamarmfield
Copy link

The Content Structure component now does get focus when the button is actioned. However, the focus is not at all visible which is an issue for sighted keyboard users - since it appears that focus has gone 'missing'. Is there a need for a separate issue on that.

As @afercia noted above, a further pressing of tab actually puts focus at the top of the document.

Additionally, if I happened to press shift-tab (reverse tab) focus then moves directly to the last focussable element in the block details sidebar.

Thus the Content Structure panel is not acting as a modal. Focus should be trapped in this element until the user wishes to dismiss the popup. I know the Escape key works here, but people may try other keys.

@afercia
Copy link
Contributor Author

afercia commented Apr 13, 2018

Totally agree thanks @grahamarmfield (hi!). About constraining tabbing, there's #5242

@noisysocks
Copy link
Member

We should now be able to do this by setting focusOnMount="container" on the Popover.

https://github.com/WordPress/gutenberg/blob/master/packages/components/src/popover/README.md#focusonmount

@afercia
Copy link
Contributor Author

afercia commented Jul 30, 2018

Yep also, the document statistics section is now focusable and uses role="note" aria-label="Document Statistics" tabindex="0" so it gets focused. There's also the new focusOnMount behavior to help with these cases so I'm going to close this issue.

@afercia afercia closed this as completed Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

No branches or pull requests

3 participants