-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
a11y: Prevent sidebar focus in site editor on small screens #55934
Conversation
Size Change: +1 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
inert={ showSidebar ? undefined : 'inert' } | ||
inert={ showSidebar ? undefined : 'true' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a typo because the value of the inert attribute is supposed to be a boolean value. Perhaps values other than false
are implicitly treated as true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for saying it was a typo to cover me, but I believe that was my doing. I think I just got it wrong 😅 Nice catch!
( isMobileViewport && canvasMode === 'view' && ! isListPage ) || | ||
( ! isMobileViewport && ( canvasMode === 'view' || ! isEditorPage ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this logic be simplified? The checks in both instances are pretty similar now, and isEditorPage
is defined as: const isEditorPage = ! isListPage;
. On larger screens, the check canvasMode === 'view'
is enough to get it to be true
. Maybe all we need is canvasMode === 'view'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
Maybe all we need is
canvasMode === 'view'
?
I tried to find out why each viewport has a condition, and why isEditorPage
and isListPage
are included in the conditions.
One reason seems to be to properly control the sidebar on the Pattern page.
On the Pattern page, canvasMode
is always view
regardless of the viewport. However, in the mobile viewport, when a pattern category is selected, the sidebar must be hidden even if the canvasMode
is view
. Otherwise, the two regions, sidebar and pattern content, will be rendered overlapping, as shown in the screenshot below.
I believe that avoiding this is the reason for such complicated conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for looking into this! I played around with it as well, and I think we could remove the ! isEditorPage
from the not mobile conditional, but since that isn't related to this PR it could be a follow-up if you also think it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Nice research!
Thanks for the review, @jeryj! |
1 similar comment
Thanks for the review, @jeryj! |
Fixes #55908
What?
This PR fixes an issue where focus could be moved to invisible elements in the sidebar of the site editor on small screens.
Why?
When you do not want the focus to move to the sidebar, it is expected to apply the inert attribute. This attribute is controlled by the showSidebar attribute, but in the case of mobile viewports, the only condition is that it is not a list page (All Templates, All Template Parts, All Pages), and canvas mode was not taken into account.
How?
Added the condition that canvas mode is view mode.
Testing Instructions
edit-site-layout__sidebar
class in the developer tools.inert
attribute, and you should be able to move focus properly using the keyboard.inert
attribute is given to the sidebar, and no invisible focus movement should occur.Screenshots or screencast
0df04ff7f9a665301820b82d5ff5d1af.mp4