Skip to content

Commit

Permalink
Fix aria-checked attribute not set for plugin settings buttons in Opt…
Browse files Browse the repository at this point in the history
…ions dropdown (#65667)


Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
  • Loading branch information
4 people authored Sep 26, 2024
1 parent 69efbca commit 427a8d0
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { store as interfaceStore } from '../../store';
import complementaryAreaContext from '../complementary-area-context';

/**
* Whether the role supports checked state.
*
* @param {import('react').AriaRole} role Role.
* @return {boolean} Whether the role supports checked state.
* @see https://www.w3.org/TR/wai-aria-1.1/#aria-checked
*/
function roleSupportsCheckedState( role ) {
return [
'checkbox',
'option',
'radio',
'switch',
'menuitemcheckbox',
'menuitemradio',
'treeitem',
].includes( role );
}

function ComplementaryAreaToggle( {
as = Button,
scope,
Expand All @@ -35,6 +54,10 @@ function ComplementaryAreaToggle( {
<ComponentToUse
icon={ selectedIcon && isSelected ? selectedIcon : icon }
aria-controls={ identifier.replace( '/', ':' ) }
// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked
aria-checked={
roleSupportsCheckedState( props.role ) ? isSelected : undefined
}
onClick={ () => {
if ( isSelected ) {
disableComplementaryArea( scope );
Expand Down

1 comment on commit 427a8d0

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 427a8d0.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11048759476
📝 Reported issues:

Please sign in to comment.