Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(TopNav): show mobile toggle when SideNav content is in context (#826)

Cindy Zhang2b46def1662c
diff --git a/packages/core/src/AppShell/XDSAppShell.tsx b/packages/core/src/AppShell/XDSAppShell.tsx
index ae50416d98..b2b7788b88 100644
--- a/packages/core/src/AppShell/XDSAppShell.tsx
+++ b/packages/core/src/AppShell/XDSAppShell.tsx
@@ -628,12 +628,23 @@ export function XDSAppShell({
// stays pinned while the page scrolls. The ref is used to measure header
// height for the sideNav's sticky offset.
// =========================================================================
- // When below breakpoint, TopNav renders in mobile-bar mode (heading + endContent + toggle)
+ // When below breakpoint, TopNav renders in mobile-bar mode (heading + endContent + toggle).
+ // Wrap with mobile content context so TopNav knows there's SideNav content
+ // in the drawer and shows the toggle even without its own collapsible items.
const topNavContent = hasTopNav ? (
isBelowBreakpoint && mobileNavEnabled ? (
- <XDSTopNavRenderContext value="mobile-bar">
- {topNav}
- </XDSTopNavRenderContext>
+ <XDSTopNavMobileContentContext
+ value={
+ hasSideNav ? (
+ <XDSSideNavRenderContext value="drawer-content">
+ {sideNav}
+ </XDSSideNavRenderContext>
+ ) : null
+ }>
+ <XDSTopNavRenderContext value="mobile-bar">
+ {topNav}
+ </XDSTopNavRenderContext>
+ </XDSTopNavMobileContentContext>
) : (
topNav
)
diff --git a/packages/core/src/TopNav/XDSTopNav.tsx b/packages/core/src/TopNav/XDSTopNav.tsx
index 192593e0b0..b7e20181bd 100644
--- a/packages/core/src/TopNav/XDSTopNav.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.tsx
@@ -179,6 +179,8 @@ export function XDSTopNav({
const mobileContent = useXDSTopNavMobileContent();
const hasCenterContent = centerContent != null;
const hasCollapsibleContent = startContent != null || centerContent != null;
+ // Show mobile toggle when there's ANY drawer content — own items OR SideNav via context
+ const hasMobileDrawerContent = hasCollapsibleContent || mobileContent != null;
// =========================================================================
// Mobile bar mode — heading + endContent + toggle, hide nav items
@@ -199,7 +201,7 @@ export function XDSTopNav({
{heading && <div {...stylex.props(styles.heading)}>{heading}</div>}
<div {...stylex.props(styles.mobileBarEnd)}>
{endContent}
- {hasCollapsibleContent && <XDSMobileNavToggle />}
+ {hasMobileDrawerContent && <XDSMobileNavToggle />}
</div>
</nav>
);