Skip to content
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

Merged
merged 10 commits into from
Sep 24, 2020

Conversation

diegohaz
Copy link
Member

@diegohaz diegohaz commented Sep 7, 2020

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 or ToolbarButton 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

Using the crop function in the Image block toolbar with the keyboard

How to test

  • Create an image block.
  • Activate the crop button.
  • Check if the toolbar works with the keyboard as expected.

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.

Template parts block toolbar with a text field inside

@github-actions
Copy link

github-actions bot commented Sep 7, 2020

Size Change: -12 B (0%)

Total Size: 1.2 MB

Filename Size Change
build/block-editor/index.js 128 kB -31 B (0%)
build/block-library/editor-rtl.css 8.57 kB -16 B (0%)
build/block-library/editor.css 8.57 kB -16 B (0%)
build/block-library/index.js 135 kB +10 B (0%)
build/components/style-rtl.css 15.5 kB +8 B (0%)
build/components/style.css 15.5 kB +9 B (0%)
build/edit-site/index.js 19 kB +24 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.41 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 8.53 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/style-rtl.css 7.6 kB 0 B
build/block-library/style.css 7.59 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.8 kB 0 B
build/components/index.js 201 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 12.2 kB 0 B
build/data-controls/index.js 1.28 kB 0 B
build/data/index.js 8.55 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.48 kB 0 B
build/edit-navigation/index.js 10.7 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 305 kB 0 B
build/edit-post/style-rtl.css 6.24 kB 0 B
build/edit-post/style.css 6.22 kB 0 B
build/edit-site/style-rtl.css 3.13 kB 0 B
build/edit-site/style.css 3.13 kB 0 B
build/edit-widgets/index.js 16.4 kB 0 B
build/edit-widgets/style-rtl.css 2.75 kB 0 B
build/edit-widgets/style.css 2.75 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.8 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@@ -21,11 +21,16 @@
min-height: $block-toolbar-height;
margin: 0;
border: $border-width solid $gray-900;
border-radius: $radius-block-ui;
Copy link
Member Author

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;
}
Copy link
Member Author

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.

Comment on lines +63 to +75
function AspectMenu( {
toggleProps,
isDisabled,
onClick,
value,
defaultValue,
} ) {
return (
<DropdownMenu
icon={ aspectRatioIcon }
label={ __( 'Aspect Ratio' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
Copy link
Member Author

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;
}
Copy link
Member Author

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.

Copy link
Contributor

@ajlende ajlende left a 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):

master-broken-toolbar

After (this PR):

25127-fixed-toolbar

@diegohaz diegohaz merged commit a3c50d6 into master Sep 24, 2020
@diegohaz diegohaz deleted the try/image-block-toolbar-roving-tabindex branch September 24, 2020 18:03
@github-actions github-actions bot added this to the Gutenberg 9.1 milestone Sep 24, 2020
@diegohaz diegohaz self-assigned this Sep 24, 2020
@diegohaz diegohaz added [a11y] Keyboard & Focus [Type] Bug An existing feature does not function as intended labels Sep 24, 2020
@diegohaz diegohaz added [Package] Block library /packages/block-library [Type] Regression Related to a regression in the latest release and removed [Type] Bug An existing feature does not function as intended labels Sep 24, 2020
@afercia
Copy link
Contributor

afercia commented Sep 28, 2020

It doesn't fix the focus loss issue, which is a separate problem that will be fixed in a follow-up 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.

@priethor priethor added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block library /packages/block-library [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The image block's editing tools break the toolbar keyboard accessibility
4 participants