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

Don't use disabled on focusable UI controls e.g. "Reset" buttons #15524

Open
afercia opened this issue May 9, 2019 · 6 comments
Open

Don't use disabled on focusable UI controls e.g. "Reset" buttons #15524

afercia opened this issue May 9, 2019 · 6 comments
Labels
[Feature] UI Components Impacts or related to the UI component system [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented May 9, 2019

Noticed while reviewing #14919 for the Range Control, see #14919 (comment), and applies to other buttons as well, for example the Font Size picker "Reset" button.

The Reset button in the font size picker:

Screenshot 2019-05-09 at 09 24 31

When using the keyboard and pressing the Reset button, the button gets a disabled HTML attribute. Thus, it's not focusable any longer and a focus loss occurs.

Worth noting modern browsers try to implement a smart behavior by the means of a so called sequential focus navigation starting point. Among other things, this feature is meant to help in this kind of situations: pressing Tab again should make the tab order start (more or less) from the place where focus was.

However, this is not guaranteed to work with assistive technologies. Not to mention some browsers don't have this feature (typically IE 11).

To avoid this kind of focus loss, Gutenberg uses a different pattern in a few places. Instead of using the HTML attribute disabled:

  • noop the button
  • use aria-disabled to communicate the button inert state
  • style the button as it was disabled

This pattern should be extended to all the cases where a UI control that currently has focus gets disabled. Starting from these "Reset" buttons, I'd like to propose to review all the cases where disabled is used across the codebase.

@afercia afercia added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [a11y] Keyboard & Focus labels May 9, 2019
@gziolo gziolo added [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components labels Oct 31, 2019
@draganescu
Copy link
Contributor

Hi @afercia, I re-tested this and I noticed that while the button still gets a disabled attribute, the tabbing order is respected, as in pressing tab moves the focus to line height, just as when the reset button is not disabled.

@afercia
Copy link
Contributor Author

afercia commented Apr 22, 2020

Hi @draganescu. I think you're confusing the so called sequential focus navigation starting point implemented in modern browsers with the native tab order. As mentioned above, those are two different things. The sequential focus navigation starting point isn't implemented in all browsers and there's no guarantee it works as expected when assistive technologies are in use. To get an idea, you should test with IE 11.

@youknowriad
Copy link
Contributor

I don't see any "reset" button on the font size control anymore. So I'm guessing this issue doesn't apply anymore.

@afercia
Copy link
Contributor Author

afercia commented Jun 19, 2023

The font size picker mentioned on this issue is just an example of the pattern that needs to be fixed. More controls do have a 'Reset' button or other buttons that get a disabled attribute while they're focused. Using the disabled attribute is the pattern that should be checked everywhere.

Specifically, the font size picker now has a withReset property set to false so that it doesn't show the Reset button. However, the component still uses the disabled attribute, thus potentially triggering a focus loss.

Other examples after a quick search in the codebase:

Combobox control:

<Button
className="components-combobox-control__reset"
icon={ closeSmall }
disabled={ ! value }
onClick={ handleOnReset }
label={ __( 'Reset' ) }
/>

Range control:

<Button
className="components-range-control__reset"
disabled={ disabled || value === undefined }
variant="secondary"
isSmall
onClick={ handleOnReset }
>
{ __( 'Reset' ) }
</Button>

Box control:

<Button
className="component-box-control__reset-button"
variant="secondary"
isSmall
onClick={ handleOnReset }
disabled={ ! isDirty }
>
{ __( 'Reset' ) }
</Button>

As said earlier, this issue isn't just about the 'Reset' buttons. it is about any control that dynamically gets a disabled attribute while it is focused.

@afercia afercia reopened this Jun 19, 2023
@afercia
Copy link
Contributor Author

afercia commented Jun 19, 2023

Specifically to the Font size picker, there's at least one occurrence where it still shows the Reset button:

  • Go to the Site Editor
  • Select a Group block
  • In the Settings sidebar, go to the Styles tab
  • Observe the Typography panel shows the preset sizes
  • Click 'Set custom size'
  • The Typography panel switches to the UI to set a custom size
  • Observe there is a 'Reset' button after the Size slider
Screenshot 2023-06-19 at 11 16 06

@youknowriad
Copy link
Contributor

Good catch, I think adding the __experimentalIsFocusable to these Button components should probably solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants