From 9075227b0fbd8848b2ae703d249e9491ad5397e0 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Sun, 30 Jan 2022 17:08:33 -0500 Subject: [PATCH 01/13] Add aria-expanded to block selection button to force the announcement. --- .../block-editor/src/components/list-view/block-contents.js | 2 ++ .../src/components/list-view/block-select-button.js | 2 ++ packages/block-editor/src/components/list-view/block.js | 1 + 3 files changed, 5 insertions(+) diff --git a/packages/block-editor/src/components/list-view/block-contents.js b/packages/block-editor/src/components/list-view/block-contents.js index 61e221b77f1066..071cd11cd70b29 100644 --- a/packages/block-editor/src/components/list-view/block-contents.js +++ b/packages/block-editor/src/components/list-view/block-contents.js @@ -26,6 +26,7 @@ const ListViewBlockContents = forwardRef( position, siblingBlockCount, level, + isExpanded, ...props }, ref @@ -71,6 +72,7 @@ const ListViewBlockContents = forwardRef( draggable={ draggable } onDragStart={ onDragStart } onDragEnd={ onDragEnd } + isExpanded={ isExpanded } { ...props } /> ) } diff --git a/packages/block-editor/src/components/list-view/block-select-button.js b/packages/block-editor/src/components/list-view/block-select-button.js index 87029cd066cefa..7a7f3b99a1a6d9 100644 --- a/packages/block-editor/src/components/list-view/block-select-button.js +++ b/packages/block-editor/src/components/list-view/block-select-button.js @@ -36,6 +36,7 @@ function ListViewBlockSelectButton( onDragStart, onDragEnd, draggable, + isExpanded, }, ref ) { @@ -81,6 +82,7 @@ function ListViewBlockSelectButton( onDragEnd={ onDragEnd } draggable={ draggable } href={ `#block-${ clientId }` } + aria-expanded={ isExpanded } > diff --git a/packages/block-editor/src/components/list-view/block.js b/packages/block-editor/src/components/list-view/block.js index a7746463c5adfd..9aee99e2c2eba7 100644 --- a/packages/block-editor/src/components/list-view/block.js +++ b/packages/block-editor/src/components/list-view/block.js @@ -185,6 +185,7 @@ function ListViewBlock( { ref={ ref } tabIndex={ tabIndex } onFocus={ onFocus } + isExpanded={ isExpanded } /> ) } From b762d399cefc3e7b9b488706ffbbc655d5c056f1 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Sun, 30 Jan 2022 17:35:28 -0500 Subject: [PATCH 02/13] Allow expand on column in index 0. Prevent focus from moving to next column if collapsed. --- packages/components/src/tree-grid/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index 62afdb6a9eb7c7..25eb8bfad87b37 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -91,8 +91,8 @@ function TreeGrid( ); } - // Focus is either at the left or right edge of the grid. - if ( nextIndex === currentColumnIndex ) { + // Focus is at the left of the grid. + if ( currentColumnIndex === 0 ) { if ( keyCode === LEFT ) { // Left: // If a row is focused, and it is expanded, collapses the current row. @@ -150,6 +150,9 @@ function TreeGrid( } // Focus the next element. + if ( activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { + nextIndex = nextIndex - 1; + } focusablesInRow[ nextIndex ].focus(); // Prevent key use for anything else. This ensures Voiceover From 79bd435057c4fcee42f321d399075bf470e1266d Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Sun, 30 Jan 2022 23:59:37 -0500 Subject: [PATCH 03/13] Shorten var. --- packages/components/src/tree-grid/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index 25eb8bfad87b37..a1a1027625524a 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -151,7 +151,7 @@ function TreeGrid( // Focus the next element. if ( activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { - nextIndex = nextIndex - 1; + nextIndex -= 1; } focusablesInRow[ nextIndex ].focus(); From 1baf983f4f84d576b093a7f6bf6ace08c84cb490 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 31 Jan 2022 01:29:13 -0500 Subject: [PATCH 04/13] Update code comment. --- packages/components/src/tree-grid/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index a1a1027625524a..b07e33c5117290 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -149,7 +149,7 @@ function TreeGrid( return; } - // Focus the next element. + // Focus the next column only if expanded. if ( activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { nextIndex -= 1; } From 8854492a10035269ab917d83e57900f7b9e5e257 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 31 Jan 2022 03:15:20 -0500 Subject: [PATCH 05/13] Make sure focus can go back to row index 0 if coming from above Options button. --- packages/components/src/tree-grid/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index b07e33c5117290..f05d13f5e71941 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -150,7 +150,7 @@ function TreeGrid( } // Focus the next column only if expanded. - if ( activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { + if ( nextIndex !== 0 && activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { nextIndex -= 1; } focusablesInRow[ nextIndex ].focus(); From 529db2469de4e5d1ce6a40f859db9408f7af2d76 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 31 Jan 2022 03:21:39 -0500 Subject: [PATCH 06/13] Fix lint error. --- packages/components/src/tree-grid/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index f05d13f5e71941..52bb4d9a2bc7c7 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -150,7 +150,10 @@ function TreeGrid( } // Focus the next column only if expanded. - if ( nextIndex !== 0 && activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { + if ( + nextIndex !== 0 && + activeRow.getAttribute( 'aria-expanded' ) === 'false' + ) { nextIndex -= 1; } focusablesInRow[ nextIndex ].focus(); From 110910e1e0ceed9af07793ee55cde6684d2a641c Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 31 Jan 2022 04:00:33 -0500 Subject: [PATCH 07/13] Try to fix bugs. --- packages/components/src/tree-grid/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index 52bb4d9a2bc7c7..bcbbf217708dd6 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -91,8 +91,11 @@ function TreeGrid( ); } - // Focus is at the left of the grid. - if ( currentColumnIndex === 0 ) { + // Focus is either at the left or right edge of the grid. + if ( + nextIndex === currentColumnIndex || + ( currentColumnIndex === 0 && keyCode === RIGHT ) + ) { if ( keyCode === LEFT ) { // Left: // If a row is focused, and it is expanded, collapses the current row. @@ -151,10 +154,10 @@ function TreeGrid( // Focus the next column only if expanded. if ( - nextIndex !== 0 && + keyCode === RIGHT && activeRow.getAttribute( 'aria-expanded' ) === 'false' ) { - nextIndex -= 1; + return; } focusablesInRow[ nextIndex ].focus(); From 2f574201a76e6e275659c984fc63e23cf21813ca Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Fri, 4 Feb 2022 00:42:26 -0500 Subject: [PATCH 08/13] Check that activeRow contains aria-expanded vs. checking the column index. Update comments. --- packages/components/src/tree-grid/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index bcbbf217708dd6..bf78c99e55569a 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -91,10 +91,11 @@ function TreeGrid( ); } - // Focus is either at the left or right edge of the grid. + // Focus is either at the left or right edge of the grid. Allow Right Arrow to expand the row. if ( nextIndex === currentColumnIndex || - ( currentColumnIndex === 0 && keyCode === RIGHT ) + ( activeRow.hasAttribute( 'aria-expanded' ) && + keyCode === RIGHT ) ) { if ( keyCode === LEFT ) { // Left: @@ -152,10 +153,10 @@ function TreeGrid( return; } - // Focus the next column only if expanded. + // Focus the next column only if expanded. Checking Right Arrow key here that way Left Arrow can always get back to the previous column regardless of the row state. if ( - keyCode === RIGHT && - activeRow.getAttribute( 'aria-expanded' ) === 'false' + activeRow.getAttribute( 'aria-expanded' ) === 'false' && + keyCode === RIGHT ) { return; } From da17b517a9e27235b9bd04f5e91ecd9c385b36df Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 7 Feb 2022 23:12:14 -0500 Subject: [PATCH 09/13] Try to make code cleaner. Update the Changelog. --- packages/components/CHANGELOG.md | 5 +---- packages/components/src/placeholder/index.js | 14 ++++++-------- .../components/src/placeholder/style.scss | 12 ------------ .../components/src/placeholder/test/index.js | 19 +------------------ packages/components/src/tree-grid/index.js | 19 ++++++++----------- 5 files changed, 16 insertions(+), 53 deletions(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index f147e9015da4bc..7c311b86395367 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -7,14 +7,11 @@ - Components: Fix `Slot`/`Fill` Emotion `StyleProvider` ([#38237](https://github.com/WordPress/gutenberg/pull/38237)) - Reduce height and min-width of the reset button on `ComboBoxControl` for consistency. ([#38020](https://github.com/WordPress/gutenberg/pull/38020)) - Removed unused `rememo` dependency ([#38388](https://github.com/WordPress/gutenberg/pull/38388)). -- Added `__unstableInputWidth` to `UnitControl` type definition ([#38429](https://github.com/WordPress/gutenberg/pull/38429)). -- Fixed typing errors for `ColorPicker` ([#38430](https://github.com/WordPress/gutenberg/pull/38430)). -- Updated destructuring of `Dropdown` props to be TypeScript friendly ([#38431](https://github.com/WordPress/gutenberg/pull/38431)). -- Added `ts-nocheck` to `ColorIndicator` so it can be used in typed components ([#38433](https://github.com/WordPress/gutenberg/pull/38433)). ### Enhancements - Update the visual design of the `Spinner` component. ([#37551](https://github.com/WordPress/gutenberg/pull/37551)) +- TreeGrid accessibility enhancements. (#38358) ## 19.3.0 (2022-01-27) diff --git a/packages/components/src/placeholder/index.js b/packages/components/src/placeholder/index.js index a5a88757249ab4..2dbed625f18098 100644 --- a/packages/components/src/placeholder/index.js +++ b/packages/components/src/placeholder/index.js @@ -73,14 +73,12 @@ function Placeholder( { { label } -
- { !! instructions && ( - - { instructions } - - ) } - { children } -
+ { !! instructions && ( +
+ { instructions } +
+ ) } +
{ children }
); } diff --git a/packages/components/src/placeholder/style.scss b/packages/components/src/placeholder/style.scss index 4941d20ad40ed6..53df5294e497fd 100644 --- a/packages/components/src/placeholder/style.scss +++ b/packages/components/src/placeholder/style.scss @@ -77,18 +77,6 @@ } } -// Overrides for browser and editor fieldset styles. -.components-placeholder__fieldset.components-placeholder__fieldset { - border: none; - padding: 0; - - .components-placeholder__instructions { - padding: 0; - font-weight: normal; - font-size: 1em; - } -} - .components-placeholder__fieldset.is-column-layout, .components-placeholder__fieldset.is-column-layout form { flex-direction: column; diff --git a/packages/components/src/placeholder/test/index.js b/packages/components/src/placeholder/test/index.js index e2d787bc51b40c..758c6bed303942 100644 --- a/packages/components/src/placeholder/test/index.js +++ b/packages/components/src/placeholder/test/index.js @@ -88,7 +88,7 @@ describe( 'Placeholder', () => { const element =
Fieldset
; const placeholder = shallow( ); const placeholderFieldset = placeholder.find( - 'fieldset.components-placeholder__fieldset' + '.components-placeholder__fieldset' ); const child = placeholderFieldset.childAt( 0 ); @@ -96,23 +96,6 @@ describe( 'Placeholder', () => { expect( child.matchesElement( element ) ).toBe( true ); } ); - it( 'should display a legend if instructions are passed', () => { - const element =
Fieldset
; - const instructions = 'Choose an option.'; - const placeholder = shallow( - - ); - const placeholderLegend = placeholder.find( - 'legend.components-placeholder__instructions' - ); - - expect( placeholderLegend.exists() ).toBe( true ); - expect( placeholderLegend.text() ).toEqual( instructions ); - } ); - it( 'should add an additional className to the top container', () => { const placeholder = shallow( diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index bf78c99e55569a..8e155982241910 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -78,6 +78,10 @@ function TreeGrid( const activeRow = activeElement.closest( '[role="row"]' ); const focusablesInRow = getRowFocusables( activeRow ); const currentColumnIndex = focusablesInRow.indexOf( activeElement ); + const canExpandCollapse = 0 === currentColumnIndex; + const cannotFocusNextColumn = + activeRow.getAttribute( 'aria-expanded' ) === 'false' && + keyCode !== LEFT; if ( includes( [ LEFT, RIGHT ], keyCode ) ) { // Calculate to the next element. @@ -91,12 +95,8 @@ function TreeGrid( ); } - // 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' ) && - keyCode === RIGHT ) - ) { + // Focus is at the left most column. + if ( canExpandCollapse ) { if ( keyCode === LEFT ) { // Left: // If a row is focused, and it is expanded, collapses the current row. @@ -153,11 +153,8 @@ function TreeGrid( return; } - // Focus the next column only if expanded. Checking Right Arrow key here that way Left Arrow can always get back to the previous column regardless of the row state. - if ( - activeRow.getAttribute( 'aria-expanded' ) === 'false' && - keyCode === RIGHT - ) { + // Focus the next element. If at most left column and row is collapsed, moving right is not allowed as this will expand. However, if row is collapsed, moving left is allowed. + if ( cannotFocusNextColumn ) { return; } focusablesInRow[ nextIndex ].focus(); From 5cb7f6b4c19fdcea5e1093a89c7277b354ecb33e Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 7 Feb 2022 23:24:28 -0500 Subject: [PATCH 10/13] Revert some files. --- packages/components/src/placeholder/index.js | 14 ++++++++------ .../components/src/placeholder/style.scss | 12 ++++++++++++ .../components/src/placeholder/test/index.js | 19 ++++++++++++++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/packages/components/src/placeholder/index.js b/packages/components/src/placeholder/index.js index 2dbed625f18098..a5a88757249ab4 100644 --- a/packages/components/src/placeholder/index.js +++ b/packages/components/src/placeholder/index.js @@ -73,12 +73,14 @@ function Placeholder( { { label } - { !! instructions && ( -
- { instructions } -
- ) } -
{ children }
+
+ { !! instructions && ( + + { instructions } + + ) } + { children } +
); } diff --git a/packages/components/src/placeholder/style.scss b/packages/components/src/placeholder/style.scss index 53df5294e497fd..4941d20ad40ed6 100644 --- a/packages/components/src/placeholder/style.scss +++ b/packages/components/src/placeholder/style.scss @@ -77,6 +77,18 @@ } } +// Overrides for browser and editor fieldset styles. +.components-placeholder__fieldset.components-placeholder__fieldset { + border: none; + padding: 0; + + .components-placeholder__instructions { + padding: 0; + font-weight: normal; + font-size: 1em; + } +} + .components-placeholder__fieldset.is-column-layout, .components-placeholder__fieldset.is-column-layout form { flex-direction: column; diff --git a/packages/components/src/placeholder/test/index.js b/packages/components/src/placeholder/test/index.js index 758c6bed303942..e2d787bc51b40c 100644 --- a/packages/components/src/placeholder/test/index.js +++ b/packages/components/src/placeholder/test/index.js @@ -88,7 +88,7 @@ describe( 'Placeholder', () => { const element =
Fieldset
; const placeholder = shallow( ); const placeholderFieldset = placeholder.find( - '.components-placeholder__fieldset' + 'fieldset.components-placeholder__fieldset' ); const child = placeholderFieldset.childAt( 0 ); @@ -96,6 +96,23 @@ describe( 'Placeholder', () => { expect( child.matchesElement( element ) ).toBe( true ); } ); + it( 'should display a legend if instructions are passed', () => { + const element =
Fieldset
; + const instructions = 'Choose an option.'; + const placeholder = shallow( + + ); + const placeholderLegend = placeholder.find( + 'legend.components-placeholder__instructions' + ); + + expect( placeholderLegend.exists() ).toBe( true ); + expect( placeholderLegend.text() ).toEqual( instructions ); + } ); + it( 'should add an additional className to the top container', () => { const placeholder = shallow( From 7ed247a5ddc1b900a6218e84997833d663f2063b Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Mon, 7 Feb 2022 23:27:00 -0500 Subject: [PATCH 11/13] Fix Changelog. --- packages/components/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 7c311b86395367..adb9f8926cf5f4 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -7,6 +7,11 @@ - Components: Fix `Slot`/`Fill` Emotion `StyleProvider` ([#38237](https://github.com/WordPress/gutenberg/pull/38237)) - Reduce height and min-width of the reset button on `ComboBoxControl` for consistency. ([#38020](https://github.com/WordPress/gutenberg/pull/38020)) - Removed unused `rememo` dependency ([#38388](https://github.com/WordPress/gutenberg/pull/38388)). +- Added `__unstableInputWidth` to `UnitControl` type definition ([#38429](https://github.com/WordPress/gutenberg/pull/38429)). +- Fixed typing errors for `ColorPicker` ([#38430](https://github.com/WordPress/gutenberg/pull/38430)). +- Updated destructuring of `Dropdown` props to be TypeScript friendly ([#38431](https://github.com/WordPress/gutenberg/pull/38431)). +- Added `ts-nocheck` to `ColorIndicator` so it can be used in typed components ([#38433](https://github.com/WordPress/gutenberg/pull/38433)). +- Added `cx` as a dependency of `useMemo` across the whole package, in order to recalculate the classnames correctly when a component is rendered across more than one `StyleProvider` ([#38541](https://github.com/WordPress/gutenberg/pull/38541)). ### Enhancements @@ -34,6 +39,7 @@ ### Experimental - Add basic history location support to `Navigator` ([#37416](https://github.com/WordPress/gutenberg/pull/37416)). +- Add focus restoration to `Navigator` ([#38149](https://github.com/WordPress/gutenberg/pull/38149)). ## 19.2.0 (2022-01-04) From b09484fd2f0203b4f9674e3a25c3b5549351f833 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Tue, 8 Feb 2022 02:17:52 -0500 Subject: [PATCH 12/13] Update packages/components/src/tree-grid/index.js Improvement for more than 2 elements. Co-authored-by: Daniel Richards --- packages/components/src/tree-grid/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index 8e155982241910..6a199b01157168 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -80,8 +80,9 @@ function TreeGrid( const currentColumnIndex = focusablesInRow.indexOf( activeElement ); const canExpandCollapse = 0 === currentColumnIndex; const cannotFocusNextColumn = + canExpandCollapse && activeRow.getAttribute( 'aria-expanded' ) === 'false' && - keyCode !== LEFT; + keyCode === RIGHT; if ( includes( [ LEFT, RIGHT ], keyCode ) ) { // Calculate to the next element. From ec7153306ae49848e9cfd2d858fb700d68744009 Mon Sep 17 00:00:00 2001 From: Alex Stine Date: Tue, 8 Feb 2022 02:20:24 -0500 Subject: [PATCH 13/13] Fix formatting error. --- packages/components/src/tree-grid/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/tree-grid/index.js b/packages/components/src/tree-grid/index.js index 6a199b01157168..a04c6c266d9bd2 100644 --- a/packages/components/src/tree-grid/index.js +++ b/packages/components/src/tree-grid/index.js @@ -80,7 +80,7 @@ function TreeGrid( const currentColumnIndex = focusablesInRow.indexOf( activeElement ); const canExpandCollapse = 0 === currentColumnIndex; const cannotFocusNextColumn = - canExpandCollapse && + canExpandCollapse && activeRow.getAttribute( 'aria-expanded' ) === 'false' && keyCode === RIGHT;