Regression: fix the usage of aria-pressed vs. aria-expanded / aria-haspopup #21716
Labels
[Focus] Accessibility (a11y)
Changes that impact accessibility and need corresponding review (e.g. markup changes).
[Type] Regression
Related to a regression in the latest release
Describe the bug
#17748 and #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 witharia-expanded
, which is inappropriate as well.To reproduce
Steps to reproduce the behavior:
2.see the main "Add block" button at the top left corner of the editor
aria-pressed="false" aria-label="Add block"
aria-haspopup="true" aria-expanded="false" aria-label="Add block"
<Inserter>
component, which used the appropriate aria-* attributes<Button>
component with anisPressed
prop. It's also inconsistent with other "inserter" buttons in the UI, which still use the correct attributes.Also:
aria-pressed="false" aria-expanded="false"
(ortrue
depending on the Settings sidebar state)Notes:
isPressed
prop is sometimes passed directly to the SVG icons. I guess this is used for the mobile app?Expected behavior
aria-expanded
attribute to indicate the controlled element expanded state. In this case, the usage ofaria-pressed
is wrong and also noisy for screen reader users.aria-haspopup
attribute.aria-pressed
attribute.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
https://www.w3.org/TR/wai-aria-1.1/#button
https://www.w3.org/TR/wai-aria-practices-1.1/#button
See the "Mute audio" example: https://www.w3.org/TR/wai-aria-practices/examples/button/button.html
Screenshots
Examples of good toggle buttons in the Gutenberg UI:
The heading level state persists: this is a correct usage.
The selected color persist: correct usage.
The HTML block view mode persists: correct usage.
Instead, buttons that open sidebars, menus, and the like need to indicate:
aria-haspopup
aria-expanded
The text was updated successfully, but these errors were encountered: