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

Accessibility improvements for List View Part 2 #38358

Merged
merged 17 commits into from
Feb 8, 2022

Conversation

alexstine
Copy link
Contributor

@alexstine alexstine commented Jan 30, 2022

Description

I have made further improvements to block-editor/list-view and components/tree-grid.

Testing Instructions

  1. Open a Post or Page.
  2. Insert some Paragraph Blocks and a Columns Block with a selected variation.
  3. Open the List View.
  4. Move through the list with Up and Down Arrow keys.
  5. Once you arrive at the Columns Block, notice how the link now contains aria-expanded. It seems that simply having aria-expanded on the parent table row wasn't working so I added it to the selection link.
  6. Pressing Left Arrow should collapse the section, the screen reader should announce collapsed.
  7. When pressing Right Arrow, you should hear expanded instead of first being placed on the Options button.
  8. Once expanded, you can press Right Arrow again to move to the Options button.

This should also be easy to test on gutenberg.run. Just enter this PR number to build.

Screenshots

Types of changes

Improvement and breaking change

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.

@alexstine alexstine added [Type] Enhancement A suggestion for improvement. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Breaking Change For PRs that introduce a change that will break existing functionality [Package] Components /packages/components Needs Accessibility Feedback Need input from accessibility [Feature] List View Menu item in the top toolbar to select blocks from a list of links. [Package] Block editor /packages/block-editor [a11y] Keyboard & Focus labels Jan 30, 2022
@alexstine alexstine self-assigned this Jan 30, 2022
@github-actions
Copy link

github-actions bot commented Jan 30, 2022

Size Change: +1.46 kB (0%)

Total Size: 1.14 MB

Filename Size Change
build/block-editor/index.min.js 142 kB +697 B (0%)
build/block-editor/style-rtl.css 14.8 kB +230 B (+2%)
build/block-editor/style.css 14.8 kB +231 B (+2%)
build/block-library/index.min.js 167 kB +276 B (0%)
build/components/index.min.js 215 kB +27 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.22 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.4 kB
build/block-library/blocks/cover/style.css 1.4 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 965 B
build/block-library/blocks/gallery/editor.css 967 B
build/block-library/blocks/gallery/style-rtl.css 1.61 kB
build/block-library/blocks/gallery/style.css 1.61 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 810 B
build/block-library/blocks/image/editor.css 809 B
build/block-library/blocks/image/style-rtl.css 500 B
build/block-library/blocks/image/style.css 503 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.98 kB
build/block-library/blocks/navigation/editor.css 1.99 kB
build/block-library/blocks/navigation/style-rtl.css 1.85 kB
build/block-library/blocks/navigation/style.css 1.84 kB
build/block-library/blocks/navigation/view.min.js 2.81 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 402 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 521 B
build/block-library/blocks/post-comments/style.css 521 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 201 B
build/block-library/blocks/quote/style.css 201 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 214 B
build/block-library/blocks/tag-cloud/style.css 215 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 921 B
build/block-library/common.css 919 B
build/block-library/editor-rtl.css 10.1 kB
build/block-library/editor.css 10.1 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 11.1 kB
build/block-library/style.css 11.1 kB
build/block-library/theme-rtl.css 672 B
build/block-library/theme.css 676 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46.4 kB
build/components/style-rtl.css 15.5 kB
build/components/style.css 15.5 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 13.4 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/data/index.min.js 7.44 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16.2 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 29.7 kB
build/edit-post/style-rtl.css 7.15 kB
build/edit-post/style.css 7.14 kB
build/edit-site/index.min.js 41.6 kB
build/edit-site/style-rtl.css 7.22 kB
build/edit-site/style.css 7.21 kB
build/edit-widgets/index.min.js 16.7 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.17 kB
build/editor/index.min.js 38.5 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.58 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.75 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 925 B
build/nux/index.min.js 2.09 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.95 kB
build/primitives/index.min.js 917 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.65 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.58 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@alexstine
Copy link
Contributor Author

