-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix keyboard navigation on the Image block toolbar #25127
Conversation
Size Change: -12 B (0%) Total Size: 1.2 MB
ℹ️ View Unchanged
|
This reverts commit dfde4c7.
@@ -21,11 +21,16 @@ | |||
min-height: $block-toolbar-height; | |||
margin: 0; | |||
border: $border-width solid $gray-900; | |||
border-radius: $radius-block-ui; |
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.
It was used in the legacy toolbar apparently to make toolbar groups rounded, but it seems that it's not needed anymore.
|
||
.wp-block-template-part__preview-dropdown-button { | ||
border-right: $border-width solid $gray-900; | ||
} |
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've updated the code to use ToolbarGroup
instead of just a <div>
, so these styles that were simulating a toolbar group aren't needed anymore.
function AspectMenu( { | ||
toggleProps, | ||
isDisabled, | ||
onClick, | ||
value, | ||
defaultValue, | ||
} ) { | ||
return ( | ||
<DropdownMenu | ||
icon={ aspectRatioIcon } | ||
label={ __( 'Aspect Ratio' ) } | ||
popoverProps={ POPOVER_PROPS } | ||
toggleProps={ toggleProps } |
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.
toggleProps
wasn't being passed to this component. That's why it wasn't being considered a ToolbarItem
.
& .components-toolbar.components-toolbar { | ||
border-width: 0; | ||
margin: 0; | ||
} |
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 snippet is already used in the new toolbar. This code also applies it to the legacy toolbar.
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 tested out the image editor and the template part, and those work as expected. It also seems to fix a styling issue with the toolbar.
Before (master, f5c32f8):
After (this PR):
Thanks for working on this. However, I'm not sure it's a good pattern because, besides the focus loss, the "roving tabindex" can't work this way. When the toolbar is displayed and users tab back and forth from the block to its toolbar, focus is expected to go on the last button that received focus. If some of these buttons are just removed from the DOM, the "roving tabindex" is just broken. Will comment on the issue with additional considerations. |
Fixes #24766
This PR addresses the case where replacing parts of the block toolbar "on the fly" breaks keyboard navigation when the new buttons aren't using
ToolbarItem
orToolbarButton
components, like in the Image block toolbar.It should've shown a deprecation warning, but this change had introduced a regression where the block toolbar stopped tracking new elements inside it. The changes in the
navigable-toolbar
component are related to this.It doesn't fix the focus loss issue, which is a separate problem that will be fixed in a follow-up PR. Currently, the user would have to press Shift+Tab to go back to the toolbar after clicking on the crop button.
Screenshots
How to test
Site editor
Currently, the block toolbar doesn't support text fields. In the Site Editor, the Template parts toolbar adds a text field asynchronously. Now it fallbacks to the legacy toolbar. It shows a deprecation warning that has been ignored in the tests for now.