Skip to content

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

TypeScript

fix(hardening): navigation sizing adjustments per visual audit (#878)

Ernest05139a10e162
diff --git a/apps/storybook/stories/SideNav.stories.tsx b/apps/storybook/stories/SideNav.stories.tsx
index 48346d160f..94a4cd7bb9 100644
--- a/apps/storybook/stories/SideNav.stories.tsx
+++ b/apps/storybook/stories/SideNav.stories.tsx
@@ -9,6 +9,7 @@ import {XDSBadge} from '@xds/core/Badge';
import {XDSButton} from '@xds/core/Button';
import {XDSIcon} from '@xds/core/Icon';
import {XDSList, XDSListItem} from '@xds/core/List';
+import {XDSMoreMenu} from '@xds/core/MoreMenu';
import {XDSNavIcon} from '@xds/core/NavIcon';
import {XDSText} from '@xds/core/Text';
import {
@@ -396,11 +397,11 @@ export const HiddenSectionHeader: Story = {
};
// =============================================================================
-// Long Heading with Tooltip
+// End Content
// =============================================================================
-export const LongHeadingText: Story = {
- name: 'Long Heading with Tooltip',
+export const EndContent: Story = {
+ name: 'End Content (Badges & Menus)',
render: () => (
<XDSSideNav
header={
@@ -408,20 +409,91 @@ export const LongHeadingText: Story = {
icon={
<XDSNavIcon icon={<CubeIcon style={{width: 16, height: 16}} />} />
}
- heading="Enterprise Resource Planning Dashboard"
- superheading="Acme Corporation International"
- subheading="[email protected]"
+ heading="My App"
headingHref="/"
/>
}>
- <XDSSideNavSection title="Main">
+ <XDSSideNavSection title="Navigation" isHeaderHidden>
<XDSSideNavItem
label="Dashboard"
icon={HomeIcon}
selectedIcon={HomeIconSolid}
isSelected
+ href="/dashboard"
+ endContent={
+ <XDSMoreMenu
+ size="sm"
+ items={[
+ {label: 'Pin to top', onClick: () => {}},
+ {label: 'Rename', onClick: () => {}},
+ {label: 'Hide from sidebar', onClick: () => {}},
+ ]}
+ />
+ }
+ />
+ <XDSSideNavItem
+ label="Projects"
+ icon={FolderIcon}
+ href="/projects"
+ endContent={<XDSBadge label={12} />}
+ />
+ <XDSSideNavItem
+ label="Analytics"
+ icon={ChartBarIcon}
+ href="/analytics"
+ endContent={<XDSBadge label="New" />}
+ />
+ <XDSSideNavItem
+ label="Team"
+ icon={UserGroupIcon}
+ href="/team"
+ endContent={
+ <XDSText type="supporting" color="secondary">
+ 8 members
+ </XDSText>
+ }
+ />
+ <XDSSideNavItem
+ label="Notifications"
+ icon={BellIcon}
+ href="/notifications"
+ endContent={
+ <XDSButton
+ label="Settings"
+ icon={
+ <XDSIcon icon={Cog6ToothIcon} size="sm" color="secondary" />
+ }
+ variant="ghost"
+ size="sm"
+ />
+ }
+ />
+ <XDSSideNavItem
+ label="Documents"
+ icon={DocumentTextIcon}
+ href="/documents"
+ endContent={
+ <XDSText type="supporting" color="secondary">
+ ⌘D
+ </XDSText>
+ }
+ />
+ <XDSSideNavItem
+ label="Settings"
+ icon={Cog6ToothIcon}
+ href="/settings"
+ endContent={
+ <XDSText type="supporting" color="secondary">
+ 3 pending
+ </XDSText>
+ }
+ />
+ <XDSSideNavItem
+ label="A very long navigation label that should truncate with ellipsis"
+ icon={DocumentTextIcon}
+ href="/long"
+ endContent={<XDSBadge label={99} />}
/>
- <XDSSideNavItem label="Projects" icon={FolderIcon} />
</XDSSideNavSection>
</XDSSideNav>
),
diff --git a/packages/core/src/Breadcrumbs/XDSBreadcrumbItem.tsx b/packages/core/src/Breadcrumbs/XDSBreadcrumbItem.tsx
index a65dc914f4..d638a0e756 100644
--- a/packages/core/src/Breadcrumbs/XDSBreadcrumbItem.tsx
+++ b/packages/core/src/Breadcrumbs/XDSBreadcrumbItem.tsx
@@ -15,7 +15,6 @@
import {useContext, type ReactNode, type MouseEvent} from 'react';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {colorVars, spacingVars, typeScaleVars} from '../theme/tokens.stylex';
import {BreadcrumbCtx} from './XDSBreadcrumbs';
import {useXDSLinkComponent} from '../Link/useXDSLinkComponent';
@@ -59,27 +58,6 @@ export interface XDSBreadcrumbItemProps {
* Test ID for the list item.
*/
'data-testid'?: string;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <Component xstyle={overrides.root} />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element. Spread after StyleX
- * inline styles, so these values take priority.
- */
- style?: React.CSSProperties;
}
// =============================================================================
@@ -120,7 +98,7 @@ const itemStyles = stylex.create({
cursor: 'pointer',
},
defaultLink: {
- color: colorVars['--color-text-accent'],
+ color: colorVars['--color-text-secondary'],
},
supportingLink: {
color: colorVars['--color-text-secondary'],
@@ -163,9 +141,6 @@ export function XDSBreadcrumbItem({
isCurrent: isCurrentProp,
startIcon,
'data-testid': testId,
- xstyle,
- className,
- style,
}: XDSBreadcrumbItemProps) {
const ctx = useContext(BreadcrumbCtx);
const isCurrent = isCurrentProp ?? ctx.isAutoLast;
@@ -187,10 +162,7 @@ export function XDSBreadcrumbItem({
stylex.props(
itemStyles.root,
isSupporting ? itemStyles.supportingSize : itemStyles.defaultSize,
- xstyle,
),
- className,
- style,
)}
data-testid={testId}>
<span
@@ -215,10 +187,7 @@ export function XDSBreadcrumbItem({
stylex.props(
itemStyles.root,
isSupporting ? itemStyles.supportingSize : itemStyles.defaultSize,
- xstyle,
),
- className,
- style,
)}
data-testid={testId}>
<LinkComponent
diff --git a/packages/core/src/NavItem/navItemStyles.stylex.ts b/packages/core/src/NavItem/navItemStyles.stylex.ts
index 0c4503566b..9f9da7be64 100644
--- a/packages/core/src/NavItem/navItemStyles.stylex.ts
+++ b/packages/core/src/NavItem/navItemStyles.stylex.ts
@@ -1,7 +1,7 @@
/**
* @file navItemStyles.stylex.ts
- * @input Uses theme tokens (color, spacing, radius, typography, transition)
- * @output Exports shared nav item appearance styles
+ * @input Uses theme tokens (color, spacing, radius, typography, transition, size)
+ * @output Exports shared nav item appearance styles and NavItemSize type
* @position Shared styles consumed by SideNavItem, TopNavItem (drawer mode),
* TopNavMenu (drawer mode), and any custom nav items that need to match.
*
@@ -13,6 +13,8 @@
* focus outlines) via stylex.props composition.
*/
+export type NavItemSize = 'sm' | 'md' | 'lg';
+
import * as stylex from '@stylexjs/stylex';
import {
colorVars,
@@ -20,6 +22,7 @@ import {
radiusVars,
typeScaleVars,
fontWeightVars,
+ sizeVars,
} from '../theme/tokens.stylex';
/**
@@ -46,8 +49,9 @@ export const navItemStyles = stylex.create({
alignItems: 'center',
gap: spacingVars['--spacing-2'],
width: '100%',
+ height: sizeVars['--size-element-md'],
paddingInline: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-2'],
+ paddingBlock: 0,
borderRadius: radiusVars['--radius-element'],
borderWidth: 0,
borderStyle: 'none',
@@ -91,4 +95,22 @@ export const navItemStyles = stylex.create({
cursor: 'not-allowed',
pointerEvents: 'none' as const,
},
+
+ /** Small size variant */
+ sm: {
+ height: sizeVars['--size-element-sm'],
+ paddingInline: spacingVars['--spacing-1'],
+ },
+
+ /** Medium size variant (default) */
+ md: {
+ height: sizeVars['--size-element-md'],
+ paddingInline: spacingVars['--spacing-2'],
+ },
+
+ /** Large size variant */
+ lg: {
+ height: sizeVars['--size-element-lg'],
+ paddingInline: spacingVars['--spacing-2'],
+ },
});
diff --git a/packages/core/src/SideNav/XDSSideNav.test.tsx b/packages/core/src/SideNav/XDSSideNav.test.tsx
index ec7cbe4c65..4c19fcb8fa 100644
--- a/packages/core/src/SideNav/XDSSideNav.test.tsx
+++ b/packages/core/src/SideNav/XDSSideNav.test.tsx
@@ -340,7 +340,7 @@ describe('XDSSideNavHeading headerEndContent', () => {
expect(screen.getByTestId('end-badge')).toBeInTheDocument();
});
- it('renders headerEndContent outside the link in isWholeHeadingLink path', () => {
+ it('renders headerEndContent inside the link in isWholeHeadingLink path', () => {
render(
<XDSSideNavHeading
heading="My App"
@@ -350,11 +350,11 @@ describe('XDSSideNavHeading headerEndContent', () => {
);
const badge = screen.getByTestId('end-badge');
expect(badge).toBeInTheDocument();
- // Badge should NOT be inside the link
- expect(badge.closest('a')).toBeNull();
+ // Badge renders inside the link
+ expect(badge.closest('a')).not.toBeNull();
});
- it('renders headerEndContent outside the button trigger in isWholeHeadingTrigger path', () => {
+ it('renders headerEndContent inside the button trigger in isWholeHeadingTrigger path', () => {
render(
<XDSSideNavHeading
heading="My App"
@@ -364,8 +364,8 @@ describe('XDSSideNavHeading headerEndContent', () => {
);
const badge = screen.getByTestId('end-badge');
expect(badge).toBeInTheDocument();
- // Badge should NOT be inside the button
- expect(badge.closest('button')).toBeNull();
+ // Badge renders inside the button trigger
+ expect(badge.closest('button')).not.toBeNull();
});
it('renders headerEndContent in mixed mode (menu + href)', () => {
diff --git a/packages/core/src/SideNav/XDSSideNav.tsx b/packages/core/src/SideNav/XDSSideNav.tsx
index 1628d0b3f0..45d79035d0 100644
--- a/packages/core/src/SideNav/XDSSideNav.tsx
+++ b/packages/core/src/SideNav/XDSSideNav.tsx
@@ -45,7 +45,7 @@ const styles = stylex.create({
overflow: 'hidden',
},
rootCollapsed: {
- width: 52,
+ width: spacingVars['--spacing-12'],
},
stickyTop: {
display: 'flex',
@@ -56,11 +56,12 @@ const styles = stylex.create({
zIndex: 1,
backgroundColor: 'inherit',
paddingBlockStart: spacingVars['--spacing-2'],
- paddingBlockEnd: spacingVars['--spacing-1'],
+ paddingBlockEnd: spacingVars['--spacing-2'],
paddingInline: spacingVars['--spacing-2'],
gap: spacingVars['--spacing-2'],
- overflow: 'hidden',
- minWidth: 0,
+ },
+ stickyTopCollapsed: {
+ alignItems: 'center',
},
topContent: {},
scrollable: {
@@ -69,6 +70,11 @@ const styles = stylex.create({
overflowX: 'hidden',
paddingInline: spacingVars['--spacing-2'],
},
+ scrollableCollapsed: {
+ display: 'flex',
+ flexDirection: 'column' as const,
+ alignItems: 'center',
+ },
scrollableNoTop: {
paddingBlockStart: spacingVars['--spacing-2'],
},
@@ -448,7 +454,11 @@ export function XDSSideNav({
)}
{...props}>
{hasStickyTop && (
- <div {...stylex.props(styles.stickyTop)}>
+ <div
+ {...stylex.props(
+ styles.stickyTop,
+ collapsed && styles.stickyTopCollapsed,
+ )}>
{header}
{topContent && (
<div {...stylex.props(styles.topContent)}>{topContent}</div>
@@ -458,6 +468,7 @@ export function XDSSideNav({
<div
{...stylex.props(
styles.scrollable,
+ collapsed && styles.scrollableCollapsed,
hasStickyTop ? styles.scrollableWithTop : styles.scrollableNoTop,
hasStickyBottom
? styles.scrollableWithBottom
diff --git a/packages/core/src/SideNav/XDSSideNavHeading.tsx b/packages/core/src/SideNav/XDSSideNavHeading.tsx
index b3b2cb5c68..a7cf974363 100644
--- a/packages/core/src/SideNav/XDSSideNavHeading.tsx
+++ b/packages/core/src/SideNav/XDSSideNavHeading.tsx
@@ -2,13 +2,12 @@
/**
* @file XDSSideNavHeading.tsx
- * @input Uses React, useRef, useCallback, ReactNode, StyleX, useXDSPopover, useTruncation
+ * @input Uses React, useRef, useCallback, ReactNode, StyleX, useXDSPopover
* @output Exports XDSSideNavHeading component and XDSSideNavHeadingProps
* @position Core implementation; used inside XDSSideNav header slot
*
* Product/suite/account heading with smart interaction boundary logic.
* Composes useXDSPopover internally when menu prop is provided.
- * Detects text truncation and shows tooltip on hover for overflowing text.
*
* SYNC: When modified, update these files to stay in sync:
* - /packages/core/src/SideNav/SideNav.doc.mjs
@@ -17,7 +16,7 @@
* - /apps/storybook/stories/SideNav.stories.tsx
*/
-import {lazy, Suspense, useCallback, useRef, type ReactNode} from 'react';
+import {useCallback, useRef, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {
@@ -34,15 +33,10 @@ import {useXDSPopover} from '../Popover/useXDSPopover';
import {XDSLink} from '../Link';
import {getIcon} from '../Icon/globalIconRegistry';
import {XDSTooltip} from '../Tooltip';
-import {useTruncation} from '../Text/useTruncation';
import {navItemStyles} from '../NavItem/navItemStyles.stylex';
import {useXDSSideNavCollapse} from './XDSSideNavCollapseContext';
import {xdsClassName, mergeProps} from '../utils';
-const LazyXDSTooltip = lazy(() =>
- import('../Tooltip/XDSTooltip').then(mod => ({default: mod.XDSTooltip})),
-);
-
// =============================================================================
// Styles
// =============================================================================
@@ -52,18 +46,15 @@ const styles = stylex.create({
display: 'flex',
alignItems: 'center',
gap: spacingVars['--spacing-2'],
- paddingInline: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-2'],
+ padding: 0,
boxSizing: 'border-box',
textDecoration: 'none',
color: 'inherit',
cursor: 'default',
- overflow: 'hidden',
- minWidth: 0,
},
rootCollapsed: {
justifyContent: 'center',
- paddingInline: spacingVars['--spacing-0-5'],
+ paddingInline: 0,
},
interactive: {
cursor: 'pointer',
@@ -73,6 +64,7 @@ const styles = stylex.create({
backgroundColor: 'transparent',
fontFamily: 'inherit',
fontSize: 'inherit',
+ fontWeight: fontWeightVars['--font-weight-normal'],
textAlign: 'start',
':hover': {
'@media (hover: hover)': {
@@ -80,6 +72,14 @@ const styles = stylex.create({
},
},
},
+ interactiveCollapsed: {
+ backgroundColor: {
+ default: 'transparent',
+ ':hover': {
+ '@media (hover: hover)': 'transparent',
+ },
+ },
+ },
icon: {
flexShrink: 0,
display: 'flex',
@@ -116,6 +116,7 @@ const styles = stylex.create({
// When super/sub headings are present, scale down the app name
headingCompact: {
fontSize: typeScaleVars['--text-label-size'],
+ fontWeight: fontWeightVars['--font-weight-semibold'],
},
subheading: {
fontSize: typeScaleVars['--text-supporting-size'],
@@ -139,17 +140,7 @@ const styles = stylex.create({
flexShrink: 0,
display: 'flex',
alignItems: 'center',
- },
- // Inner interactive element (link/button) when headerEndContent splits
- // the interactive boundary — stretches to fill remaining space so
- // headerEndContent hugs the trailing edge of the nav.
- interactiveInner: {
- display: 'flex',
- alignItems: 'center',
- flex: 1,
- minWidth: 0,
- padding: 0,
- gap: 'inherit',
+ marginInlineStart: 'auto',
},
popoverContent: {
padding: spacingVars['--spacing-1'],
@@ -196,6 +187,11 @@ export interface XDSSideNavHeadingProps {
* Link for the subheading.
*/
subheadingHref?: string;
+ /**
+ * Content rendered at the trailing edge of the heading row.
+ * Hidden in collapsed mode.
+ */
+ headerEndContent?: ReactNode;
/**
* Menu content shown in a popover. When provided, the header composes
* useXDSPopover internally and shows a dropdown chevron. The trigger
@@ -204,13 +200,6 @@ export interface XDSSideNavHeadingProps {
* - With hrefs → links are independent, chevron/remaining area is the trigger
*/
menu?: ReactNode;
- /**
- * Content rendered at the trailing edge of the heading row.
- * Useful for badges, status indicators, or compact action buttons.
- * Not part of the popover trigger or heading link — purely decorative/interactive.
- * Hidden when the sidebar is collapsed.
- */
- headerEndContent?: ReactNode;
/**
* StyleX styles created via `stylex.create()`. Merged with the component's
* base styles inside a single `stylex.props()` call for optimal deduplication.
@@ -282,8 +271,8 @@ export function XDSSideNavHeading({
superheadingHref,
subheading,
subheadingHref,
- menu,
headerEndContent,
+ menu,
xstyle,
className,
style,
@@ -295,45 +284,6 @@ export function XDSSideNavHeading({
const rootRef = useRef<HTMLDivElement>(null);
const collapsedItemRef = useRef<HTMLElement>(null);
- // Truncation detection for heading text elements
- const headingTruncation = useTruncation({maxLines: 1});
- const superheadingTruncation = useTruncation({maxLines: 1});
- const subheadingTruncation = useTruncation({maxLines: 1});
-
- // Refs for tooltip anchors
- const headingSpanRef = useRef<HTMLSpanElement>(null);
- const superheadingSpanRef = useRef<HTMLSpanElement>(null);
- const subheadingSpanRef = useRef<HTMLSpanElement>(null);
-
- // Merged ref callbacks for truncation + tooltip anchor
- const mergedHeadingRef = useCallback(
- (el: HTMLSpanElement | null) => {
- headingTruncation.ref(el);
- (
- headingSpanRef as React.MutableRefObject<HTMLSpanElement | null>
- ).current = el;
- },
- [headingTruncation.ref],
- );
- const mergedSuperheadingRef = useCallback(
- (el: HTMLSpanElement | null) => {
- superheadingTruncation.ref(el);
- (
- superheadingSpanRef as React.MutableRefObject<HTMLSpanElement | null>
- ).current = el;
- },
- [superheadingTruncation.ref],
- );
- const mergedSubheadingRef = useCallback(
- (el: HTMLSpanElement | null) => {
- subheadingTruncation.ref(el);
- (
- subheadingSpanRef as React.MutableRefObject<HTMLSpanElement | null>
- ).current = el;
- },
- [subheadingTruncation.ref],
- );
-
const popover = useXDSPopover({
dialogLabel: 'Navigation menu',
});
@@ -393,6 +343,36 @@ export function XDSSideNavHeading({
{collapsedIcon}
</a>
);
+ } else if (menu) {
+ collapsedElement = (
+ <>
+ <button
+ ref={collapsedSetRef as React.Ref<HTMLButtonElement>}
+ type="button"
+ onClick={handleToggle}
+ aria-label={heading}
+ data-testid={testId}
+ {...popover.triggerProps}
+ {...mergeProps(
+ xdsClassName('side-nav-heading'),
+ stylex.props(
+ navItemStyles.item,
+ styles.rootCollapsed,
+ styles.interactive,
+ styles.interactiveCollapsed,
+ xstyle,
+ ),
+ className,
+ style,
+ )}>
+ {collapsedIcon}
+ </button>
+ {popover.render(
+ <div {...stylex.props(styles.popoverContent)}>{menu}</div>,
+ {placement: 'below', alignment: 'start', xstyle: styles.popover},
+ )}
+ </>
+ );
} else {
collapsedElement = (
<div
@@ -431,30 +411,6 @@ export function XDSSideNavHeading({
const isWholeHeadingLink =
!!headingHref && !menu && !superheadingHref && !subheadingHref;
- // Render truncation tooltips for text spans (only in expanded mode)
- const renderTruncationTooltips = () => (
- <>
- {superheadingTruncation.isTruncated && (
- <Suspense fallback={null}>
- <LazyXDSTooltip
- content={superheading!}
- anchorRef={superheadingSpanRef}
- />
- </Suspense>
- )}
- {headingTruncation.isTruncated && (
- <Suspense fallback={null}>
- <LazyXDSTooltip content={heading} anchorRef={headingSpanRef} />
- </Suspense>
- )}
- {subheadingTruncation.isTruncated && (
- <Suspense fallback={null}>
- <LazyXDSTooltip content={subheading!} anchorRef={subheadingSpanRef} />
- </Suspense>
- )}
- </>
- );
-
// Render text content
const renderTextContent = () => (
<span {...stylex.props(styles.textContainer)}>
@@ -468,11 +424,7 @@ export function XDSSideNavHeading({
{superheading}
</XDSLink>
) : (
- <span
- ref={mergedSuperheadingRef}
- {...stylex.props(styles.superheading)}>
- {superheading}
- </span>
+ <span {...stylex.props(styles.superheading)}>{superheading}</span>
))}
{hasAnyHref && headingHref && menu ? (
<XDSLink
@@ -484,7 +436,6 @@ export function XDSSideNavHeading({
</XDSLink>
) : (
<span
- ref={mergedHeadingRef}
{...stylex.props(
styles.heading,
hasCompactHeading && styles.headingCompact,
@@ -502,9 +453,7 @@ export function XDSSideNavHeading({
{subheading}
</XDSLink>
) : (
- <span ref={mergedSubheadingRef} {...stylex.props(styles.subheading)}>
- {subheading}
- </span>
+ <span {...stylex.props(styles.subheading)}>{subheading}</span>
))}
</span>
);
@@ -519,97 +468,28 @@ export function XDSSideNavHeading({
// Whole heading is a link (no menu, single headingHref)
if (isWholeHeadingLink) {
- // When headerEndContent is provided, render it outside the link
- if (headerEndContent) {
- return (
- <>
- <div
- ref={ref}
- data-testid={testId}
- {...mergeProps(
- xdsClassName('side-nav-heading'),
- stylex.props(styles.root, xstyle),
- className,
- style,
- )}>
- <a
- href={headingHref}
- {...stylex.props(
- styles.root,
- styles.interactive,
- styles.interactiveInner,
- )}
- {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}>
- {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
- {renderTextContent()}
- </a>
- {headerEndContentElement}
- {chevronElement}
- </div>
- {renderTruncationTooltips()}
- </>
- );
- }
return (
- <>
- <a
- ref={ref as React.Ref<HTMLAnchorElement>}
- href={headingHref}
- data-testid={testId}
- {...mergeProps(
- xdsClassName('side-nav-heading'),
- stylex.props(styles.root, styles.interactive, xstyle),
- className,
- style,
- )}
- {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}>
- {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
- {renderTextContent()}
- {chevronElement}
- </a>
- {renderTruncationTooltips()}
- </>
+ <a
+ ref={ref as React.Ref<HTMLAnchorElement>}
+ href={headingHref}
+ data-testid={testId}
+ {...mergeProps(
+ xdsClassName('side-nav-heading'),
+ stylex.props(styles.root, styles.interactive, xstyle),
+ className,
+ style,
+ )}
+ {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}>
+ {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
+ {renderTextContent()}
+ {headerEndContentElement}
+ {chevronElement}
+ </a>
);
}
// Whole header is the popover trigger (menu, no hrefs)
if (isWholeHeadingTrigger) {
- // When headerEndContent is provided, render it outside the button trigger
- if (headerEndContent) {
- return (
- <>
- <div
- data-testid={testId}
- {...mergeProps(
- xdsClassName('side-nav-heading'),
- stylex.props(styles.root, xstyle),
- className,
- style,
- )}>
- <button
- ref={setRef as React.Ref<HTMLButtonElement>}
- type="button"
- onClick={handleToggle}
- {...popover.triggerProps}
- {...stylex.props(
- styles.root,
- styles.interactive,
- styles.interactiveInner,
- )}>
- {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
- {renderTextContent()}
- {chevronElement}
- </button>
- {headerEndContentElement}
- </div>
- {renderTruncationTooltips()}
- {popover.render(
- <div {...stylex.props(styles.popoverContent)}>{menu}</div>,
- {placement: 'below', alignment: 'start', xstyle: styles.popover},
- )}
- </>
- );
- }
return (
<>
<button
@@ -626,9 +506,9 @@ export function XDSSideNavHeading({
)}>
{icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
{renderTextContent()}
+ {headerEndContentElement}
{chevronElement}
</button>
- {renderTruncationTooltips()}
{popover.render(
<div {...stylex.props(styles.popoverContent)}>{menu}</div>,
{placement: 'below', alignment: 'start', xstyle: styles.popover},
@@ -673,7 +553,6 @@ export function XDSSideNavHeading({
</button>
)}
</div>
- {renderTruncationTooltips()}
{popover.render(
<div {...stylex.props(styles.popoverContent)}>{menu}</div>,
{placement: 'below', alignment: 'start', xstyle: styles.popover},
@@ -685,88 +564,6 @@ export function XDSSideNavHeading({
// Static heading with independent links (no menu)
if (hasAnyHref && !isWholeHeadingLink) {
return (
- <>
- <div
- ref={ref}
- data-testid={testId}
- {...mergeProps(
- xdsClassName('side-nav-heading'),
- stylex.props(styles.root, xstyle),
- className,
- style,
- )}
- {...props}>
- {icon &&
- (headingHref ? (
- <a href={headingHref} {...stylex.props(styles.icon)}>
- {icon}
- </a>
- ) : (
- <span {...stylex.props(styles.icon)}>{icon}</span>
- ))}
- <span {...stylex.props(styles.textContainer)}>
- {superheading &&
- (superheadingHref ? (
- <XDSLink
- label={superheading}
- href={superheadingHref}
- color="secondary"
- size="xsm">
- {superheading}
- </XDSLink>
- ) : (
- <span
- ref={mergedSuperheadingRef}
- {...stylex.props(styles.superheading)}>
- {superheading}
- </span>
- ))}
- {headingHref ? (
- <XDSLink
- label={heading}
- href={headingHref}
- color="primary"
- weight="semibold">
- {heading}
- </XDSLink>
- ) : (
- <span
- ref={mergedHeadingRef}
- {...stylex.props(
- styles.heading,
- hasCompactHeading && styles.headingCompact,
- )}>
- {heading}
- </span>
- )}
- {subheading &&
- (subheadingHref ? (
- <XDSLink
- label={subheading}
- href={subheadingHref}
- color="secondary"
- size="xsm">
- {subheading}
- </XDSLink>
- ) : (
- <span
- ref={mergedSubheadingRef}
- {...stylex.props(styles.subheading)}>
- {subheading}
- </span>
- ))}
- </span>
- {headerEndContentElement}
- {chevronElement}
- </div>
- {renderTruncationTooltips()}
- </>
- );
- }
-
- // Default: static heading, no links, no menu
- return (
- <>
<div
ref={ref}
data-testid={testId}
@@ -777,13 +574,80 @@ export function XDSSideNavHeading({
style,
)}
{...props}>
- {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
- {renderTextContent()}
+ {icon &&
+ (headingHref ? (
+ <a href={headingHref} {...stylex.props(styles.icon)}>
+ {icon}
+ </a>
+ ) : (
+ <span {...stylex.props(styles.icon)}>{icon}</span>
+ ))}
+ <span {...stylex.props(styles.textContainer)}>
+ {superheading &&
+ (superheadingHref ? (
+ <XDSLink
+ label={superheading}
+ href={superheadingHref}
+ color="secondary"
+ size="xsm">
+ {superheading}
+ </XDSLink>
+ ) : (
+ <span {...stylex.props(styles.superheading)}>{superheading}</span>
+ ))}
+ {headingHref ? (
+ <XDSLink
+ label={heading}
+ href={headingHref}
+ color="primary"
+ weight="semibold">
+ {heading}
+ </XDSLink>
+ ) : (
+ <span
+ {...stylex.props(
+ styles.heading,
+ hasCompactHeading && styles.headingCompact,
+ )}>
+ {heading}
+ </span>
+ )}
+ {subheading &&
+ (subheadingHref ? (
+ <XDSLink
+ label={subheading}
+ href={subheadingHref}
+ color="secondary"
+ size="xsm">
+ {subheading}
+ </XDSLink>
+ ) : (
+ <span {...stylex.props(styles.subheading)}>{subheading}</span>
+ ))}
+ </span>
{headerEndContentElement}
{chevronElement}
</div>
- {renderTruncationTooltips()}
- </>
+ );
+ }
+
+ // Default: static heading, no links, no menu
+ return (
+ <div
+ ref={ref}
+ data-testid={testId}
+ {...mergeProps(
+ xdsClassName('side-nav-heading'),
+ stylex.props(styles.root, xstyle),
+ className,
+ style,
+ )}
+ {...props}>
+ {icon && <span {...stylex.props(styles.icon)}>{icon}</span>}
+ {renderTextContent()}
+ {headerEndContentElement}
+ {chevronElement}
+ </div>
);
}
diff --git a/packages/core/src/SideNav/XDSSideNavItem.tsx b/packages/core/src/SideNav/XDSSideNavItem.tsx
index af8c56995f..2befb3ac09 100644
--- a/packages/core/src/SideNav/XDSSideNavItem.tsx
+++ b/packages/core/src/SideNav/XDSSideNavItem.tsx
@@ -20,6 +20,7 @@ import * as stylex from '@stylexjs/stylex';
import {
colorVars,
spacingVars,
+ sizeVars,
fontWeightVars,
typeScaleVars,
durationVars,
@@ -33,7 +34,7 @@ import type {XDSLinkComponentType} from '../Link/types';
import {useXDSPopover} from '../Popover/useXDSPopover';
import {xdsClassName, mergeProps} from '../utils';
import {XDSTooltip} from '../Tooltip';
-import {navItemStyles} from '../NavItem/navItemStyles.stylex';
+import {navItemStyles, type NavItemSize} from '../NavItem/navItemStyles.stylex';
import {
useXDSSideNavCollapse,
XDSSideNavCollapseContext,
@@ -52,8 +53,11 @@ const styles = stylex.create({
},
itemCollapsed: {
justifyContent: 'center',
- paddingInline: spacingVars['--spacing-1'],
+ width: sizeVars['--size-element-md'],
+ paddingInline: 0,
},
+ itemCollapsedSm: {width: sizeVars['--size-element-sm']},
+ itemCollapsedLg: {width: sizeVars['--size-element-lg']},
label: {
flex: 1,
minWidth: 0,
@@ -92,7 +96,7 @@ const styles = stylex.create({
transitionTimingFunction: easeVars['--ease-standard'],
flexShrink: 0,
},
- expandChevronCollapsed: {
+ expandChevronExpanded: {
transform: 'rotate(180deg)',
},
// Popover surface for collapsed items with children
@@ -191,6 +195,11 @@ export interface XDSSideNavItemProps {
isCollapsed?: boolean;
onCollapsedChange?: (isCollapsed: boolean) => void;
};
+ /**
+ * Size variant for the nav item.
+ * @default 'md'
+ */
+ size?: NavItemSize;
/**
* Test ID for the item element.
*/
@@ -233,6 +242,7 @@ export function XDSSideNavItem({
endContent,
children,
collapsible: itemCollapsible,
+ size = 'md',
'data-testid': testId,
ref,
}: XDSSideNavItemProps) {
@@ -345,7 +355,10 @@ export function XDSSideNavItem({
xdsClassName('side-nav-item'),
stylex.props(
navItemStyles.item,
+ navItemStyles[size],
styles.itemCollapsed,
+ size === 'sm' && styles.itemCollapsedSm,
+ size === 'lg' && styles.itemCollapsedLg,
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
),
@@ -447,7 +460,7 @@ export function XDSSideNavItem({
<span
{...stylex.props(
styles.expandChevron,
- isItemCollapsed && styles.expandChevronCollapsed,
+ !isItemCollapsed && styles.expandChevronExpanded,
)}>
{getIcon('chevronDown')}
</span>
@@ -474,6 +487,7 @@ export function XDSSideNavItem({
xdsClassName('side-nav-item'),
stylex.props(
navItemStyles.item,
+ navItemStyles[size],
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
),
@@ -491,6 +505,7 @@ export function XDSSideNavItem({
xdsClassName('side-nav-item'),
stylex.props(
navItemStyles.item,
+ navItemStyles[size],
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
),
diff --git a/packages/core/src/TopNav/XDSTopNav.tsx b/packages/core/src/TopNav/XDSTopNav.tsx
index b7e20181bd..c7007c8244 100644
--- a/packages/core/src/TopNav/XDSTopNav.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.tsx
@@ -13,7 +13,6 @@
* - /apps/storybook/stories/TopNav.stories.tsx
*/
-
import {type ReactNode} from 'react';
import type {XDSBaseProps} from '../XDSBaseProps';
import * as stylex from '@stylexjs/stylex';
@@ -34,13 +33,10 @@ const styles = stylex.create({
base: {
alignItems: 'center',
width: '100%',
- height: spacingVars['--spacing-12'],
- paddingInline: spacingVars['--spacing-4'],
+ padding: spacingVars['--spacing-2'],
boxSizing: 'border-box',
// Publish inline padding for edge compensation (ghost buttons at edges).
- // Uses --container-padding-inline (not --container-padding) because TopNav
- // has no block padding (fixed height) — the isotropic variable would be misleading.
- '--container-padding-inline': spacingVars['--spacing-4'],
+ '--container-padding-inline': spacingVars['--spacing-2'],
},
// Flex layout (default, used when no centerContent)
baseFlex: {
@@ -92,8 +88,7 @@ const styles = stylex.create({
display: 'flex',
alignItems: 'center',
width: '100%',
- height: spacingVars['--spacing-12'],
- paddingInline: spacingVars['--spacing-4'],
+ padding: spacingVars['--spacing-2'],
boxSizing: 'border-box',
},
mobileBarEnd: {
diff --git a/packages/core/src/TopNav/XDSTopNavItem.tsx b/packages/core/src/TopNav/XDSTopNavItem.tsx
index 723d56bd98..c3dcf930ed 100644
--- a/packages/core/src/TopNav/XDSTopNavItem.tsx
+++ b/packages/core/src/TopNav/XDSTopNavItem.tsx
@@ -28,7 +28,7 @@ import {
import {useXDSLinkComponent} from '../Link/useXDSLinkComponent';
import type {XDSLinkComponentType} from '../Link/types';
import {useXDSTopNavRenderMode} from './XDSTopNavRenderContext';
-import {navItemStyles} from '../NavItem/navItemStyles.stylex';
+import {navItemStyles, type NavItemSize} from '../NavItem/navItemStyles.stylex';
import {xdsClassName, mergeProps} from '../utils';
/**
@@ -39,7 +39,7 @@ const styles = stylex.create({
display: 'inline-flex',
alignItems: 'center',
gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-2'],
+ paddingBlock: spacingVars['--spacing-1-5'],
paddingInline: spacingVars['--spacing-3'],
borderRadius: radiusVars['--radius-element'],
fontSize: typeScaleVars['--text-label-size'],
@@ -138,6 +138,12 @@ export interface XDSTopNavItemProps extends XDSBaseProps<HTMLAnchorElement> {
* If omitted and icon is provided, item becomes icon-only.
*/
children?: ReactNode;
+ /**
+ * Size variant for the nav item. Has no effect in horizontal mode;
+ * controls height/padding in drawer mode.
+ * @default 'md'
+ */
+ size?: NavItemSize;
}
/**
@@ -166,6 +172,7 @@ export function XDSTopNavItem({
isDisabled = false,
icon,
children,
+ size = 'md',
xstyle,
className,
style,
@@ -191,6 +198,7 @@ export function XDSTopNavItem({
xdsClassName('top-nav-item', {mode: 'drawer'}),
stylex.props(
navItemStyles.item,
+ navItemStyles[size],
styles.drawerFocus,
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
diff --git a/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx b/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx
index cb72f08cb1..9c96d6cc4e 100644
--- a/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx
+++ b/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx
@@ -50,7 +50,7 @@ const styles = stylex.create({
display: 'inline-flex',
alignItems: 'center',
gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-2'],
+ paddingBlock: spacingVars['--spacing-1-5'],
paddingInline: spacingVars['--spacing-3'],
borderRadius: radiusVars['--radius-element'],
fontSize: typeScaleVars['--text-label-size'],
diff --git a/packages/core/src/TopNav/XDSTopNavMenu.tsx b/packages/core/src/TopNav/XDSTopNavMenu.tsx
index fa5a1dfc6b..b8c9e5a82d 100644
--- a/packages/core/src/TopNav/XDSTopNavMenu.tsx
+++ b/packages/core/src/TopNav/XDSTopNavMenu.tsx
@@ -47,7 +47,7 @@ const styles = stylex.create({
display: 'inline-flex',
alignItems: 'center',
gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-2'],
+ paddingBlock: spacingVars['--spacing-1-5'],
paddingInline: spacingVars['--spacing-3'],
borderRadius: radiusVars['--radius-element'],
fontSize: typeScaleVars['--text-label-size'],