From e3ca4b831962b8e584b635d3e8402f04211ccd63 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Wed, 9 Oct 2024 14:51:44 -0400 Subject: [PATCH] Toggle sidebar sections --- .prettierrc | 4 ++++ assets/js/sidebar.ts | 9 ++++----- assets/scss/_sidebar.scss | 9 ++++++++- hugo.toml | 14 ++++++++++++-- layouts/partials/sidebar.html | 20 ++++++++++---------- 5 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..c1a6f6671 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/assets/js/sidebar.ts b/assets/js/sidebar.ts index 74c0ab15b..e49fa96fe 100644 --- a/assets/js/sidebar.ts +++ b/assets/js/sidebar.ts @@ -5,7 +5,7 @@ document const child = sidebarParent.parentNode.querySelector( '.js-sidebar-child-group' ); - const caret = sidebarParent.parentNode + const caret = sidebarParent .querySelector('.js-sidebar-toggle') .querySelector('.caret'); @@ -18,17 +18,16 @@ document }); // Handle toggle click behaviour -document.querySelectorAll('.js-sidebar-toggle').forEach((toggle) => { +document.querySelectorAll('.js-sidebar-parent').forEach((toggle) => { toggle.addEventListener('click', (e) => { e.preventDefault(); - const sidebarParent = toggle.parentNode.querySelector('.js-sidebar-parent'); const child = toggle.parentNode.querySelector('.js-sidebar-child-group'); const caret = toggle.querySelector('.caret'); // We aren't using the class here because expanded parents are not always active - const isExpanded = sidebarParent?.getAttribute('aria-expanded') === 'true'; + const isExpanded = toggle?.getAttribute('aria-expanded') === 'true'; - sidebarParent?.setAttribute('aria-expanded', isExpanded ? 'false' : 'true'); + toggle?.setAttribute('aria-expanded', isExpanded ? 'false' : 'true'); child?.setAttribute('aria-hidden', isExpanded ? 'true' : 'false'); child?.classList.toggle('hide', isExpanded); caret?.classList.toggle('rotate', isExpanded); diff --git a/assets/scss/_sidebar.scss b/assets/scss/_sidebar.scss index 77e571baa..3162f859f 100644 --- a/assets/scss/_sidebar.scss +++ b/assets/scss/_sidebar.scss @@ -129,10 +129,17 @@ font-size: 16px; font-weight: 700; margin-bottom: calc(var(--mm-spacing) / 8); + outline: none; + width: 100%; - &:hover { + &:hover, + &:focus { text-decoration: none; } + + &:hover .caret { + fill: var(--mm-color-display-text); + } } .sidebar__toggle { diff --git a/hugo.toml b/hugo.toml index 5e682b39b..9b966659c 100644 --- a/hugo.toml +++ b/hugo.toml @@ -22,11 +22,16 @@ title = 'MaxMind' name = 'minFraud' pageRef = '/minfraud' weight = 10 + [[menus.minfraud]] + name = 'Overview' + pageRef = '/minfraud' + parent = 'minFraud' + weight = 10 [[menus.minfraud]] name = 'Evaluate a Transaction' pageRef = '/minfraud/evaluate-a-transaction' parent = 'minFraud' - weight = 10 + weight = 15 [[menus.minfraud]] name = 'Report a transaction' pageRef = '/minfraud/report-a-transaction' @@ -86,11 +91,16 @@ title = 'MaxMind' name = 'GeoIP' pageRef = '/geoip' weight = 10 + [[menus.geoip]] + name = 'Overview' + pageRef = '/geoip' + parent = 'GeoIP' + weight = 10 [[menus.geoip]] name = 'Geolocate an IP' pageRef = '/geoip/geolocate-an-ip' parent = 'GeoIP' - weight = 10 + weight = 15 [[menus.geoip]] name = 'Databases' pageRef = '/geoip/geolocate-an-ip/databases' diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 8c772051c..4fb3114b9 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -8,13 +8,13 @@ href="{{ .URL }}" > {{ .Name }} + {{ if .HasChildren }} -