Skip to content
13 changes: 13 additions & 0 deletions src/components/focus-active-link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import {useEffect} from 'react';
import {usePathname} from 'next/navigation';

type Props = {
activeLinkSelector: string;
Expand Down Expand Up @@ -96,3 +97,15 @@ export function ScrollActiveLink({activeLinkSelector}: Props) {
// don't render anything, just exist as a client-side component for the useEffect.
return null;
}

/** Uncheck the sidebar toggle checkbox whenever the route changes, closing it on mobile. */
export function CloseSidebarOnNavigation({sidebarToggleId}: {sidebarToggleId: string}) {
const pathname = usePathname();
useEffect(() => {
const checkbox = document.getElementById(sidebarToggleId) as HTMLInputElement | null;
if (checkbox) {
checkbox.checked = false;
}
}, [pathname, sidebarToggleId]);
return null;
}
44 changes: 24 additions & 20 deletions src/components/mobileMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@ export function MobileMenu({pathname, searchPlatforms}: Props) {

<Popover.Portal>
<Theme accentColor="iris">
<Popover.Content className={styles.PopoverContent} sideOffset={5}>
<Popover.Content className={styles.PopoverContent} sideOffset={5} align="end">
<Box display={{xs: 'block', sm: 'none'}}>
<li className={styles.MenuItem}>
<Search path={pathname} searchPlatforms={searchPlatforms} />
</li>
<ul className="list-none p-0 m-0">
<li className={styles.MenuItem}>
<Search path={pathname} searchPlatforms={searchPlatforms} />
</li>
</ul>
<div className={styles.MenuSeparator} />
</Box>
{mainSections.map(section => (
<li key={section.href} className={styles.MenuItem}>
<Link href={section.href}>{section.label}</Link>
<ul className="list-none p-0 m-0">
{mainSections.map(section => (
<li key={section.href} className={styles.MenuItem}>
<Link href={section.href}>{section.label}</Link>
</li>
))}
<li className={styles.MenuItem}>
<Link href="https://sentry.io/changelog/">Changelog</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sandbox.sentry.io/">Sandbox</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sentry.io/">Go to Sentry</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sentry.io/signup/">Get Started</Link>
</li>
))}
<li className={styles.MenuItem}>
<Link href="https://sentry.io/changelog/">Changelog</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sandbox.sentry.io/">Sandbox</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sentry.io/">Go to Sentry</Link>
</li>
<li className={styles.MenuItem}>
<Link href="https://sentry.io/signup/">Get Started</Link>
</li>
</ul>
</Popover.Content>
</Theme>
</Popover.Portal>
Expand Down
3 changes: 2 additions & 1 deletion src/components/sidebar/developDocsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {DocNode, nodeForPath} from 'sentry-docs/docTree';

import styles from './style.module.scss';

import {ScrollActiveLink} from '../focus-active-link';
import {CloseSidebarOnNavigation, ScrollActiveLink} from '../focus-active-link';

import {DynamicNav, toTree} from './dynamicNav';
import {SidebarLink, SidebarSeparator} from './sidebarLink';
Expand Down Expand Up @@ -44,6 +44,7 @@ export function DevelopDocsSidebar({
return (
<aside className={`${styles.sidebar} p-3`} data-layout-anchor="left">
<input type="checkbox" id={sidebarToggleId} className="hidden" />
<CloseSidebarOnNavigation sidebarToggleId={sidebarToggleId} />
<style>{':root { --sidebar-width: 300px; }'}</style>
<div className="flex flex-col items-stretch h-full min-h-0">
<div className={styles.toc}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Platform} from 'sentry-docs/types';

import styles from './style.module.scss';

import {ScrollActiveLink} from '../focus-active-link';
import {CloseSidebarOnNavigation, ScrollActiveLink} from '../focus-active-link';
import {PlatformSelector} from '../platformSelector';
import {VersionSelector} from '../versionSelector';

Expand Down Expand Up @@ -154,6 +154,7 @@ export async function Sidebar({path, versions}: SidebarProps) {
return (
<aside className={`${styles.sidebar} py-3`} data-layout-anchor="left">
<input type="checkbox" id={sidebarToggleId} className="hidden" />
<CloseSidebarOnNavigation sidebarToggleId={sidebarToggleId} />
<style>{':root { --sidebar-width: 300px; }'}</style>
<div className="flex flex-col items-stretch h-full min-h-0">
<MobileSidebarNav platforms={basicPlatforms} />
Expand Down
1 change: 0 additions & 1 deletion src/components/sidebar/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
left: 0;
top: var(--header-height, 80px);
width: var(--sidebar-width);
height: calc(100vh - var(--header-height, 80px));
display: flex;

& + :global(.main-content) {
Expand Down
Loading