WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Regression: fix the usage of aria-pressed vs. aria-expanded / aria-haspopup #21716

Open afercia opened 4 years ago

afercia commented 4 years ago

Describe the bug https://github.com/WordPress/gutenberg/pull/17748 and https://github.com/WordPress/gutenberg/pull/20951 introduced many changes to to various buttons in the UI, including the main inserter button. In some cases, these buttons now use the aria-pressed attribute inappropriately and miss important ARIA attributes that were previously used. In other cases, aria-pressed is used in combination with aria-expanded, which is inappropriate as well.

To reproduce Steps to reproduce the behavior:

  1. activate latest Gutenberg plugin (I tested with 7.9.1) 2.see the main "Add block" button at the top left corner of the editor
  2. see the button now uses these attributes: aria-pressed="false" aria-label="Add block"
  3. deactivate the plugin, see the button on WP 5.4 uses these attributes: aria-haspopup="true" aria-expanded="false" aria-label="Add block"
  4. This button was previously rendered by the <Inserter> component, which used the appropriate aria-* attributes
  5. It now uses a <Button> component with an isPressed prop. It's also inconsistent with other "inserter" buttons in the UI, which still use the correct attributes.

Also:

  1. See the Settings button at the top right
  2. See it uses these attributes: aria-pressed="false" aria-expanded="false" (or true depending on the Settings sidebar state)
  3. Note this is already released in WP 5.2 so there's no need to activate the plugin.

Notes:

Expected behavior

TL:DR The aria-pressed attribute identifies the button as a toggle button. A toggle buttons is a special semantic-type of button, with its expected interaction. It's a two-state button and its state persists together with the result of the associated action until users toggle the button again.

Thus, aria-pressed must not be used to indicate a "selected" or "active" state. It must be exclusively used to identify the button as a "toggle" button.

References: https://www.w3.org/TR/wai-aria-1.1/#aria-pressed

Indicates the current "pressed" state of toggle buttons. See related aria-checked and aria-selected. Toggle buttons require a full press-and-release cycle to change their value.

https://www.w3.org/TR/wai-aria-1.1/#button

An input that allows for user-triggered actions when clicked or pressed. See related link. Buttons support the optional attribute aria-pressed. Buttons with a non-empty aria-pressed attribute are toggle buttons. When aria-pressed is true the button is in a "pressed" state, when aria-pressed is false it is not pressed. If the attribute is not present, the button is a simple command button.

https://www.w3.org/TR/wai-aria-practices-1.1/#button

Toggle button: A two-state button that can be either off (not pressed) or on (pressed). ...

See the "Mute audio" example: https://www.w3.org/TR/wai-aria-practices/examples/button/button.html

aria-pressed identifies the button as a toggle button.

Screenshots Examples of good toggle buttons in the Gutenberg UI:

The heading level state persists: this is a correct usage.

Screenshot 2020-04-19 at 14 01 11

The selected color persist: correct usage.

Screenshot 2020-04-19 at 14 05 02

The HTML block view mode persists: correct usage.

Screenshot 2020-04-19 at 14 01 02

Instead, buttons that open sidebars, menus, and the like need to indicate:

afercia commented 4 years ago

Practical impact of using aria-pressed together with aria-expanded (incorrect usage). tested with Firefox and NVDA on Windows:

Screenshot (94)

To reproduce: