Skip to content

Commit 1e4443d

Browse files
fixed-mobile-hamburger-to-header-#2066
1 parent 0872315 commit 1e4443d

File tree

6 files changed

+85
-15
lines changed

6 files changed

+85
-15
lines changed

assets/sass/layout.scss

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,18 @@ header {
185185
padding: 1rem 0;
186186

187187
display: grid;
188-
grid-template-areas: "logo tagline search dark";
188+
grid-template-areas: "logo tagline search controls";
189189
grid-template-columns: auto 1fr auto auto;
190190
align-items: center;
191191

192+
.header-controls {
193+
grid-area: controls;
194+
display: flex;
195+
align-items: center;
196+
gap: 1rem;
197+
padding-left: 1rem;
198+
}
199+
192200
#logo {
193201
grid-area: logo;
194202
display: flex;
@@ -507,11 +515,18 @@ table.benchmarks {
507515
// Mobile
508516
@media (max-width: $mobile-m) {
509517
header {
510-
grid-template-areas: "logo tagline dark"
511-
"search search search";
518+
grid-template-areas: "logo tagline controls"
519+
"search search search";
520+
padding: 0.5rem 1rem;
521+
512522
#tagline {
513523
font-size: clamp(0.8rem, 3vw, 1.3rem);
514524
}
525+
526+
.header-controls {
527+
padding-left: 0;
528+
justify-content: flex-end;
529+
}
515530
}
516531
#masthead {
517532
.inner { flex-direction: column-reverse; }

assets/sass/sidebar.scss

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,27 @@ aside.sidebar.active {
3535
}
3636
.sidebar-btn {
3737
display: none;
38+
border: none;
39+
background: none;
40+
padding: 0;
41+
margin: 0;
42+
cursor: pointer;
43+
width: 24px;
44+
height: 24px;
45+
transition: opacity 0.2s ease;
46+
filter: sepia(100%) saturate(300%) brightness(70%) hue-rotate(350deg);
47+
opacity: 0.8;
48+
49+
&:hover {
50+
opacity: 1;
51+
}
3852
}
3953

4054
// Breakpoint ----------------
4155
@media (max-width: $default) {
4256
.sidebar-btn {
43-
@include background-image-2x($baseurl + "images/icons/sidebar", 24px, 24px, left center);
44-
@include border-top-right-radius(5px);
45-
@include border-bottom-right-radius(5px);
46-
background-color: var(--black-3) !important;
57+
@include background-image-2x($baseurl + "images/icons/sidebar", 24px, 24px, center center);
4758
display: block;
48-
position: fixed;
49-
padding: 2rem 0rem;
50-
z-index: 1;
51-
border: none;
52-
left: 0;
53-
width: 1.6rem;
5459
}
5560
.sidebar-btn:focus + .sidebar, .sidebar:focus-within {
5661
@include responsive-sidebar-ui;

layouts/_default/baseof.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ <h1>Redirecting&hellip;</h1>
6868
{{ $style := resources.Get "sass/application.scss" | resources.ExecuteAsTemplate "application.scss" . | css.Sass | resources.Minify | fingerprint }}
6969
<link rel="stylesheet" href="{{ $style.RelPermalink }}"{{ if (hasPrefix .Site.BaseURL "https://") }} integrity="{{ $style.Data.Integrity }}"{{ end }}>
7070
<script src="{{ relURL "js/modernizr.js" }}"></script>
71+
<script src="{{ relURL "js/mobile-nav.js" }}"></script>
7172
<!--[if (gte IE 6)&(lte IE 8)]>
7273
<script src="{{ relURL "js/selectivizr-min.js" }}"></script>
7374
<![endif]-->

layouts/partials/header.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,23 @@
2121
<div id="search-results"></div>
2222
</div>
2323
{{ end }}
24-
<img src="{{ relURL "images/dark-mode.svg" }}" id="dark-mode-button" />
24+
<div class="header-controls">
25+
<!-- toggle button for dark mode -->
26+
<img src="{{ relURL "images/dark-mode.svg" }}" id="dark-mode-button" />
27+
28+
<!-- toggle button for sidebar -->
29+
{{ $section := .Scratch.Get "section" }}
30+
{{ if or
31+
(eq $section "about")
32+
(eq $section "learn")
33+
(eq $section "tools")
34+
(eq $section "docs")
35+
(eq $section "install")
36+
(eq $section "community")
37+
(eq .Params.Subsection "reference")
38+
(eq .Params.Subsection "manual")
39+
}}
40+
<button class="sidebar-btn" aria-label="Toggle menu"></button>
41+
{{ end }}
42+
</div>
2543
</header>

layouts/partials/sidebar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{ $section := .Scratch.Get "section" }}
2-
<div tabindex="1" class="sidebar-btn"></div>
32
<aside class="sidebar" id="sidebar">
43
<nav>
54
<ul>

static/js/mobile-nav.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
document.addEventListener('DOMContentLoaded', function() {
2+
const sidebarBtn = document.querySelector('.sidebar-btn');
3+
const sidebar = document.getElementById('sidebar');
4+
5+
if (sidebarBtn && sidebar) {
6+
// Set initial ARIA state
7+
sidebarBtn.setAttribute('aria-expanded', 'false');
8+
9+
// Toggle sidebar when button is clicked
10+
sidebarBtn.addEventListener('click', function() {
11+
const isExpanded = this.getAttribute('aria-expanded') === 'true';
12+
this.setAttribute('aria-expanded', !isExpanded);
13+
sidebar.classList.toggle('active');
14+
});
15+
16+
// Close sidebar when clicking outside
17+
document.addEventListener('click', function(e) {
18+
if (!sidebar.contains(e.target) && !sidebarBtn.contains(e.target)) {
19+
sidebar.classList.remove('active');
20+
sidebarBtn.setAttribute('aria-expanded', 'false');
21+
}
22+
});
23+
24+
// Close sidebar when pressing Escape key
25+
document.addEventListener('keydown', function(e) {
26+
if (e.key === 'Escape' && sidebar.classList.contains('active')) {
27+
sidebar.classList.remove('active');
28+
sidebarBtn.setAttribute('aria-expanded', 'false');
29+
}
30+
});
31+
}
32+
});

0 commit comments

Comments
 (0)