-
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
List view: Refactor ARIA attributes #48461
Changes from 8 commits
0034510
e28899c
ebd1773
ba860a1
9749780
21fc852
55f43ac
88788ba
4c30383
4c2b450
08967ae
54797d5
0833362
115cfdc
0630cf1
b56270b
90f9425
eed5466
17cdc5b
3c9068c
714f331
87b8c8c
e7a577b
cffe7d1
f2abb6a
7e5a6ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,7 @@ import { | |
} from '@wordpress/components'; | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { moreVertical } from '@wordpress/icons'; | ||
import { | ||
useState, | ||
useRef, | ||
useEffect, | ||
useCallback, | ||
memo, | ||
} from '@wordpress/element'; | ||
import { useState, useRef, useCallback, memo } from '@wordpress/element'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { sprintf, __ } from '@wordpress/i18n'; | ||
|
||
|
@@ -53,7 +47,6 @@ function ListViewBlock( { | |
path, | ||
isExpanded, | ||
selectedClientIds, | ||
preventAnnouncement, | ||
isSyncedBranch, | ||
} ) { | ||
const cellRef = useRef( null ); | ||
|
@@ -111,20 +104,13 @@ function ListViewBlock( { | |
level | ||
); | ||
|
||
let blockAriaLabel = __( 'Link' ); | ||
if ( blockInformation ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that the condition to check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that is the case, please check the variable directly below this line. It was not included in this conditional and still used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of the below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too sure if that check is still needed, though, but because #38775 introduced the check, it'd probaly be good to verify before removing the check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yeah, I totally missed that sneaky conditional on that line. NVM. |
||
blockAriaLabel = isLocked | ||
? sprintf( | ||
// translators: %s: The title of the block. This string indicates a link to select the locked block. | ||
__( '%s link (locked)' ), | ||
blockInformation.title | ||
) | ||
: sprintf( | ||
// translators: %s: The title of the block. This string indicates a link to select the block. | ||
__( '%s link' ), | ||
blockInformation.title | ||
); | ||
} | ||
const blockAriaLabel = isLocked | ||
? sprintf( | ||
// translators: %s: The title of the block. This string indicates a link to select the locked block. | ||
__( '%s (locked)' ), | ||
blockInformation.title | ||
) | ||
: blockInformation.title; | ||
|
||
const settingsAriaLabel = blockInformation | ||
? sprintf( | ||
|
@@ -134,8 +120,7 @@ function ListViewBlock( { | |
) | ||
: __( 'Options' ); | ||
|
||
const { isTreeGridMounted, expand, collapse, BlockSettingsMenu } = | ||
useListViewContext(); | ||
const { expand, collapse, BlockSettingsMenu } = useListViewContext(); | ||
|
||
const hasSiblings = siblingBlockCount > 0; | ||
const hasRenderedMovers = showBlockMovers && hasSiblings; | ||
|
@@ -149,15 +134,6 @@ function ListViewBlock( { | |
{ 'is-visible': isHovered || isFirstSelectedBlock } | ||
); | ||
|
||
// If ListView has experimental features related to the Persistent List View, | ||
alexstine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// only focus the selected list item on mount; otherwise the list would always | ||
// try to steal the focus from the editor canvas. | ||
useEffect( () => { | ||
if ( ! isTreeGridMounted && isSelected ) { | ||
cellRef.current.focus(); | ||
} | ||
}, [] ); | ||
|
||
const onMouseEnter = useCallback( () => { | ||
setIsHovered( true ); | ||
toggleBlockHighlight( clientId, true ); | ||
|
@@ -250,17 +226,13 @@ function ListViewBlock( { | |
data-block={ clientId } | ||
data-expanded={ canExpand ? isExpanded : undefined } | ||
isExpanded={ canExpand ? isExpanded : undefined } | ||
aria-selected={ !! isSelected || forceSelectionContentLock } | ||
andrewserong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ref={ rowRef } | ||
> | ||
<TreeGridCell | ||
className="block-editor-list-view-block__contents-cell" | ||
colSpan={ colSpan } | ||
ref={ cellRef } | ||
aria-label={ blockAriaLabel } | ||
aria-selected={ !! isSelected || forceSelectionContentLock } | ||
aria-expanded={ canExpand ? isExpanded : undefined } | ||
aria-describedby={ descriptionId } | ||
andrewserong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
{ ( { ref, tabIndex, onFocus } ) => ( | ||
<div className="block-editor-list-view-block__contents-container"> | ||
|
@@ -277,9 +249,10 @@ function ListViewBlock( { | |
currentlyEditingBlockInCanvas ? 0 : tabIndex | ||
} | ||
onFocus={ onFocus } | ||
isExpanded={ isExpanded } | ||
isExpanded={ canExpand ? isExpanded : undefined } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to match the others. |
||
selectedClientIds={ selectedClientIds } | ||
preventAnnouncement={ preventAnnouncement } | ||
ariaLabel={ blockAriaLabel } | ||
ariaDescribedBy={ descriptionId } | ||
/> | ||
<div | ||
className="block-editor-list-view-block-select-button__description" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ const ListViewLeaf = forwardRef( | |
level={ level } | ||
positionInSet={ position } | ||
setSize={ rowCount } | ||
disableAriaExpanded={ true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes the clickable expander to no longer render, which removes the ability to expand / collapse container blocks via the mouse. |
||
{ ...props } | ||
> | ||
{ children } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,7 @@ export default function useBlockSelection() { | |
} | ||
|
||
if ( label ) { | ||
speak( label ); | ||
speak( label, 'assertive' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but this required a fix. |
||
} | ||
}, | ||
[ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,8 @@ function UnforwardedTreeGrid( | |
const canExpandCollapse = 0 === currentColumnIndex; | ||
const cannotFocusNextColumn = | ||
canExpandCollapse && | ||
activeRow.getAttribute( 'aria-expanded' ) === 'false' && | ||
( activeRow.getAttribute( 'data-expanded' ) === 'false' || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to add this attribute check here or else we'll never know if it is okay to expand or collapse with the keyboard. Should probably document an example in README. Likely need to update unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @alexstine , would you be able to work on a follow-up where you add info to the README, or (even better) add a Storybook example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ciampo Storybook is tricky for me to use so doubt I would be much help making an example that might not be testable by me. I only use Storybook when stuff is not testable any other way because accessibility is not great and components used in-practice are much easier to test. For the README example, let me open a follow-up. That should be easy enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable, thank you! I'll see if I can help and add the Storybook example myself |
||
activeRow.getAttribute( 'aria-expanded' ) === 'false' ) && | ||
keyCode === RIGHT; | ||
|
||
if ( ( [ LEFT, RIGHT ] as number[] ).includes( keyCode ) ) { | ||
|
@@ -112,6 +113,8 @@ function UnforwardedTreeGrid( | |
// Left: | ||
// If a row is focused, and it is expanded, collapses the current row. | ||
if ( | ||
activeRow.getAttribute( 'data-expanded' ) === | ||
'true' || | ||
activeRow.getAttribute( 'aria-expanded' ) === 'true' | ||
) { | ||
onCollapseRow( activeRow ); | ||
|
@@ -151,8 +154,10 @@ function UnforwardedTreeGrid( | |
// Right: | ||
// If a row is focused, and it is collapsed, expands the current row. | ||
if ( | ||
activeRow.getAttribute( 'data-expanded' ) === | ||
'false' || | ||
activeRow.getAttribute( 'aria-expanded' ) === | ||
'false' | ||
'false' | ||
) { | ||
onExpandRow( activeRow ); | ||
event.preventDefault(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ function UnforwardedTreeGridRow( | |
positionInSet, | ||
setSize, | ||
isExpanded, | ||
disableAriaExpanded, | ||
...props | ||
}: WordPressComponentProps< TreeGridRowProps, 'tr', false >, | ||
ref: React.ForwardedRef< HTMLTableRowElement > | ||
|
@@ -28,7 +29,7 @@ function UnforwardedTreeGridRow( | |
aria-level={ level } | ||
aria-posinset={ positionInSet } | ||
aria-setsize={ setSize } | ||
aria-expanded={ isExpanded } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the best area to explain this. The reason why this needs to exist is as follows.
One of these attributes is required for the keyboard functionality. Not pretty, but it works. |
||
aria-expanded={ disableAriaExpanded ? undefined : isExpanded } | ||
> | ||
{ children } | ||
</tr> | ||
|
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.
Not sure why this component was no longer receiving this prop.