@talldan Do you think this is too much of a stretch? I wanted to make sure the row could be expanded without first being all the way to the right but this will prevent users from focussing the Options button until the row is expanded. Do you think this is too much of a breaking change compared to how things currently work? It actually makes more sense to me this way but I can understand the Options menu may be independent of if child Blocks are showing or not. The other thing I had to change was preventing focus on Options button while state is collapsed. The reason being expanded would not be announced if focus were moved to the Options button so if the row is collapsed, it will require 2 Right Arrow key presses to focus the Options button.

@MarcoZehe
Copy link
Contributor

It seems that simply having aria-expanded on the parent table row wasn't working so I added it to the selection link.

Yes, those states only work on the actual element, don't propagate to child elements. And because the link is the focused element within the list view item, it needs to get the expanded state.

@alexstine
Copy link
Contributor Author

@MarcoZehe Thought so, it was an easy enough fix. I kept the aria-expanded on the row so I didn't break future code. It is possible other parts of code would not use child element as it is being used here.

@MarcoZehe
Copy link
Contributor

Good thinking. This also makes it clearer when navigating the grid with the virtual cursor, in NVDA, for example.

Copy link
Contributor

@MarcoZehe MarcoZehe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a play with this, and to me, this makes a lot of sense. This includes the part where you first expand a collapsed element before moving to the options button. Even as a keyboard user, you may want to have a glance at what's hidden under that collapsed column etc. before you move it or such. I'm giving this my approval, but please only merge this once the others have agreed.

@alexstine
Copy link
Contributor Author

@MarcoZehe Thanks for the review.

Yep, I'll be holding off here until I get a decision on if this will be allowed or not. I agree, better UX for sure.

@alexstine
Copy link
Contributor Author

alexstine commented Jan 31, 2022

@talldan Thanks for the review.

If you press left on an already collapsed item that has a parent, focus jumps to the parent. Was that intentional?

I am not sure I understand. Essentially, I only want aria-expanded to change if the current index is equal to 0 that way the first column controls the expand/collapse. If the row is collapsed and I press Left Arrow again, nothing happens. Can you give me steps on how to replicate this? Do I need child of child Blocks?

The second issue is if you navigate onto the Block Settings button of a collapsed block using the up/down arrow keys from the row above, it isn't possible to use the left arrow key. The right arrow key seems to be the only thing that works.

Pushed a commit to fix this, should work fine now.

