Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ nav#sidebar {
z-index: $z-index-for-handbook-nav;
margin-left: -800px;
width: 90%;
visibility: hidden;

ul {
padding-bottom: 200px;
Expand All @@ -223,6 +224,7 @@ nav#sidebar {

&.show {
margin-left: 0px;
visibility: visible;
}

& > ul > li,
Expand Down
21 changes: 21 additions & 0 deletions packages/typescriptlang-org/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ const toggleNavigationSection: MouseEventHandler = (event) => {
export const SidebarToggleButton = () => {
const toggleClick = () => {
const navSidebar = document.getElementById("sidebar")
const toggleButton = document.getElementById("small-device-button-sidebar")
const isOpen = navSidebar?.classList.contains("show")
if (isOpen) {
navSidebar?.classList.remove("show")
navSidebar?.setAttribute("inert", "")
toggleButton?.focus()
} else {
navSidebar?.classList.add("show")
navSidebar?.removeAttribute("inert")
}
}

Expand Down Expand Up @@ -127,6 +131,23 @@ export const Sidebar = (props: Props) => {
}
}

useEffect(() => {
const sidebar = document.getElementById("sidebar")
if (!sidebar) return

const mq = window.matchMedia("(max-width: 800px)")
const sync = () => {
if (mq.matches && !sidebar.classList.contains("show")) {
sidebar.setAttribute("inert", "")
} else {
sidebar.removeAttribute("inert")
}
}
sync()
mq.addEventListener("change", sync)
return () => mq.removeEventListener("change", sync)
}, [])

return (
<nav aria-label="sidebar" id="sidebar">
<ul>
Expand Down
Loading