From 29b0bb311f092963e35a23a11846398b979f9187 Mon Sep 17 00:00:00 2001 From: Ron Holt Date: Fri, 8 Nov 2019 00:14:40 -0800 Subject: [PATCH 1/2] Close small menu when user clicks outside #1375 --- js/navigation.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/navigation.js b/js/navigation.js index fa926517..2dc69932 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -42,6 +42,17 @@ } }; + // Close small menu when user clicks outside + document.addEventListener( 'click', function( event ) { + var isClickInside = container.contains( event.target ); + + if ( ! isClickInside ) { + container.className = container.className.replace( ' toggled', '' ); + button.setAttribute( 'aria-expanded', 'false' ); + menu.setAttribute( 'aria-expanded', 'false' ); + } + } ); + // Get all the link elements within the menu. links = menu.getElementsByTagName( 'a' ); From 9dee7649496047136bf082f6e896b5125aba5347 Mon Sep 17 00:00:00 2001 From: Ismail El Korchi Date: Fri, 10 Apr 2020 03:04:28 +0100 Subject: [PATCH 2/2] Fix a minor spacing issue --- js/navigation.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index 2dc69932..ee18d754 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -42,16 +42,16 @@ } }; - // Close small menu when user clicks outside - document.addEventListener( 'click', function( event ) { - var isClickInside = container.contains( event.target ); + // Close small menu when user clicks outside + document.addEventListener( 'click', function( event ) { + var isClickInside = container.contains( event.target ); - if ( ! isClickInside ) { - container.className = container.className.replace( ' toggled', '' ); - button.setAttribute( 'aria-expanded', 'false' ); - menu.setAttribute( 'aria-expanded', 'false' ); - } - } ); + if ( ! isClickInside ) { + container.className = container.className.replace( ' toggled', '' ); + button.setAttribute( 'aria-expanded', 'false' ); + menu.setAttribute( 'aria-expanded', 'false' ); + } + } ); // Get all the link elements within the menu. links = menu.getElementsByTagName( 'a' );