packages/components/src/tree-grid/index.js Show resolved Hide resolved
nextIndex !== 0 &&
activeRow.getAttribute( 'aria-expanded' ) === 'false'
) {
nextIndex -= 1;
Copy link
Contributor

@talldan talldan Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the part that's confusing about this code is that it doesn't take into account whether the user presses right or left keys. I guess the intention is to prevent any changes to the index? Basically stopping focus from moving? I don't know that it's necessary because the return statement on line 135 prevents the same thing.

It seems to work better for me if I change it to something like this to prevent focus moving beyond the right edge of the grid:

if (
	keyCode === RIGHT &&
	nextIndex === currentColumnIndex
) {
	return;
}

@talldan
Copy link
Contributor

talldan commented Jan 31, 2022

Pushed a commit to fix this, should work fine now.

Thanks. That does fix pressing the left arrow key, but it still seems possible to press the right arrow key when at the right edge of the grid, and focus moves unexpectedly to the left. I don't think that's intentional, but let me know if it is. I left a couple of comments on why that might be.

@alexstine
Copy link
Contributor Author

alexstine commented Jan 31, 2022

@talldan What makes this really difficult is that second column and knowing when to move back and forth. In an ideal world, it should work like this.

  1. If at index 0, you can collapse and expand.
  2. If at index 0, you can only move to index 1 if expanded.
  3. If index 0 is collapsed but you are at index 1, you should be able to return to index 0.

Index 0 being the Block and index 1 being the Options button. Index 0 = Left Arrow, index 1 = Right Arrow.

Pushed a fresh commit, working better?

Comment on lines 156 to 161
if (
nextIndex !== 0 &&
keyCode === RIGHT &&
activeRow.getAttribute( 'aria-expanded' ) === 'false'
) {
nextIndex -= 1;
return;
}
Copy link
Contributor

@talldan talldan Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem I have reviewing here is that I'm not really sure what the desired behavior is.

Should the right key always be prevented from doing anything when a row is collapsed?

Something that needs to be considered is that the TreeGrid component is general purpose. List View has two columns, but another implementation of TreeGrid might have more than two columns, so any code added should take that into account.

I could have a TreeGrid with four columns. Say that the third column of a collapsed row is currently focused. Is the expectation that pressing right does nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@talldan The problem I am trying to solve is this.

  1. I only want the Block selection button to be able to expand and collapse the child Blocks. In the List View, that is the 1st column with index of 0.
  2. The current model is not very user friendly for screen reader users. To expand, you must find the collapsed Block, press Right Arrow to focus the Options button, and then Right Arrow again to expand. The problem is, all the way at the right, the user will not hear the expanded state get updated because Options button contains:
aria-expanded="false"

Because the Options menu for the Block is closed. The only way to know for sure that the row was expanded again is to either navigate with Down Arrow to the first child Block Options button or to press Left Arrow and you should hear the expanded state on the Block selection button.

To be honest, I think this needs a dedicated component as what we're trying to do here is really pretty complex. If not, I have another option that may work.

  1. Expand the List View to 3 columns.
  2. Block name column which will be used to expand/collapse, link that jumps to the Block, and finally the Block Options button.
  3. This way we don't have to worry about relying on table position to expand/collapse. We simply listen for an onClick for the first column.

It may be easier to show you why this doesn't work in practice. If you would like, happy to jump on a quick Zoom and I can show you the big UX improvement between trunk and my branch. Maybe that would be better, that way you can visualize exactly what the problem is?

Thanks for hanging in there with me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered the issue with the options button having its own aria-expanded.

Testing again now and I think the only remaining issue I see in List View is that it's possible to this:

  1. Add a paragraph and a columns block
  2. Focus the columns block in List View and collapse it
  3. Press the up key (focus the paragraph), then the right key (focus the options button of the paragraph), then the down key (focus the options button of the columns block)
  4. Press the right key

Expected: Nothing happens
Actual: The collapsed column is expanded.

The issue here might be screen reader announcements, since the options button's aria-expanded won't change.

Maybe the right arrow key to expand should only work in the first column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I am trying to say. To expand should only happen in the 1st column. The 1st column should be responsible for collapsing and expanding.

Copy link
Member

@ramonjd ramonjd Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not offering much more than has been said, but I've been comparing this PR's changes with trunk.

On trunk the expand does indeed occur on the second td element with a right arrow click.

This PR changes the expand to the first td element.

I can reproduce Dan's scenario above, but it appears to be consistent for all options buttons, that is, I cannot right arrow (only down arrow to the lower blocks' options, or left to select the row).

This appears fairly intuitive to me as I'm at the end item of a single row. The caveat is that I mainly navigate using a pointer. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramonjd The only problem with an approach like this is the way the current column index is working. If I am in the Options column and I press Left Arrow, it will return a current index of 1 which makes no sense because I should not be in the column anymore. None the less, it doesn't work for whatever reason. Calculating indexes like this is turning out to be really unreliable when you want a specific column to do the expanding. It will only return 0 once you are at the edge of the left column or something like that. I don't have vision so can't honestly tell you exactly what it is doing.

How about instead of passing a prop, I attach a data-column-trigger="true"? I know @talldan didn't want to go that way but for me, it seems like it would be safer. That way I can always know that data tag when focus is placed on it, the collapse/expand can work.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point, thanks for explaining. I was, in a clumsy way, trying to advocate for some sort of flag to tell TreeGrid to expand at a certain point.

