Skip to content

Commit 33ee2ec

Browse files
committed
Fix the '+(xx) others' link losing focus after activation
Reported as an issue in JAWS, and also further observed as problematic in other screen-readers, this issue was actually a problem for all users as it did not focus a relevant element after activation. I've now changed the behaviour: * Anchor element is replaced with a button for improved accessibility * Button inherits parent styles to appear like a link * After activation, focus the first link in the now-visible links panel
1 parent a996c31 commit 33ee2ec

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/assets/javascripts/modules/hide-other-links.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
99
this.hiddenElementContainer = this.createHiddenElementContainer()
1010
this.shownElements = []
1111
this.hiddenElements = []
12-
this.showLink = document.createElement('a')
12+
this.showLink = document.createElement('button')
1313
}
1414

1515
HideOtherLinks.prototype.init = function () {
@@ -51,7 +51,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
5151

5252
this.showLink.classList.add('show-other-content', 'govuk-link')
5353
this.showLink.innerHTML = linkText
54-
this.showLink.href = '#'
54+
this.showLink.setAttribute('aria-expanded', 'false')
55+
this.showLink.setAttribute('aria-controls', 'other-content')
5556

5657
this.showLink.addEventListener('click', this.showHiddenLinks.bind(this))
5758

@@ -71,6 +72,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
7172
HideOtherLinks.prototype.createHiddenElementContainer = function () {
7273
var showHide = document.createElement('span')
7374
showHide.classList.add('other-content')
75+
showHide.id = 'other-content'
7476

7577
return showHide
7678
}
@@ -79,8 +81,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
7981
event.preventDefault()
8082

8183
this.hiddenElementContainer.style.display = ''
84+
this.hiddenElementContainer.querySelectorAll('a')[0].focus()
8285
this.showLink.remove()
83-
this.hiddenElementContainer.focus()
8486
}
8587

8688
Modules.HideOtherLinks = HideOtherLinks

app/assets/stylesheets/views/_worldwide-organisation.scss

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
.js-enabled {
77
.worldwide-organisation-header {
88
.show-other-content {
9-
@include govuk-font(14);
9+
all: inherit;
10+
display: inline;
1011
margin-left: .3em;
1112
white-space: nowrap;
13+
color: $govuk-link-colour;
14+
cursor: pointer;
15+
@include govuk-link-common;
16+
@include govuk-font(16);
1217
}
1318
}
1419
}

0 commit comments

Comments
 (0)