File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed
Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,11 @@ const toggleNav = (active) => {
106106 closeButton . focus ( ) ;
107107 } else if (
108108 ! safeActive &&
109- document . activeElement === closeButton &&
110- menuButton
109+ menuButton &&
110+ getComputedStyle ( menuButton ) . display !== 'none'
111+
111112 ) {
112- // The mobile nav was just deactivated, and focus was on the close
113- // button, which is no longer visible. We don't want the focus to
113+ // The mobile nav was just deactivated. We don't want the focus to
114114 // disappear into the void, so focus on the menu button if it's
115115 // visible (this may have been what the user was just focused on,
116116 // if they triggered the mobile nav by mistake).
@@ -147,7 +147,10 @@ const focusNavButton = (event) => {
147147
148148 // Only shift focus if within dropdown
149149 if ( ! event . target . matches ( NAV_CONTROL ) ) {
150- parentNavItem . querySelector ( NAV_CONTROL ) . focus ( ) ;
150+ const navControl = parentNavItem . querySelector ( NAV_CONTROL )
151+ if ( navControl ) {
152+ navControl . focus ( )
153+ }
151154 }
152155} ;
153156
Original file line number Diff line number Diff line change 66<div class =" display-flex flex-wrap margin-top-5" >
77{% for item in icons .items %}
88 <div role =" region" aria-atomic =" true" class =" font-sans-xl position-relative icon-example border-1px border-base-lighter hover:text-white hover:bg-primary-vivid hover:border-primary-darker " data-meta =" {{ item .name }} {{ item .meta }}" aria-label =" {{ item .name }} icon." >
9- <button type =" button" onclick =" copyHTML(this)" class =" bg-transparent cursor-pointer text-no-underline text-black display-flex width-card height-card flex-align-center flex-align-center border-0 flex-column flex-justify-center padding-2 hover:text-white" aria-label =" Copy to clipboard" style =" -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;" >
9+ <button type =" button" onclick =" copyHTML(this)" class =" bg-transparent cursor-pointer text-no-underline text-black display-flex width-card height-card flex-align-center flex-align-center border-0 flex-column flex-justify-center padding-2 hover:text-white" aria-label =" Copy icon to clipboard" style =" -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;" >
1010 <svg class =" usa-icon" aria-hidden =" true" focusable =" false" role =" img" >
1111 <use xlink:href =" {{ icons .img_path }}/sprite.svg#{{ item .name }}" ></use >
1212 </svg >
1313 <span class =" font-sans-3xs margin-top-2 display-block" aria-hidden =" true" >{{ item .name }}</span >
1414 </button >
15- <span aria-live =" assertive" style =" pointer-events:none" class =" message-holder bottom-1 position-absolute font-sans-3xs text-bold display-block text-center left-0 width-full" aria-label = " {{ item . name }} " ></span >
15+ <span aria-live =" assertive" style =" pointer-events:none" class =" message-holder bottom-1 position-absolute font-sans-3xs text-bold display-block text-center left-0 width-full" ></span >
1616 </div >
1717{% endfor %}
1818</div >
@@ -42,7 +42,6 @@ function copyHTML(el){
4242
4343 message = document .createElement (" span" );
4444 message .setAttribute (" id" , " icon-copy-notice" );
45- message .setAttribute (" aria-live" , " assertive" );
4645 message .innerHTML = " Copied to clipboard!" ;
4746
4847 /* Copy the text inside the text field */
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ describe("navigation toggle", () => {
3232 let sandbox ;
3333 let header ;
3434 let nav ;
35+ let navPrimary ;
3536 let navControl ;
3637 let overlay ;
3738 let closeButton ;
@@ -47,6 +48,7 @@ describe("navigation toggle", () => {
4748 navigation . on ( ) ;
4849 header = body . querySelector ( ".usa-header" ) ;
4950 nav = body . querySelector ( ".usa-nav" ) ;
51+ navPrimary = body . querySelector ( ".usa-nav__primary" ) ;
5052 navControl = body . querySelector ( ".usa-nav__link" ) ;
5153 overlay = body . querySelector ( ".usa-overlay" ) ;
5254 closeButton = body . querySelector ( ".usa-nav__close" ) ;
@@ -150,6 +152,15 @@ describe("navigation toggle", () => {
150152 assert . strictEqual ( accordionButton . getAttribute ( "aria-expanded" ) , "false" ) ;
151153 } ) ;
152154
155+ it ( "hides the nav when the Escape key is hit" , ( ) => {
156+ menuButton . click ( ) ;
157+ navControl . focus ( ) ;
158+ EVENTS . escape ( navPrimary )
159+ assert . strictEqual ( isVisible ( nav ) , false ) ;
160+ assert . strictEqual ( isVisible ( overlay ) , false ) ;
161+ assert . strictEqual ( document . activeElement , menuButton )
162+ } ) ;
163+
153164 it ( "collapses dropdowns when focus leaves nav" , ( ) => {
154165 menuButton . click ( ) ;
155166 navLink . click ( ) ;
You can’t perform that action at this time.
0 commit comments