How about instead of passing a prop, I attach a data-column-trigger="true"?

This sounds like it's worth a shot - I would tend to trust @talldan's judgement on this, but it would be good to see working. Maybe he'll come around ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with an approach like this is the way the current column index is working. If I am in the Options column and I press Left Arrow, it will return a current index of 1 which makes no sense because I should not be in the column anymore. None the less, it doesn't work for whatever reason.

This is the same function that handles the arrow key press and moves focus, so currentColumnIndex is always the index before focus has moved.nextIndex is where focus will end up if the function doesn't return early.

I think @ramonjd's code should work. I wonder if it's needed though, with what's being proposed it seems like column zero would always be the column where expands/collapse works.

The trouble is that this code previously just handled moving focus, but now more stuff has been added to it, and it's a little confusing. If this code were to be rewritten, I think it might be best to assign some well named variables to make the code more readable:

const isCollapsed = activeRow.getAttribute( 'aria-expanded' ) === 'false';
const lastColumnIndex = focusablesInRow.length - 1;
const shouldExpand = isCollapsed && currentColumnIndex === 0 &&  keyCode === RIGHT;
const shouldCollapse = ! isCollapsed && currentColumnIndex === 0 && keyCode === LEFT;
const shouldMoveLeft = ! shouldCollapse && currentColumnIndex > 0 && keyCode === LEFT;
const shouldMoveRight = ! shouldExpand && currentColumnIndex < lastColumnIndex && keyCode === RIGHT;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@talldan I thought at one point you were worried about having another column that could possibly be the one doing the expanding/collapsing. E.g.

<table>
<tr>
<td></td>
<td>Expand/Collapse</td>
</tr>
<tr></tr>
</table>

That is why I was working on extra code to try to add support for any column specified by a developer but adapt it for the List View. If you are okay with column index of 0 (first column) doing all the expanding and collapsing, let me clean the code up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a miscommunication. I'm ok with it just being the first column 👍

Copy link
Contributor Author

@alexstine alexstine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small modification to improve re-usability.

// Focus is either at the left or right edge of the grid. Allow Right Arrow to expand the row.
if (
nextIndex === currentColumnIndex ||
( activeRow.hasAttribute( 'aria-expanded' ) &&
Copy link
Contributor Author

@alexstine alexstine Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the index, I opted to check the activeRow to see if it contained aria-expanded or not. This in theory should be more compatible with possible future uses as it doesn't require a hard coded index value which could change depending on how many td/column elements there are.

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @alexstine , before merging would you mind adding an entry to the CHANGELOG ?

Thank you!

@alexstine
Copy link
Contributor Author

@talldan This looking better?

@alexstine
Copy link
Contributor Author

@ciampo My Changelog update looks good?

Thanks.

alexstine and others added 2 commits February 8, 2022 02:17
Improvement for more than 2 <td> elements.

Co-authored-by: Daniel Richards <[email protected]>
@alexstine
Copy link
Contributor Author

@talldan Changes implemented and still working fine on my end. Any final bug searches?

@talldan
Copy link
Contributor

talldan commented Feb 8, 2022

Seems to work well! Thanks for all your patience, I know I held this one up a bit, appreciate you working with me on the review changes.

@talldan talldan merged commit 271703c into trunk Feb 8, 2022
@talldan talldan deleted the update/list-view-accessibility branch February 8, 2022 08:21
@github-actions github-actions bot added this to the Gutenberg 12.6 milestone Feb 8, 2022
@ciampo
Copy link
Contributor

ciampo commented Feb 8, 2022

@ciampo My Changelog update looks good?

Pretty much! It just missed the full link to the PR, I've opened #38611 to add it :)

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] List View Menu item in the top toolbar to select blocks from a list of links. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Accessibility Feedback Need input from accessibility [Package] Block editor /packages/block-editor [Package] Components /packages/components [Type] Breaking Change For PRs that introduce a change that will break existing functionality [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants