File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ const menu = html`<ul
4949> </ ul > `;
5050const closeButton = html `< button
5151 class ="close-button "
52+ aria-label ="Close "
5253 onclick =${ ( ) => ui . closeModal ( ) }
5354 title ="Close"
5455>
@@ -77,12 +78,13 @@ respecPill.addEventListener(
7778 e . stopPropagation ( ) ;
7879 respecPill . setAttribute ( "aria-expanded" , String ( menu . hidden ) ) ;
7980 toggleMenu ( ) ;
80- menu . querySelector ( "li:first-child button" ) . focus ( ) ;
81+ menu . querySelector ( "li:first-child button" ) ? .focus ( ) ;
8182 }
8283) ;
8384
8485document . documentElement . addEventListener ( "click" , ( ) => {
8586 if ( ! menu . hidden ) {
87+ respecPill . setAttribute ( "aria-expanded" , "false" ) ;
8688 toggleMenu ( ) ;
8789 }
8890} ) ;
@@ -95,6 +97,35 @@ menu.addEventListener(
9597 respecPill . setAttribute ( "aria-expanded" , String ( menu . hidden ) ) ;
9698 toggleMenu ( ) ;
9799 respecPill . focus ( ) ;
100+ return ;
101+ }
102+ const items = /** @type {HTMLElement[] } */ ( [
103+ ...menu . querySelectorAll ( "button:not([disabled])" ) ,
104+ ] ) ;
105+ const currentIndex = items . indexOf (
106+ /** @type {HTMLElement } */ ( document . activeElement )
107+ ) ;
108+ switch ( e . key ) {
109+ case "ArrowDown" : {
110+ e . preventDefault ( ) ;
111+ const next = items [ ( currentIndex + 1 ) % items . length ] ;
112+ next ?. focus ( ) ;
113+ break ;
114+ }
115+ case "ArrowUp" : {
116+ e . preventDefault ( ) ;
117+ const prev = items [ ( currentIndex - 1 + items . length ) % items . length ] ;
118+ prev ?. focus ( ) ;
119+ break ;
120+ }
121+ case "Home" :
122+ e . preventDefault ( ) ;
123+ items [ 0 ] ?. focus ( ) ;
124+ break ;
125+ case "End" :
126+ e . preventDefault ( ) ;
127+ items [ items . length - 1 ] ?. focus ( ) ;
128+ break ;
98129 }
99130 }
100131) ;
You can’t perform that action at this time.
0 commit comments