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 improvements for List View Part 1 #37798
Conversation
|
This focus issue really baffles me. 😞 If you press Escape while List View is open, focus is placed on List View button properly. However, if you select Close, focus fails and you just get hung out in the page. I switched to useEffect that way I could listen to the List View open from store. Probably not a great solution but it works 100% for both cases. What do you all think? Is there something I'm missing on useFocusReturn that could be causing this? I may try to debug later this weekend... Thanks! |
|
Size Change: -544 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
I think I see why. The ref returned by A way to test this, if you open List View, shift-tab to the close button and then press escape you'll see focus is lost then also. So it's more about where the focus resides when the panel is closed. Things seem to work ok if the line I did think that only |
|
Two separate focus return refs seems to resolve all issues. There might be a better way. Here's some code: const focusOnMountRef = useFocusOnMount( 'firstElement' );
const headerFocusReturnRef = useFocusReturn();
const contentFocusReturnRef = useFocusReturn();
function closeOnEscape( event ) {
if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
event.preventDefault();
setIsListViewOpened( false );
}
}
const instanceId = useInstanceId( ListViewSidebar );
const labelId = `edit-post-editor__list-view-panel-label-${ instanceId }`;
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
aria-labelledby={ labelId }
className="edit-post-editor__list-view-panel"
onKeyDown={ closeOnEscape }
>
<div
className="edit-post-editor__list-view-panel-header"
ref={ headerFocusReturnRef }
>
<strong id={ labelId }>{ __( 'List view' ) }</strong>
<Button
icon={ closeSmall }
label={ __( 'Close list view sidebar' ) }
onClick={ () => setIsListViewOpened( false ) }
/>
</div>
<div
className="edit-post-editor__list-view-panel-content"
ref={ useMergeRefs( [
contentFocusReturnRef,
focusOnMountRef,
] ) }
>
<ListView
onSelect={ selectEditorBlock }
showNestedBlocks
__experimentalFeatures
__experimentalPersistentListViewFeatures
/>
</div>
</div>
); |
|
@talldan Is there anything wrong with just using how I made the PR? I know it seems a little unconventional, but it works without much effort. I wish I could just use the dialog approach like the Inserter uses, but focus shouldn't be constrained to this element. |
|
@alexstine If we can use the existing |
|
@talldan I honestly have no idea how this even works but it works. Let me finish applying the fixes to other packages and I'll push fresh commit. Something weird happening in logic for sure. |
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 is working well for me! Yeah, there seems to be some weird interaction between useFocusReturn and useFocusOnMount, but I can't think of a better solution offhand, so ✅
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.
Working well for me as well. Thank you.
|
The code looks good to me... I only have one question: Why did we change the case to some sentences here, capitalizing the 1st letter of every word? I was under the impression that we're generally trying to avoid that 🤔 |
|
I was wondering the same, but it seems we are capitalizing feature names: |
|
Ah OK, gotcha. Makes sense then 👍 |
Description
How has this been tested?
I tested in Firefox with the NVDA screen reader. Changes only applied to Posts and Pages for now.
Screenshots
Types of changes
Bug fix and enhancement
Checklist:
*.native.jsfiles for terms that need renaming or removal).