Skip to content

Commit

Permalink
Components: Fix inaccessible disabled Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Jun 4, 2024
1 parent 5e25386 commit cb8e110
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ module.exports = {
'no-restricted-syntax': [
'error',
...restrictedSyntax,
...restrictedSyntaxComponents,
{
selector:
':matches(Literal[value=/--wp-admin-theme-/],TemplateElement[value.cooked=/--wp-admin-theme-/])',
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/autocomplete/autocompleter-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function ListBox( {
id={ `components-autocomplete-item-${ instanceId }-${ option.key }` }
role="option"
aria-selected={ index === selectedIndex }
__experimentalIsFocusable
disabled={ option.isDisabled }
className={ clsx(
'components-autocomplete__result',
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/button/stories/e2e/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const VariantStates: StoryFn< typeof Button > = (
key={ variant ?? 'undefined' }
>
<Button { ...props } variant={ variant } />
{ /* eslint-disable-next-line no-restricted-syntax */ }
<Button { ...props } variant={ variant } disabled />
<Button
{ ...props }
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/button/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ describe( 'Button', () => {
} );

it( 'should add a disabled prop to the button', () => {
// eslint-disable-next-line no-restricted-syntax
render( <Button disabled /> );

expect( screen.getByRole( 'button' ) ).toBeDisabled();
Expand Down Expand Up @@ -536,6 +537,7 @@ describe( 'Button', () => {

it( 'should become a button again when disabled is supplied', () => {
// @ts-expect-error - a button should not have `href`
// eslint-disable-next-line no-restricted-syntax
render( <Button href="https://wordpress.org/" disabled /> );

expect( screen.getByRole( 'button' ) ).toBeVisible();
Expand Down Expand Up @@ -624,8 +626,12 @@ describe( 'Button', () => {
<Button href="foo" />
{ /* @ts-expect-error - `target` requires `href` */ }
<Button target="foo" />

{ /* eslint-disable no-restricted-syntax */ }
{ /* @ts-expect-error - `disabled` is only for buttons */ }
<Button href="foo" disabled />
{ /* eslint-enable no-restricted-syntax */ }

<Button href="foo" type="image/png" />
{ /* @ts-expect-error - if button, type must be submit/reset/button */ }
<Button type="image/png" />
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/combobox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ function ComboboxControl( props: ComboboxControlProps ) {
<Button
className="components-combobox-control__reset"
icon={ closeSmall }
// Disable reason: Focus returns to input field when reset is clicked.
// eslint-disable-next-line no-restricted-syntax
disabled={ ! value }
onClick={ handleOnReset }
label={ __( 'Reset' ) }
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {
? control.role
: 'menuitem'
}
__experimentalIsFocusable
disabled={ control.isDisabled }
>
{ control.title }
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/form-token-field/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export default function Token( {
className="components-form-token-field__remove-token"
icon={ closeSmall }
onClick={ ! disabled ? onClick : undefined }
// Disable reason: Even when FormTokenField itself is accessibly disabled, token reset buttons shouldn't be in the tab sequence.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled }
label={ messages.remove }
aria-describedby={ `components-form-token-field__token-text-${ instanceId }` }
Expand Down

0 comments on commit cb8e110

Please sign in to comment.