@@ -81,18 +81,14 @@ import Headroom from 'headroom.js';
8181
8282 // keyboard is being used
8383 menuTitles . forEach ( function ( title ) {
84- // when focusing a menu title, close all menus
85- title . addEventListener ( 'focus' , function ( ) {
86- menuCategories . forEach ( function ( category ) {
87- category . classList . remove ( 'is-active' ) ;
88- } ) ;
89- } ) ;
90-
91- // when leaving the last link of a menu, close all menus
9284 const menuLinks = title
9385 . closest ( '.fl-menu-category' )
9486 . querySelectorAll ( 'a' ) ;
9587
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
90+
91+ // when leaving the last link of a menu, close all menus
9692 menuLinks [ menuLinks . length - 1 ] . addEventListener (
9793 'keydown' ,
9894 function ( event ) {
@@ -104,6 +100,15 @@ import Headroom from 'headroom.js';
104100 }
105101 ) ;
106102
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+
107112 // when clicking or pressing enter, toggle the menu
108113 title . addEventListener ( 'click' , function ( event ) {
109114 event . preventDefault ( ) ;
0 commit comments