Skip to content

Commit 68bd3a9

Browse files
committed
Sidebar: Mobile support
1 parent 4b4cca2 commit 68bd3a9

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

assets/css/v2/style.css

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,46 @@ nav {
526526
column-gap: var(--grid-column-gutter);
527527
}
528528

529-
.sidebar-layout {
530-
display: none;
529+
body:has(#sidebar-v2[style*="block"]) {
530+
overflow-y: hidden;
531+
}
532+
533+
.main-layout {
534+
display: flex;
535+
flex-direction: column;
536+
position: relative;
537+
538+
.sidebar-layout {
539+
min-height: fit-content;
540+
position: sticky;
541+
top: 0;
542+
padding: 1rem;
543+
background-color: white;
544+
width: calc(100% + 4rem);
545+
margin-left: -2rem;
546+
overflow-y: scroll;
547+
548+
&::before {
549+
display: none;
550+
}
551+
552+
.sidebar-mobile-toggle {
553+
background-color: oklch(var(--color-brand));
554+
color: white;
555+
border: none;
556+
display: block !important;
557+
}
558+
559+
nav {
560+
width: 100%;
561+
height: 100vh;
562+
display: none;
563+
564+
.sidebar__container {
565+
width: 100%;
566+
}
567+
}
568+
}
531569
}
532570

533571
main {

assets/js/sidebar-v2.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
document.addEventListener('click', (e) => {
22
const toggle = e.target.closest('.sidebar__toggle');
3+
const sidebarMobileToggle = e.target.closest('.sidebar-mobile-toggle');
34
if (toggle) {
45
const chevron = toggle.querySelector('.sidebar__chevron');
56
const expanded = toggle.getAttribute('aria-expanded') === 'true';
@@ -14,5 +15,15 @@ document.addEventListener('click', (e) => {
1415
if (chevron) {
1516
chevron.classList.toggle('sidebar__chevron--open', !expanded);
1617
}
18+
} else if (sidebarMobileToggle) {
19+
// Show the sidebar
20+
const sidebar = document.getElementById('sidebar-v2');
21+
const expanded =
22+
sidebarMobileToggle.getAttribute('aria-expanded') === 'true';
23+
sidebarMobileToggle.setAttribute('aria-expanded', String(!expanded));
24+
sidebar.setAttribute(
25+
'style',
26+
!expanded ? 'display: block;' : 'display: none;'
27+
);
1728
}
1829
});

layouts/_default/docs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
<section class="main-layout">
7171
<div class="sidebar-layout" id="sidebar-layout">
72+
<button class="sidebar-mobile-toggle" aria-expanded="false" style="display: none;"><p>Click</p></button>
7273
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
7374
{{ partial "sidebar-v2.html" . }}
7475
</nav>

0 commit comments

Comments
 (0)