Skip to content

Commit 50df63f

Browse files
committed
Sidebar: Mobile support
1 parent 4da9c2e commit 50df63f

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed

assets/css/v2/style.css

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
--sidebar-line-box-left: 12px;
9292
--sidebar-width: 22rem;
9393
--sidebar-line-width: 11.5px;
94+
--sidebar-mobile-top-displacement: 3rem;
9495
--side-gutter-width: 20rem;
9596
--table-top-bottom-spacing: 1rem;
9697
--table-row-space-between: 1.5rem;
@@ -266,6 +267,10 @@ header {
266267
padding: 20px 10px;
267268
}
268269

270+
.nav-item-explore {
271+
margin: 0;
272+
}
273+
269274
.navbar-button {
270275
padding: 0.5rem 0.5rem;
271276
border: none;
@@ -526,8 +531,74 @@ nav {
526531
column-gap: var(--grid-column-gutter);
527532
}
528533

529-
.sidebar-layout {
530-
display: none;
534+
body:has(#sidebar-v2[style*="block"]) {
535+
/* Disable scrolling in main content + hide footer if the sidebar is visible */
536+
overflow-y: hidden;
537+
538+
.sidebar-layout {
539+
position: absolute;
540+
height: 100%;
541+
}
542+
543+
footer {
544+
display: none;
545+
}
546+
547+
.sidebar-layout .sidebar-mobile-toggle {
548+
display: flex !important;
549+
align-items: center;
550+
position: sticky;
551+
top: 1rem;
552+
margin-top: 2rem;
553+
padding: 0.5rem;
554+
color: white;
555+
background-color: oklch(var(--color-brand));
556+
}
557+
}
558+
559+
.breadcrumb .sidebar-mobile-toggle {
560+
display: inline !important;
561+
padding: 0;
562+
}
563+
564+
.sidebar-mobile-toggle {
565+
background-color: transparent;
566+
border: none;
567+
568+
.lucide {
569+
margin-right: 1rem;
570+
}
571+
}
572+
573+
.main-layout {
574+
/* Mobile support for sidebar */
575+
display: flex;
576+
flex-direction: column;
577+
position: relative;
578+
579+
.sidebar-layout {
580+
min-height: fit-content;
581+
background: white;
582+
z-index: 3;
583+
width: calc(100% + 4rem);
584+
margin-left: -2rem;
585+
586+
&::before {
587+
display: none;
588+
}
589+
590+
nav {
591+
width: 100%;
592+
display: none;
593+
padding: 0;
594+
top: var(--sidebar-mobile-top-displacement);
595+
max-height: calc(100vh - var(--sidebar-mobile-top-displacement));
596+
597+
.sidebar__container {
598+
width: 100%;
599+
}
600+
}
601+
}
531602
}
532603

533604
main {
@@ -936,6 +1007,16 @@ p {
9361007
line-height: 1.5rem;
9371008
}
9381009

1010+
.breadcrumb-layout {
1011+
position: sticky;
1012+
top: 0;
1013+
z-index: 3;
1014+
background-color: white;
1015+
width: calc(100% + 4rem);
1016+
margin-left: -2rem;
1017+
padding: 1rem 2rem;
1018+
}
1019+
9391020
.breadcrumb {
9401021
color: var(--color-foreground);
9411022
text-decoration: none;
@@ -1163,7 +1244,7 @@ blockquote p:last-child {
11631244
}
11641245

11651246
/* Maintain the split column for as long as possible */
1166-
@media (min-width: 67rem) {
1247+
@media (min-width: 88rem) {
11671248
blockquote.side-callout {
11681249
grid-column: 2 !important;
11691250
align-self: start;

assets/js/sidebar-v2.js

Lines changed: 18 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,6 +15,23 @@ 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+
sidebar.setAttribute(
24+
'style',
25+
!expanded ? 'display: block;' : 'display: none;'
26+
);
27+
28+
// Set the aria for all the toggle buttons so they are in lockstep
29+
const toggleButtons = document.getElementsByClassName(
30+
'sidebar-mobile-toggle'
31+
);
32+
for (const button of [...toggleButtons]) {
33+
button.setAttribute('aria-expanded', String(!expanded));
34+
}
1735
}
1836
});
1937

layouts/_default/docs.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@
6969

7070
<section class="main-layout">
7171
<div class="sidebar-layout" id="sidebar-layout">
72-
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
72+
<button class="sidebar-mobile-toggle" style="display: none;" aria-expanded="false">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
73+
<nav data-mf="true" id="sidebar-v2" class="sidebar">
7374
{{ partial "sidebar-v2.html" . }}
7475
</nav>
7576
</div>
7677

7778
<section id="maincontent" class="content-layout">
7879
<div data-cms-edit="content" class="text-content">
79-
<section class="breadcrumb-layout" data-mf="true" style="display: none;">
80+
<section class="breadcrumb-layout wide" data-mf="true" style="display: none;">
8081
{{ if not .IsHome }}
8182
{{ if not (in .Params.display_breadcrumb "false" ) }}
8283
{{ partial "breadcrumb" .}}

layouts/_default/list.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
<main class="content col d-block align-top content-has-toc" role="main" data-mf="true" style="display: none">
1414
<section class="main-layout">
1515
<div class="sidebar-layout" id="sidebar-layout">
16+
<button class="sidebar-mobile-toggle" style="display: none;" aria-expanded="false">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
1617
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
1718
{{ partial "sidebar-v2.html" . }}
1819
</nav>
1920
</div>
2021

2122
<section id="maincontent" class="content-layout" data-mf="true" style="display: none">
2223
<div data-cms-edit="content" class="text-content list-page">
23-
<section class="breadcrumb-layout">
24+
<section class="breadcrumb-layout wide">
2425
{{ if not .IsHome }}
2526
{{ if not (in .Params.display_breadcrumb "false" ) }}
2627
{{ partial "breadcrumb" .}}

layouts/partials/breadcrumb.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<nav aria-label="breadcrumb" class="breadcrumb navbar">
22
<div class="nav flex-md-row">
33
<ol class="breadcrumb">
4+
<button class="sidebar-mobile-toggle" aria-expanded="false" style="display: none;">{{ partial "lucide" (dict "context" . "icon" "align-justify") }}</button>
45
<li><a href="/" alt="NGINX Docs Home">Home</a></li>
56
{{- define "breadcrumb" -}}
67
{{- with .Parent -}}

0 commit comments

Comments
 (0)