Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only toggle details aria attributes if already set
I believe this dates from when the polyfill for the `<details>` element used to be applied in all browsers, and added extra ARIA attributes which always needed to be kept in sync when this script toggled the open state. However, since GOV.UK Frontend v3.1.0 the polyfill now does nothing in browsers that natively support the <details> elements [1]. This means that once these attributes are set on page load, unless the polyfill is running there is nothing to keep them in sync if the user toggles the details element: - `aria-expanded` will always be `true`, potentially causing AT to announce the expanded state incorrectly - `aria-hidden` will always be `false` – although this is likely not an issue as aria-hidden can't make things hidden using display:none 're-appear' in the accessibility tree Instead, only toggle `aria-expanded` if it is already set on the element (which should only happen if the polyfill has run, in which case the browser does not natively support the `<details>` element). We also need to re-introduce the `aria-hidden` attribute removed in 8b53583 as when the polyfill runs it currently adds an `aria-hidden` attribute which means the content inside the `<details>` element will be inaccessible even when opened unless we remove it. Add a comment to try and explain why this code needs to exist. [1]: alphagov/govuk-frontend#1523
- Loading branch information