Skip to content

Commit 542f6a7

Browse files
committed
a11y: #4225 olh nav suport aria-expanded
1 parent 3d20430 commit 542f6a7

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/themes/OLH/assets/js/app.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ $(document).on('click', '[data-toggle]', function() {
2323
$button.attr('aria-expanded', !currentExpanded);
2424
});
2525

26+
// Accessibility: Handle Nav aria-expanded on keyboard navigation
27+
$(document).on('click', '[aria-expanded]', function() {
28+
var $button = $(this);
29+
var currentExpanded = $button.attr('aria-expanded') === 'true';
30+
$button.attr('aria-expanded', !currentExpanded);
31+
});
32+
33+
function toggleAriaExpanded(submenu, expanded) {
34+
var $parent = submenu.parent('li.is-dropdown-submenu-parent');
35+
var $button = $parent.find('a[aria-expanded]');
36+
$button.attr('aria-expanded', expanded);
37+
}
38+
39+
// Accessibility: Listen for Foundation menu events to update aria-expanded
40+
$(document).ready(function() {
41+
// dropdown menu (wide screen)
42+
$(document).on('show.zf.dropdownmenu', function(event, $sub) {
43+
toggleAriaExpanded($sub, true);
44+
});
45+
46+
$(document).on('hide.zf.dropdownmenu', function(event, $sub) {
47+
$('a[aria-expanded="true"]').attr('aria-expanded', 'false');
48+
});
49+
50+
// drilldown menu (narrow screen)
51+
$(document).on('open.zf.drilldown', function(event, $elem) {
52+
toggleAriaExpanded($elem, true);
53+
});
54+
55+
$(document).on('hide.zf.drilldown', function(event, $elem) {
56+
$('a[aria-expanded="true"]').attr('aria-expanded', 'false');
57+
});
58+
});
59+
2660
$(".search-toggle").click(function() {
2761
var $searchMenu = $("#search-menu");
2862
if ($searchMenu.is(':visible')) {

src/themes/OLH/templates/core/nav.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li class="is-dropdown-submenu-parent">
2424
<a href="#" data-options="is_hover:true; hover_timeout:5000"
2525
role="button"
26-
aria-expanded="true"
26+
aria-expanded="false"
2727
aria-controls="menu-nav-item-{{ item.counter }}"
2828
>
2929
{{ item.link_name }}
@@ -65,7 +65,7 @@
6565
<li class="is-dropdown-submenu-parent">
6666
<a href="#" data-options="is_hover:true; hover_timeout:5000"
6767
role="button"
68-
aria-expanded="true"
68+
aria-expanded="false"
6969
aria-controls="menu-nav-journal"
7070
>
7171
{{ journal_settings.styling.editorial_group_page_name }}
@@ -119,7 +119,7 @@
119119
<li class="is-dropdown-submenu-parent show-for-small-only">
120120
<a href="#" data-options="is_hover:true; hover_timeout:5000"
121121
role="button"
122-
aria-expanded="true"
122+
aria-expanded="false"
123123
aria-controls="menu-nav-account"
124124
>
125125
{% trans 'Account' %}

0 commit comments

Comments
 (0)