Skip to content

Commit

Permalink
Set aria-checked
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Mar 17, 2022
1 parent f4d0f3b commit dec8b06
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/components/src/checkbox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function CheckboxControl( {
return;
}

// It cannot be set using an HTML attribute.
node.indeterminate = !! indeterminate;

setShowCheckedIcon( node.matches( ':checked' ) );
Expand All @@ -57,6 +58,15 @@ export default function CheckboxControl( {
const id = `inspector-checkbox-control-${ instanceId }`;
const onChangeValue = ( event ) => onChange( event.target.checked );

let ariaChecked;
if ( showCheckedIcon ) {
ariaChecked = 'true';
} else if ( showIndeterminateIcon ) {
ariaChecked = 'mixed';
} else {
ariaChecked = 'false';
}

return (
<BaseControl
label={ heading }
Expand All @@ -74,6 +84,7 @@ export default function CheckboxControl( {
onChange={ onChangeValue }
checked={ checked }
aria-describedby={ !! help ? id + '__help' : undefined }
aria-checked={ ariaChecked }
{ ...props }
/>
{ showIndeterminateIcon ? (
Expand Down

0 comments on commit dec8b06

Please sign in to comment.