From a1fe48c7463c808db61953c8d3ce84b4a9dad7a5 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Sun, 4 Oct 2020 12:28:36 +0200 Subject: [PATCH 1/9] Update primary navigation Removes aria-haspopup Moves the aria-expanded to the button. Fixes the aria-controls, adding a new ID to the ul. Adds a toggle button for sub menus. --- assets/css/ie.css | 45 +++++++++-------- assets/js/primary-navigation.js | 61 +++++++++++++---------- assets/sass/06-components/navigation.scss | 46 +++++++++-------- header.php | 6 +-- inc/menu-functions.php | 41 +++------------ style-rtl.css | 45 +++++++++-------- style.css | 45 +++++++++-------- 7 files changed, 143 insertions(+), 146 deletions(-) diff --git a/assets/css/ie.css b/assets/css/ie.css index 80fa0f1ae..e5eaf5a5d 100644 --- a/assets/css/ie.css +++ b/assets/css/ie.css @@ -5076,7 +5076,7 @@ h1.page-title { .primary-navigation #toggle-menu { display: none; } - .primary-navigation > .primary-menu-container > ul > li > ul { + .primary-navigation > .primary-menu-container ul > li .sub-menu-toggle[aria-expanded="false"] ~ ul { display: none; } .admin-bar .primary-navigation { @@ -5112,34 +5112,40 @@ h1.page-title { margin: 13px 0; position: relative; width: 100%; - z-index: 1; -} - -.primary-navigation > div > .menu-wrapper li:hover, .primary-navigation > div > .menu-wrapper li:focus-within { - cursor: pointer; - z-index: 99999; } @media only screen and (min-width: 482px) { .primary-navigation > div > .menu-wrapper li { - display: inherit; margin: 0; width: inherit; - /* Submenu display in the responsive menu */ - } - .primary-navigation > div > .menu-wrapper li:hover > ul, - .primary-navigation > div > .menu-wrapper li:focus-within > ul, - .primary-navigation > div > .menu-wrapper li ul:hover, - .primary-navigation > div > .menu-wrapper li ul:focus { - visibility: visible; - opacity: 1; - display: block; } .primary-navigation > div > .menu-wrapper li:last-child { margin-right: 0; } } +.primary-navigation > div > .menu-wrapper .sub-menu-toggle { + display: flex; + height: 44px; + width: 44px; + padding: 0; + justify-content: center; + align-items: center; + background: transparent; + color: currentColor; + border: none; +} + +.primary-navigation > div > .menu-wrapper .sub-menu-toggle:focus { + outline: 2px solid #28303d; +} + +@media only screen and (max-width: 481px) { + .primary-navigation > div > .menu-wrapper .sub-menu-toggle { + display: none; + } +} + .primary-navigation > div > .menu-wrapper > li > .sub-menu { position: relative; } @@ -5150,11 +5156,10 @@ h1.page-title { left: 0; margin: 0; min-width: max-content; - opacity: 0; position: absolute; - top: calc(100% - 13px); + top: 100%; transition: all 0.5s ease; - visibility: hidden; + z-index: 99999; } } diff --git a/assets/js/primary-navigation.js b/assets/js/primary-navigation.js index 44365ce9e..5f88f722e 100644 --- a/assets/js/primary-navigation.js +++ b/assets/js/primary-navigation.js @@ -3,30 +3,40 @@ * * Required to open and close the mobile navigation. */ -( function() { - /** - * Toggle an attribute's value - * - * @param {Element} element - * @param {Attribute} attribute - * @param {String} trueVal - * @param {String} falseVal - * @since 1.0.0 - */ - var toggleAttribute = function ( element, attribute, trueVal, falseVal ) { - if ( undefined === trueVal ) { - trueVal = true; - } - if ( undefined === falseVal ) { - falseVal = false; - } - if ( trueVal !== element.getAttribute( attribute ) ) { - element.setAttribute( attribute, trueVal ); - } else { - element.setAttribute( attribute, falseVal ); - } +/** + * Toggle an attribute's value + * + * @param {Element} element + * @param {Attribute} attribute + * @param {String} trueVal + * @param {String} falseVal + * @since 1.0.0 + */ +function twentytwentyoneToggleAttribute(element, attribute, trueVal, falseVal) { + if (undefined === trueVal) { + trueVal = true; + } + if (undefined === falseVal) { + falseVal = false; } + if (trueVal !== element.getAttribute(attribute)) { + element.setAttribute(attribute, trueVal); + } else { + element.setAttribute(attribute, falseVal); + } +} + +/** + * Handle clicks on submenu toggles. + * + * @param {Element} el + */ +function twentytwentyoneExpandSubMenu(el) { // eslint-disable-line no-unused-vars + twentytwentyoneToggleAttribute(el, 'aria-expanded', 'true', 'false'); +} + +( function() { /** * Menu Toggle Behaviors @@ -41,11 +51,10 @@ mobileButton.onclick = function() { wrapper.classList.toggle( `${ id }-navigation-open` ); wrapper.classList.toggle( 'lock-scrolling' ); - toggleAttribute( mobileButton, 'aria-expanded', 'true', 'false' ); + twentytwentyoneToggleAttribute( mobileButton, 'aria-expanded', 'true', 'false' ); mobileButton.focus(); } } - /** * Trap keyboard navigation in the menu modal. * Adapted from TwentyTwenty @@ -53,7 +62,7 @@ document.addEventListener( 'keydown', function( event ) { if ( ! wrapper.classList.contains( `${ id }-navigation-open` ) ){ return; - } + } var modal, elements, selectors, lastEl, firstEl, activeEl, tabKey, shiftKey, escKey; modal = document.querySelector( `.${ id }-navigation` ); @@ -94,4 +103,4 @@ window.addEventListener( 'load', function() { new navMenu( 'primary' ); }); -} )(); \ No newline at end of file +} )(); diff --git a/assets/sass/06-components/navigation.scss b/assets/sass/06-components/navigation.scss index 5c25498b9..7674ed5bb 100644 --- a/assets/sass/06-components/navigation.scss +++ b/assets/sass/06-components/navigation.scss @@ -162,7 +162,7 @@ } // Hide sub-sub-menus - > .primary-menu-container > ul > li > ul { + > .primary-menu-container ul > li .sub-menu-toggle[aria-expanded="false"] ~ ul { display: none; } @@ -200,35 +200,38 @@ margin: var(--primary-nav--padding) 0; position: relative; width: 100%; - z-index: 1; - - &:hover, - &:focus-within { - cursor: pointer; - z-index: 99999; - } @include media(mobile) { - display: inherit; margin: 0; width: inherit; - /* Submenu display in the responsive menu */ - &:hover > ul, - &:focus-within > ul, - ul:hover, - ul:focus { - visibility: visible; - opacity: 1; - display: block; - } - &:last-child() { margin-right: 0; } } } + // Sub menu buttons + .sub-menu-toggle { + display: flex; + height: 44px; + width: 44px; + padding: 0; + justify-content: center; + align-items: center; + background: transparent; + color: currentColor; + border: none; + + &:focus { + outline: 2px solid var(--wp--style--color--link, var(--global--color-primary)); + } + + @include media(mobile-only) { + display: none; + } + } + // Sub-menus Flyout > li > .sub-menu { @@ -239,11 +242,10 @@ left: 0; margin: 0; min-width: max-content; - opacity: 0; position: absolute; - top: calc(100% - var(--primary-nav--padding)); + top: 100%; transition: all 0.5s ease; - visibility: hidden; + z-index: 99999; } .sub-menu { diff --git a/header.php b/header.php index 1208ee030..6b8e7472b 100644 --- a/header.php +++ b/header.php @@ -30,9 +30,9 @@ -