Skip to content

Commit d36908a

Browse files
committed
Change method to match production behaviour
1 parent c660b44 commit d36908a

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

media/js/cms/flare-navigation.es6.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,22 @@ import Headroom from 'headroom.js';
7878
});
7979

8080
const menuTitles = document.querySelectorAll('.fl-menu-title');
81+
let focusedMenu = null;
8182

8283
// keyboard is being used
8384
menuTitles.forEach(function (title) {
8485
const menuLinks = title
8586
.closest('.fl-menu-category')
8687
.querySelectorAll('a');
8788

88-
// focus events are no good here as we mix in a click handler below
89-
// which is also triggered after our focus would run
89+
title.addEventListener('focus', function () {
90+
menuCategories.forEach(function (category) {
91+
if (category.classList.contains('is-active')) {
92+
focusedMenu = category;
93+
}
94+
category.classList.remove('is-active');
95+
});
96+
});
9097

9198
// when leaving the last link of a menu, close all menus
9299
menuLinks[menuLinks.length - 1].addEventListener(
@@ -100,21 +107,19 @@ import Headroom from 'headroom.js';
100107
}
101108
);
102109

103-
// when leaving the first link of a menu, close all menus
104-
menuLinks[0].addEventListener('keydown', function (event) {
105-
if (event.key === 'Tab' && event.shiftKey) {
106-
menuCategories.forEach(function (category) {
107-
category.classList.remove('is-active');
108-
});
109-
}
110-
});
111-
112110
// when clicking or pressing enter, toggle the menu
113111
title.addEventListener('click', function (event) {
114112
event.preventDefault();
115113

116114
const menuPanel = event.target.closest('.fl-menu-category');
117115

116+
// focus runs first then click. if we click a menu that was closed
117+
// by focus don't open it again immediately
118+
if (focusedMenu === menuPanel) {
119+
focusedMenu = null;
120+
return;
121+
}
122+
118123
if (menuPanel.classList.contains('is-active')) {
119124
menuPanel.classList.remove('is-active');
120125
} else {

0 commit comments

Comments
 (0)