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

Accessibility: Consolidate the focusOnOpen behavior in the withFocusReturn Higher Order Component #4566

Closed
wants to merge 1 commit into from

Conversation

youknowriad
Copy link
Contributor

I noticed that each time we want to use withFocusReturn HoC. Having a focusOnOpen behavior makes sense. While this was made possible with the Popover component right now, we use the withFocusReturn in other places than Popovers.

In this PR I moved the focusOnOpen behavior from the Popover component to the withFocusReturn HoC. It might make sense to rename this HoC, ideas?

I also I'm applying withFocusReturn to the publish panel partially fixing #4187

@youknowriad youknowriad self-assigned this Jan 18, 2018
@youknowriad youknowriad requested review from afercia and aduth January 18, 2018 09:00
@afercia
Copy link
Contributor

afercia commented Jan 18, 2018

@youknowriad thanks. I think it makes perfectly sense for components like modals, dropdown menus, etc. that are not mounted initially.

Not sure it works well for the Publish Panel and the Sidebar.

1
Sidebar: When users keep the sidebar open, on page load the sidebar is mounted. As it works now, withFocusReturn sets the firstTabbable to button.editor-sidebar__panel-tab.is-active and the initial focus is actually on the sidebar "active tab".

Worth noting that, depending on the workflow, this button can also be disabled so, regardless of the above, it won't be focusable.

2
Sidebar: there are scenarios where there's no activeElementOnMount yet. For example, on page load I navigate to the X button of the sidebar:

screen shot 2018-01-18 at 12 02 11

I click the X and focus is moved back to the document root. I'd expect it to move back to the "cog" button.

3
Publish Panel: When closing the publish panel, clicking on the X, focus is not moved back to the "Publish..." button for me. I guess because the header section that contains the "Publish..." button gets unmounted and then mounted again so activeElementOnMount was the previous button and when it re-renders it's actually a new reference in the DOM?

Overall, for the Sidebar and Publish Panel, I think we can't solve the interaction issues with code. The root cause of the problem is in the interface and it should be solved re-thinking the interface.

@youknowriad
Copy link
Contributor Author

So your saying, it's ok to handle the focusOnMount and focusReturn together but you think we shouldn't use this HoC in the sidebar/publish panel?

Noting that the sidebar already had the withFocusReturn HoC before this PR.

@youknowriad
Copy link
Contributor Author

youknowriad commented Jan 18, 2018

I click the X and focus is moved back to the document root. I'd expect it to move back to the "cog" button.

What if we opened the sidebar using the block settings menu? A sidebar can be opened from several places, so its placement in the DOM shouldn't be relative to a toggle IMO

@afercia
Copy link
Contributor

afercia commented Jan 18, 2018

it's ok to handle the focusOnMount and focusReturn together but you think we shouldn't use this HoC in the sidebar/publish panel?

It depends on the component it will be used with. Modals and dropdown and similar always need to get focus on the first tabbable and return focus on the "opener" when closed. So if withFocusReturn is going to always do the two things, then its usage should be limited to only some types of interactions.

Instead, if we want a more generic component, maybe this could be a "focus manager" with different methods that can be used individually? Worth noting there's still one important piece about focus management that's missing as a generic implementation: constraining tabbing within a component. If I'm not wrong, it is implemented in some specific components but there's no generic constrainTabbing. Maybe this could be a third thing to include in a generic "focus manager"?

Noting that the sidebar already had the withFocusReturn HoC before this PR.

Yep I know, and If I'm not wrong yesterday focus was moved back correctly? maybe something changed in the last hours.

@mtias mtias added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jan 26, 2018
@youknowriad
Copy link
Contributor Author

Not sure what are the actionable items in the PR here. Talking about this particular HoC and not other accessibility utilities.

@youknowriad
Copy link
Contributor Author

I still think we should consolidate focusOnOpen and withFocusReturn on the same Higher Order Component regardless of the way we fix the publish flow. I'll try to do this in a separate PR.

@youknowriad youknowriad deleted the add/generic-focus-on-open branch April 20, 2018 13:23
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

Successfully merging this pull request may close these issues.

3 participants