material-web/migrations/v2
Elizabeth Mitchell 5df9410e60 fix!: aria-labels announcing twice with "group" on components
BREAKING CHANGE: `querySelector` for `[role]` and `[aria-*]` attributes may no longer work. See `@material/web/migrations/v2/README.md` and `@material/web/migrations/v2/query-selector-aria.ts`.

Browser/SR test results (go/mwc-double-aria-test-results)
  -  VoiceOver on Chrome
  -  VoiceOver on iOS Safari
  -  TalkBack on Chrome
  -  ChromeVox on Chrome
  -  NVDA on Chrome
  -  NVDA on Firefox
  -  JAWS on Chrome
  -  JAWS on Firefox
  (Optional)
  -  VoiceOver on Safari
  -  VoiceOver on Firefox

PiperOrigin-RevId: 648859827
2024-07-02 15:22:12 -07:00
..
query-selector-aria_test.ts fix!: aria-labels announcing twice with "group" on components 2024-07-02 15:22:12 -07:00
query-selector-aria.ts fix!: aria-labels announcing twice with "group" on components 2024-07-02 15:22:12 -07:00
README.md fix!: aria-labels announcing twice with "group" on components 2024-07-02 15:22:12 -07:00

Breaking changes from v1 to v2

ARIA attribute querySelector

What changed?

role and aria-* attributes now shift at runtime to data-role and data-aria-* attributes. This fixes a screen reader bug around labels announcing more than once.

What broke?

Using querySelector or querySelectorAll with [role] or [aria-*] attribute selectors.

<md-checkbox aria-label="Agree"></md-checkbox>
<script>
  const agreeCheckbox = document.querySelector(
    'md-checkbox[aria-label="Agree"]'
  );
  // `agreeCheckbox` is null!
</script>

How to fix?

Provide selector strings to ariaSelector() before querying.

import {ariaSelector} from '@material/web/migrations/v2/query-selector-aria';

const agreeCheckbox = document.querySelector(
  ariaSelector('md-checkbox[aria-label="Agree"]')
);

Note: Element APIs, such as element.getAttribute('role') and element.ariaLabel will continue to work as expected.