-
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
Table of contents block accessibility improvements #54322
Changes from 1 commit
a791c30
5698a02
7d35d5d
c3dc6e3
0960e26
a78bfe0
923e4f2
6ba365f
c50ec95
b58c158
e732665
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 |
---|---|---|
|
@@ -45,7 +45,8 @@ | |
"__experimentalDefaultControls": { | ||
"fontSize": true | ||
} | ||
} | ||
}, | ||
"ariaLabel": true | ||
}, | ||
"example": {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,11 @@ export default function TableOfContentsEdit( { | |
return ( | ||
<> | ||
<nav { ...blockProps }> | ||
<ol inert="true"> | ||
<TableOfContentsList nestedHeadingList={ headingTree } /> | ||
<ol> | ||
<TableOfContentsList | ||
nestedHeadingList={ headingTree } | ||
disableLinkActivation={ 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. Passing this prop to disable link activation for the editor side. |
||
/> | ||
</ol> | ||
</nav> | ||
{ toolbarControls } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,32 @@ const ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry'; | |
|
||
export default function TableOfContentsList( { | ||
nestedHeadingList, | ||
disableLinkActivation, | ||
}: { | ||
nestedHeadingList: NestedHeadingData[]; | ||
disableLinkActivation?: boolean; | ||
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. Is there a better way to type this? |
||
} ): WPElement { | ||
return ( | ||
<> | ||
{ nestedHeadingList.map( ( node, index ) => { | ||
const { content, link } = node.heading; | ||
|
||
const entry = link ? ( | ||
<a className={ ENTRY_CLASS_NAME } href={ link }> | ||
<a | ||
className={ ENTRY_CLASS_NAME } | ||
href={ link } | ||
aria-disabled={ disableLinkActivation || 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. This communicates disabled state to screen readers. |
||
onClick={ | ||
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 prevents click. |
||
disableLinkActivation | ||
? ( event ) => event?.preventDefault() | ||
: undefined | ||
} | ||
onContextMenu={ | ||
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 prevents context menu open in new tab/window. |
||
disableLinkActivation | ||
? ( event ) => event?.preventDefault() | ||
: undefined | ||
} | ||
> | ||
{ content } | ||
</a> | ||
) : ( | ||
|
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'm not sure why no one caught this regression. This makes the content completely inaccessible to keyboard users. Please don't do this unless you have a really good reason to.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert
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.
inert
was added in several places in d50e613; we maybe should take a look at each usage.