Skip to content

Commit 1ff305f

Browse files
committed
Revert "Close the mobile menu before navigation"
This reverts commit 5bcd020.
1 parent 5bcd020 commit 1ff305f

3 files changed

Lines changed: 7 additions & 36 deletions

File tree

src/components/Layout/Sidebar/SidebarLink.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ interface SidebarLinkProps {
2626
icon?: React.ReactNode;
2727
isExpanded?: boolean;
2828
hideArrow?: boolean;
29-
onNavigate?: () => void;
3029
}
3130

3231
export function SidebarLink({
@@ -37,7 +36,6 @@ export function SidebarLink({
3736
level,
3837
isExpanded,
3938
hideArrow,
40-
onNavigate,
4139
}: SidebarLinkProps) {
4240
const ref = useRef<HTMLAnchorElement>(null);
4341

@@ -61,7 +59,6 @@ export function SidebarLink({
6159
ref={ref}
6260
title={title}
6361
target={target}
64-
onNavigate={onNavigate}
6562
passHref
6663
aria-current={selected ? 'page' : undefined}
6764
className={cn(

src/components/Layout/Sidebar/SidebarRouteTree.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface SidebarRouteTreeProps {
2323
breadcrumbs: RouteItem[];
2424
routeTree: RouteItem;
2525
level?: number;
26-
onNavigate?: () => void;
2726
}
2827

2928
function CollapseWrapper({
@@ -82,7 +81,6 @@ export function SidebarRouteTree({
8281
breadcrumbs,
8382
routeTree,
8483
level = 0,
85-
onNavigate,
8684
}: SidebarRouteTreeProps) {
8785
const slug = (usePathname() || '/').split(/[\?\#]/)[0];
8886
const currentRoutes = routeTree.routes as RouteItem[];
@@ -111,7 +109,6 @@ export function SidebarRouteTree({
111109
isForceExpanded={isForceExpanded}
112110
routeTree={{title, routes}}
113111
breadcrumbs={[]}
114-
onNavigate={onNavigate}
115112
/>
116113
);
117114
} else if (routes) {
@@ -131,15 +128,13 @@ export function SidebarRouteTree({
131128
version={version}
132129
isExpanded={isExpanded}
133130
hideArrow={isForceExpanded}
134-
onNavigate={onNavigate}
135131
/>
136132
<CollapseWrapper duration={250} isExpanded={isExpanded}>
137133
<SidebarRouteTree
138134
isForceExpanded={isForceExpanded}
139135
routeTree={{title, routes}}
140136
breadcrumbs={breadcrumbs}
141137
level={level + 1}
142-
onNavigate={onNavigate}
143138
/>
144139
</CollapseWrapper>
145140
</li>
@@ -154,7 +149,6 @@ export function SidebarRouteTree({
154149
level={level}
155150
title={title}
156151
version={version}
157-
onNavigate={onNavigate}
158152
/>
159153
</li>
160154
);

src/components/Layout/TopNav/TopNav.tsx

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
useRef,
1717
useCallback,
1818
useEffect,
19-
useLayoutEffect,
2019
startTransition,
2120
Suspense,
2221
} from 'react';
@@ -118,9 +117,7 @@ function Link({
118117
href,
119118
children,
120119
...props
121-
}: React.AnchorHTMLAttributes<HTMLAnchorElement> & {
122-
onNavigate?: () => void;
123-
}) {
120+
}: React.AnchorHTMLAttributes<HTMLAnchorElement>) {
124121
return (
125122
<NextLink
126123
href={`${href}`}
@@ -131,12 +128,11 @@ function Link({
131128
);
132129
}
133130

134-
function NavItem({url, isActive, children, onNavigate}: any) {
131+
function NavItem({url, isActive, children}: any) {
135132
return (
136133
<div className="flex flex-auto sm:flex-1">
137134
<Link
138135
href={url}
139-
onNavigate={onNavigate}
140136
className={cn(
141137
'active:scale-95 transition-transform w-full text-center outline-link py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full capitalize whitespace-nowrap',
142138
!isActive && 'hover:bg-primary/5 hover:dark:bg-primary-dark/5',
@@ -173,21 +169,14 @@ export default function TopNav({
173169
const [showSearch, setShowSearch] = useState(false);
174170
const [isScrolled, setIsScrolled] = useState(false);
175171
const scrollParentRef = useRef<HTMLDivElement>(null);
176-
const closeMenu = useCallback(() => setOpenMenuPath(null), []);
177172
// Deriving from the path hides the menu as soon as a navigation commits.
178173
// Forget the path afterwards, so going Back doesn't reopen the menu.
179174
if (openMenuPath !== null && openMenuPath !== asPath) {
180-
closeMenu();
175+
setOpenMenuPath(null);
181176
}
182177
const isMenuOpen = openMenuPath === asPath;
183178
const {breadcrumbs} = getRouteMeta(asPath, routeTree);
184179

185-
// The mobile menu is transient UI. Reset it when Activity hides this route
186-
// so going Back does not restore the menu in its open state.
187-
useLayoutEffect(() => {
188-
return () => setOpenMenuPath(null);
189-
}, []);
190-
191180
// HACK. Fix up the data structures instead.
192181
if ((routeTree as any).routes.length === 1) {
193182
routeTree = (routeTree as any).routes[0];
@@ -428,28 +417,20 @@ export default function TopNav({
428417
{/* No fallback UI so need to be careful not to suspend directly inside. */}
429418
<Suspense fallback={null}>
430419
<div className="ps-3 xs:ps-5 xs:gap-0.5 xs:text-base overflow-x-auto flex flex-row lg:hidden text-base font-bold text-secondary dark:text-secondary-dark">
431-
<NavItem
432-
isActive={section === 'learn'}
433-
url="/learn"
434-
onNavigate={closeMenu}>
420+
<NavItem isActive={section === 'learn'} url="/learn">
435421
Learn
436422
</NavItem>
437423
<NavItem
438424
isActive={section === 'reference'}
439-
url="/reference/react"
440-
onNavigate={closeMenu}>
425+
url="/reference/react">
441426
Reference
442427
</NavItem>
443428
<NavItem
444429
isActive={section === 'community'}
445-
url="/community"
446-
onNavigate={closeMenu}>
430+
url="/community">
447431
Community
448432
</NavItem>
449-
<NavItem
450-
isActive={section === 'blog'}
451-
url="/blog"
452-
onNavigate={closeMenu}>
433+
<NavItem isActive={section === 'blog'} url="/blog">
453434
Blog
454435
</NavItem>
455436
</div>
@@ -464,7 +445,6 @@ export default function TopNav({
464445
routeTree={routeTree}
465446
breadcrumbs={breadcrumbs}
466447
isForceExpanded={isMenuOpen}
467-
onNavigate={closeMenu}
468448
/>
469449
</Suspense>
470450
<div className="h-16" />

0 commit comments

Comments
 (0)