-
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
Navigable regions: skip empty regions #63687
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
This change makes sense to me, although I'll let others with more experience in navigating the editor region-by-region also leave their feedback before approving and merging.
We will also need a CHANGELOG entry (and potentially a dev note).
@@ -49,7 +49,7 @@ export function useNavigateRegions( shortcuts: Shortcuts = defaultShortcuts ) { | |||
function focusRegion( offset: number ) { | |||
const regions = Array.from( | |||
ref.current?.querySelectorAll< HTMLElement >( | |||
'[role="region"][tabindex="-1"]' | |||
'[role="region"][tabindex="-1"]:not(:empty)' |
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.
Will do the job, although it's not perfect, since it :empty
will be false if there's even just a whitespace character, like a space or a newline:
Children can be either element nodes or text (including whitespace)
Still, better than before 👍
@@ -49,7 +49,7 @@ export function useNavigateRegions( shortcuts: Shortcuts = defaultShortcuts ) { | |||
function focusRegion( offset: number ) { | |||
const regions = Array.from( | |||
ref.current?.querySelectorAll< HTMLElement >( | |||
'[role="region"][tabindex="-1"]' | |||
'[role="region"][tabindex="-1"]:not(:empty)' |
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 also wish we had some tests for this 🤔
Not a blocker for the PR of course.
@@ -49,7 +49,7 @@ export function useNavigateRegions( shortcuts: Shortcuts = defaultShortcuts ) { | |||
function focusRegion( offset: number ) { | |||
const regions = Array.from( | |||
ref.current?.querySelectorAll< HTMLElement >( | |||
'[role="region"][tabindex="-1"]' | |||
'[role="region"][tabindex="-1"]:not(:empty)' |
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.
Let's definitely include a CHANGELOG entry for this.
Thanks for this PR but I don't think this is the behavior we'd want for the landmarks / navigable regions. Coincidentally, I discussed how to improve landmarks / navigable regions with @joedolson at WCEU in June. When using ARIA landmarks, the UI informs users the page content is split in a certain number of main sections. From that moment on, users would expect to find the same amount and type of ladnmarks in any state of the UI. That is to say ladnmarks should be 'static' and never appear or disappear or be 'skipped' dynamically. This leads to the problem of what to do when a landmark is 'empty'. In the context of the editor this typically happens when one of the side panels is collapsed. The original implementation discussed with @jorgefilipecosta I think at WCEU Belgrade in 2018 was to keep all the landmarks / navigable regions always rendered and, when the panel they are supposed to contain is closed, to provide a Button that is only revealed on focus. The Button is the content of the landmarks / navigable regions when collapsed and it opens the associated panel. This worked for some time in the editor. There is still an Open publish panel button that works this way. There used to be a similar 'Open block settings / Open document settings' button that was removed I think in #60561 thus breaking the original intent of the lanrmarks implementation. Other panels were implemented but never added the 'toggle button' for the empty state. Skipping ARIA landmarks wouldn't be expected. The amount and purpose of the landmarks should never change and should be predictable. Instead of the approach in this PR, I would strongly recommend to open a new issue and consider how to make the landmarks / navigable regions implementation solid and be part of the design guide lines of this project. Pinging @joedolson for any additional thoughts he may want to add. I'm sorry I understand the frustration when spending time and efforts with intent to make things better turns out to not be the best solution but maybe this proves that creating an issue for broader discussion before coding, as required by the contributing guidelines of this project, would help. Cc @youknowriad as we discussed this point related to process during WCEU. |
Are you suggesting that in an SPA (or an application with multiple pages but where the navigation happens client side), we can't use ARIA landmarks because we can't guarantee that the regions are consistent between all the pages? |
Did I say we can't use them? For example: consider the Inserter and the List view. They are ARIA landmarks / navigable regions. By default, they are not rendered. As such, on page load a screen reader would perceive 6 landmarks (including the WordPress 'main"). Screenshot to visually illustrate by using the Firefox Landmarks add-on: When opening the Inserter and the List view, the landmarks suddenly become 7: In most of the cases, focus will already be inside the Inserter or the List view. In such a case, a landmark isn't useful at all for users. It is not expected to be there. And when it's there, it's not useful that is a landmark. Instead, a more solid principle would be to uae 5 landmarks in the editor. Inform users that some of these landmarks may contain varying content. Use the interface skeleton to reenforce the logical splitting of the editor sections. Establish guide lines to infomr contributors (designers and developers) that any panel must render within one of the landmarks and provide one accompanying toggle button to open it. For instance:
It wouldn't be a big deal if a ladnarmk contains for instance 3 toggle buttons when the panel are collapsed. That's what I discussed with @jeodolson at WCEU. |
yeah, you're right you didn't say don't use them but for me, this is exactly what it means. You say that the editor should container the following landmarks
That makes sense to me but where it doesn't is that the site editor is not a just an editor, it's actually several pages that are different from each other:
I'm trying to think what this guideline means (regions can't be dynamic). How hard that rule is?
|
Yes I agree the Site Editor is already different as in the view mode / edit mode have inherently different main sections and thus different landmarks. With data views and future new layouts the 5 landmarks example may not make sense any longer. I'd think e should really sit down and think together at how to solve this in a solid, future-proof way. |
In this case I anticipated the approach was probably at best a band-aid. No frustration here and I appreciate you elaborating on what should be done better.
Seems like there’s a chance this could still work in Site editor but probably only if it’s okay for a landmarks to switch to another DOM element. I expect the original ordering of landmarks must be preserved which might also make it too difficult to attempt this, but for instance:
Right now the site editor navigation is in another part of the DOM and can’t be contained by the same parent region as the Insert/List View. Would it be okay if the parent around the List View and Inserter stopped being the Navigation landmark at the same instant the site editor navigation becomes the Navigation landmark and vice versa? |
What?
A fix to skip empty regions when using the keyboard shortcuts.
Why?
Empty regions are currently navigated/focused by the shortcuts and yet don’t have any content. It also creates a feeling like the shortcut didn’t work or you failed to press the key because an empty region isn’t visibly focused yet is still a “stop” in the circuit of regions.
How?
Simply excludes empty regions by only matching
:not(:empty)
regions.Testing Instructions
This is applicable in any editor but it’s worth noting that the Post editor has one empty region when the "Editor settings" sidebar is not open. The Site editor has two when in edit mode and the "Editor Settings" sidebar is not open.
Testing Instructions for Keyboard
I think the above instructions suffice?
Screenshots or screencast
Before (Site editor)
navigate-regions-trunk.mp4
After (Site editor)
navigate-regions-skip-empty.mp4