From d8d89bc6818849849f58da3ff890d45044735dc5 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Wed, 5 Nov 2014 17:37:48 -0800 Subject: [PATCH] _s: Improve menu toggle accessibility. Makes it a little easier to use the primary navigation with assistive devices. See #545. --- header.php | 2 +- js/navigation.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/header.php b/header.php index 5f0d5e5f..ee7a393a 100644 --- a/header.php +++ b/header.php @@ -29,7 +29,7 @@ diff --git a/js/navigation.js b/js/navigation.js index 706e4d85..13a4e448 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -7,12 +7,14 @@ var container, button, menu; container = document.getElementById( 'site-navigation' ); - if ( ! container ) + if ( ! container ) { return; + } button = container.getElementsByTagName( 'button' )[0]; - if ( 'undefined' === typeof button ) + if ( 'undefined' === typeof button ) { return; + } menu = container.getElementsByTagName( 'ul' )[0]; @@ -22,13 +24,21 @@ return; } - if ( -1 === menu.className.indexOf( 'nav-menu' ) ) + menu.setAttribute( 'aria-expanded', 'false' ); + + if ( -1 === menu.className.indexOf( 'nav-menu' ) ) { menu.className += ' nav-menu'; + } button.onclick = function() { - if ( -1 !== container.className.indexOf( 'toggled' ) ) + if ( -1 !== container.className.indexOf( 'toggled' ) ) { container.className = container.className.replace( ' toggled', '' ); - else + button.setAttribute( 'aria-expanded', 'false' ); + menu.setAttribute( 'aria-expanded', 'false' ); + } else { container.className += ' toggled'; + button.setAttribute( 'aria-expanded', 'true' ); + menu.setAttribute( 'aria-expanded', 'true' ); + } }; } )();