-
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
Keyboard accessibility: Add a "Skip link" to jump back from the inspector to the selected block #5856
Conversation
Whilst I would like to change those, I think keeping it the same is sensible. Changing to me seems like we'd cause friction where none is needed. Position wise it seems to make sense tabbing through. Is it usual to have such skips in different places on screens? It totally may be, which is why asking for insights. |
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.
Design wise this is just like core so giving it approval for now.
@@ -0,0 +1,27 @@ | |||
.skip-to-selected-block { |
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 class name does not adhere to the Gutenberg naming conventions:
https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#naming
It should be corrected to .editor-skip-to-selected-block
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.
Yep, I've used editor-
initially then removed waiting for a feedback about the placement of the whole thing,
} | ||
} | ||
|
||
.edit-post-sidebar .skip-to-selected-block:focus { |
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.
edit-post
is a superset of (extends) the underlying editor
, so there should not be awareness of that context from here. These styles, if needed, should be applied within edit-post/components/sidebar/style.scss
(also better reflecting that they're specific to the edit-post sidebar, for someone looking for those styles).
editor/utils/dom.js
Outdated
@@ -16,6 +16,10 @@ export function getBlockDOMNode( uid ) { | |||
return document.querySelector( '[data-block="' + uid + '"]' ); | |||
} | |||
|
|||
export function getBlockWrapperDOMNode( uid ) { |
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.
Can we add a JSDoc block here describing the intended behavior, arguments, and return value? That we describe this as expected to return an element with tabIndex might reveal that it could potentially benefit from a more appropriate name: getBlockTabbableWrapper
? I don't feel strongly; proposed name is fine too.
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 yes, forgot to do that.
@@ -0,0 +1,37 @@ | |||
/** |
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.
Aside: If "Skip To" buttons are expected to be commonplace, could make for a good base components
component.
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.
Do you mean moving it to the /components
directory?
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.
Yes, maybe not SkipToSelectedBlock
as-is, since it an implementation specific to block usage, but a SkipTo
, which SkipToSelectedBlock
can extend (or just inline SkipTo
where we're using SkipToSelectedBlock
).
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 OK. Hm at the moment I don't see the need for other "Skip To"s, the ones in core and this one should suffice, for now. We can always iterate later, if need be?
|
||
export default withSelect( ( select ) => { | ||
return { | ||
selectedBlock: select( 'core/editor' ).getSelectedBlock(), |
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.
getSelectedBlock
can be a computationally-intensive selector. I wish we had a simpler way to get access to the direct UID value of the singular selected block. We do have getBlockSelectionStart
, but this also returns a value for a multi-selection. Which actually raises another point: do we care if it's a singular block selection? Seems like we'd want to return to the first UID of the set of selected blocks in either case.
@@ -55,6 +55,8 @@ $z-layers: ( | |||
'.components-popover.is-bottom': 99990, | |||
|
|||
'.components-autocomplete__results': 1000000, | |||
|
|||
'.skip-to-selected-block': 100000, |
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.
Why so high? In fact, even without z-index
at all, it appears to layer as I'd expect.
FWIW, this isn't the same as putting the button on equal footing as .edit-post-sidebar
, since it's already within the stacking context of the sidebar.
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.
For re-use in other places e.g. header toolbar, publishing flow, etc. I guess it should have a high z-index.
}; | ||
|
||
return ( | ||
selectedBlock && uid && |
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.
selectedBlock
will never be falsey here. You already have a condition above for ! selectedBlock
.
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.
selectedBlock
is falsey initially and switching (even with mouse) the sidebar to the block inspector renders the skip link (the render method must return "something")
I don't have an answer, I think this is the first time I see a "skip link" to actually jump back :) Will ask the a11y team opinion. |
What's in a word: skip link / jump back. It's all relative to how some sees/uses the page I guess. |
I think I've addressed most of the points, pending feedback on #5856 (comment) For now, it's placed only in the block inspector. I've tested it also with multi-selection and thanks to |
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.
👍
eb20646
to
978b412
Compare
Rebased to solve conflict. |
Nice one! |
This PR adds a way for keyboard and assistive technologies users to jump back to the currently selected block.
Users can already use keyboard shortcuts to navigate the editor regions, see #3084 and screen reader users can use ARIA landmarks, see #2380. These tools can be used to jump from the block being edited to the Sidebar but there's no way to jump back from the sidebar to the block being edited.
This PR adds a reusable component that mimics the "skip links" already used in core. Actually, it's a button that gets revealed just when it receives keyboard focus and, when pressed, moves focus back to the currently selected block.
Related:
For now, it's placed in the block inspector in the sidebar (in the bottom right corner of the screen) but it could be useful also in the "post settings". I could see it also reused in the header toolbar and in the publishing flow, so I guess the best option would be to consider it as a generic component. In this regard, I'm not sure where the new files should be placed. For now they're in the
editor
directory. Any feedback welcome.Screenshot:
Design-wise, I've made it look like the current "skip links" in core, any feedback welcome.
When a better, customizable, shortcut for
navigateRegions
will be available, see:Consider a mechanism to customize shortcuts, e.g. Ctrl + backtick
#3218there will be a way for all keyboard users to jump from the selected block to the sidebar and back from the sidebar to the selected block, thus fixing #1182