Skip to content

Commit d8088e5

Browse files
committed
Only set aria-controls when Service Navivation menu is visible
Works around an [issue with Voice Over where the button would still show in the rotor on Mac](https://bugs.webkit.org/show_bug.cgi?id=300899) by only setting the `aria-controls` attribute when the button is not `hidden`.
1 parent 7a919b3 commit d8088e5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/govuk-frontend/src/govuk/components/service-navigation/service-navigation.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ export class ServiceNavigation extends Component {
4949
return this
5050
}
5151

52-
const menuId = $menuButton.getAttribute('aria-controls')
52+
const menuId = $menuButton.getAttribute('data-aria-controls')
53+
5354
if (!menuId) {
5455
throw new ElementError({
5556
component: ServiceNavigation,
5657
identifier:
57-
'Navigation button (`<button class="govuk-js-service-navigation-toggle">`) attribute (`aria-controls`)'
58+
'Navigation button (`<button class="govuk-js-service-navigation-toggle">`) attribute (`data-aria-controls`)'
5859
})
5960
}
6061

@@ -126,9 +127,15 @@ export class ServiceNavigation extends Component {
126127
if (this.mql.matches) {
127128
this.$menu.removeAttribute('hidden')
128129
this.$menuButton.setAttribute('hidden', '')
130+
// Voice Over keeps the button listed in its Form Controls rotor
131+
// https://bugs.webkit.org/show_bug.cgi?id=300899
132+
this.$menuButton.removeAttribute('aria-controls')
129133
} else {
130134
this.$menuButton.removeAttribute('hidden')
131135
this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString())
136+
// Voice Over keeps the button listed in its Form Controls rotor
137+
// https://bugs.webkit.org/show_bug.cgi?id=300899
138+
this.$menuButton.setAttribute('aria-controls', this.$menu.id)
132139

133140
if (this.menuIsOpen) {
134141
this.$menu.removeAttribute('hidden')

packages/govuk-frontend/src/govuk/components/service-navigation/template.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data-module="govuk-service-navigation"
3737
{% if navigationItems | length or params.slots.navigationStart or params.slots.navigationEnd %}
3838
<nav aria-label="{{ params.navigationLabel | default(menuButtonText, true) }}" class="govuk-service-navigation__wrapper {%- if params.navigationClasses %} {{ params.navigationClasses }}{% endif %}">
3939
{% if collapseNavigationOnMobile %}
40-
<button type="button" class="govuk-service-navigation__toggle govuk-js-service-navigation-toggle" aria-controls="{{ navigationId }}" {%- if params.menuButtonLabel and params.menuButtonLabel != menuButtonText %} aria-label="{{ params.menuButtonLabel }}"{% endif %} hidden>
40+
<button type="button" class="govuk-service-navigation__toggle govuk-js-service-navigation-toggle" data-aria-controls="{{ navigationId }}" {%- if params.menuButtonLabel and params.menuButtonLabel != menuButtonText %} aria-label="{{ params.menuButtonLabel }}"{% endif %} hidden>
4141
{{ menuButtonText }}
4242
</button>
4343
{% endif %}

0 commit comments

Comments
 (0)