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

Fix aria-checked attribute not set for plugin settings buttons in Options dropdown #65667

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle all the possible roles for checked state
  • Loading branch information
manzoorwanijk committed Sep 26, 2024
commit de3992ce230fb881b7c4f042f55ac801eedb8974
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 {HTMLElement['role']} 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 Down Expand Up @@ -37,10 +56,7 @@ function ComplementaryAreaToggle( {
aria-controls={ identifier.replace( '/', ':' ) }
// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked
aria-checked={
props.role === 'menuitemcheckbox' ||
props.role === 'menuitemradio'
? isSelected
: undefined
roleSupportsCheckedState( props.role ) ? isSelected : undefined
}
onClick={ () => {
if ( isSelected ) {
Expand Down
Loading