From 35d53d2231bb45ca29edfb87e6d28b3f551144ce Mon Sep 17 00:00:00 2001 From: quanb-duy Date: Fri, 21 Mar 2025 16:56:27 +0100 Subject: [PATCH 1/2] Collapse/expand buttons in left navigation improvement for navigating using keyboard --- assets/scss/menu.scss | 118 +++++++++++++++++++++------------- layouts/partials/sidebar.html | 33 ++++++---- static/js/menu.js | 20 ++++++ 3 files changed, 114 insertions(+), 57 deletions(-) diff --git a/assets/scss/menu.scss b/assets/scss/menu.scss index 57c4318..a7756fc 100644 --- a/assets/scss/menu.scss +++ b/assets/scss/menu.scss @@ -47,43 +47,64 @@ opacity: 0; } - &__mobile-trigger { - display: none; - } - - &__mobile-icon { + &__mobile-btn { position: fixed; top: $header-first-nav-height-desktop; + left: 10px; + z-index: 34; display: flex; justify-content: center; align-items: center; width: 55px; height: $header-second-nav-height; - left: 10px; - z-index: 34; + padding: 0; + background: transparent; + border: none; transition: $transition; cursor: pointer; + &:focus { + outline: 2px solid $color-shocking-pink; + outline-offset: 2px; + } + + @include mq(large) { + display: none; + } + } + + &__mobile-icon { + position: relative; + display: flex; + justify-content: center; + align-items: center; + width: 26px; + height: 22px; + &::before { content: url("../img/burger.svg"); display: block; width: 26px; height: 22px; } + } - &::after { - content: ""; + &__mobile-btn[aria-expanded="true"] { + left: calc(100% - 55px); + + .gd-docs-menu__mobile-icon::before { display: none; + } + + .gd-docs-menu__mobile-icon::after { + content: ""; + display: block; width: 31px; height: 31px; background-image: url("../img/close.svg"); background-repeat: no-repeat; background-size: contain; } - - @include mq(large) { - display: none; - } } &__mobile-bg { @@ -101,23 +122,11 @@ } } - &__mobile-trigger:checked ~ &, - &__mobile-trigger:checked ~ &__mobile-bg { + &__mobile-btn[aria-expanded="true"] ~ &, + &__mobile-btn[aria-expanded="true"] ~ &__mobile-bg { left: 0; } - &__mobile-trigger:checked ~ &__mobile-icon { - left: calc(100% - 55px); - - &::before { - display: none; - } - - &::after { - display: block; - } - } - & > &-section { padding-left: 0; } @@ -141,6 +150,14 @@ } } + &-section-wrapper { + display: none; + + &.expanded { + display: block; + } + } + &-page__label ~ &-section { padding-left: 0; } @@ -193,25 +210,42 @@ } } - &__toggle { - display: none; - } - - &__chevron { + &__toggle-btn { + display: flex; + align-items: center; + justify-content: center; margin: 4px 0 0; + padding: 4px; + background: transparent; + border: none; cursor: pointer; - - svg { + + // Add focus styles for keyboard navigation + &:focus { + outline: 2px solid $color-shocking-pink; + outline-offset: 2px; + border-radius: 3px; + } + + // SVG rotation based on expanded state + &[aria-expanded="false"] .gd-docs-menu-page__chevron svg { transform: rotate(180deg); } - } - - &__toggle:checked ~ &__title &__chevron { - svg { + + &[aria-expanded="true"] .gd-docs-menu-page__chevron svg { transform: rotate(0deg); } } + &__chevron { + display: flex; + margin: 0; + } + + &__toggle { + display: none; + } + &__label { display: block; flex: 0 0 auto; @@ -223,14 +257,6 @@ } } - &-page__toggle ~ &-section { - display: none; - } - - &-page__toggle:checked ~ &-section { - display: block; - } - .dropdown-toggle { display: flex; justify-content: space-between; diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 34c4827..94686ee 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -1,8 +1,9 @@ {{/* (C) 2023 GoodData Corporation */}} - - +
-