@nswds/ui 5.0.3 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { Link } from './link.js';
6
6
 
7
7
  declare const badgeVariants: (props?: ({
8
8
  variant?: "solid" | "soft" | "surface" | "outline" | null | undefined;
9
- color?: "primary/grey" | "light" | "primary/white" | "white" | "grey" | "primary" | "secondary" | "tertiary" | "accent" | null | undefined;
9
+ color?: "white" | "grey" | "primary" | "secondary" | "tertiary" | "accent" | "primary/grey" | "light" | "primary/white" | null | undefined;
10
10
  size?: "default" | "sm" | "lg" | null | undefined;
11
11
  } & class_variance_authority_types.ClassProp) | undefined) => string;
12
12
  type BadgeProps = VariantProps<typeof badgeVariants> & React__default.ComponentPropsWithoutRef<'span'> & {
@@ -5,7 +5,7 @@ import React__default from 'react';
5
5
  import { Link } from './link.js';
6
6
 
7
7
  declare const buttonVariants: (props?: ({
8
- variant?: "solid" | "soft" | "surface" | "outline" | "link" | "ghost" | null | undefined;
8
+ variant?: "solid" | "soft" | "surface" | "outline" | "ghost" | "link" | null | undefined;
9
9
  color?: "white" | "grey" | "primary" | "secondary" | "tertiary" | "accent" | "danger" | "success" | "warning" | null | undefined;
10
10
  size?: "default" | "sm" | "lg" | "icon" | null | undefined;
11
11
  iconOnly?: boolean | null | undefined;
@@ -30,7 +30,7 @@ declare const headerColors: {
30
30
  };
31
31
  type HeaderColor = keyof typeof headerColors;
32
32
  declare const headerVariants: (props?: ({
33
- color?: "light" | "white" | "grey" | "dark" | null | undefined;
33
+ color?: "white" | "grey" | "light" | "dark" | null | undefined;
34
34
  } & class_variance_authority_types.ClassProp) | undefined) => string;
35
35
  declare const headerContainerVariants: (props?: ({
36
36
  container?: "fluid" | "contained" | null | undefined;
@@ -3,7 +3,7 @@ import { VariantProps } from 'class-variance-authority';
3
3
  import React__default from 'react';
4
4
 
5
5
  declare const mastheadVariants: (props?: ({
6
- color?: "light" | "white" | "grey" | "dark" | null | undefined;
6
+ color?: "white" | "grey" | "light" | "dark" | null | undefined;
7
7
  } & class_variance_authority_types.ClassProp) | undefined) => string;
8
8
  declare const mastheadContainerVariants: (props?: ({
9
9
  container?: "fluid" | "contained" | null | undefined;
@@ -42,6 +42,13 @@ type PushMenuLevel = {
42
42
  * app can render the same trail outside the menu (e.g. in a sheet header).
43
43
  * Prefixed with "PushMenu" to avoid colliding with a future breadcrumb
44
44
  * component in the package barrel.
45
+ *
46
+ * `maxLength` is a HARD bound on the returned string, measured in UTF-16 units
47
+ * (`String.length`) — the one exception is a single level, whose title is
48
+ * returned verbatim because there is nothing to collapse. Callers rendering the
49
+ * trail in a fixed-width slot can rely on that. Middle-elision is attempted
50
+ * first because it reads better; when it does not fit, the full trail is
51
+ * truncated from the end.
45
52
  */
46
53
  declare function generatePushMenuBreadcrumb(levels: {
47
54
  title: string;
@@ -12,6 +12,20 @@ const PUSH_MENU_DURATION_MS = 300;
12
12
  function buildLevelId(path) {
13
13
  return `level-${path.length > 0 ? path.join("--") : "root"}`;
14
14
  }
15
+ function truncateWithEllipsis(value, maxLength) {
16
+ if (maxLength < 1) {
17
+ return "";
18
+ }
19
+ const budget = maxLength - 1;
20
+ let out = "";
21
+ for (const codePoint of value) {
22
+ if (out.length + codePoint.length > budget) {
23
+ break;
24
+ }
25
+ out += codePoint;
26
+ }
27
+ return `${out}\u2026`;
28
+ }
15
29
  function generatePushMenuBreadcrumb(levels, maxLength = 50) {
16
30
  const first = levels[0];
17
31
  if (levels.length <= 1) {
@@ -24,9 +38,12 @@ function generatePushMenuBreadcrumb(levels, maxLength = 50) {
24
38
  const last = levels.at(-1);
25
39
  const secondLast = levels.at(-2);
26
40
  if (levels.length > 3 && first && last && secondLast) {
27
- return `${first.title} \u203A \u2026 \u203A ${secondLast.title} \u203A ${last.title}`;
41
+ const elided = `${first.title} \u203A \u2026 \u203A ${secondLast.title} \u203A ${last.title}`;
42
+ if (elided.length <= maxLength) {
43
+ return elided;
44
+ }
28
45
  }
29
- return `${full.slice(0, maxLength - 1)}\u2026`;
46
+ return truncateWithEllipsis(full, maxLength);
30
47
  }
31
48
  function warnIfNavigationMalformed(navigation) {
32
49
  if (process.env.NODE_ENV === "production") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/push-menu.tsx"],"names":[],"mappings":";;;;;;;;;AA0BA,MAAM,qBAAA,GAAwB;AA2B9B,SAAS,aAAa,IAAA,EAAwB;AAC5C,EAAA,OAAO,CAAA,MAAA,EAAS,KAAK,MAAA,GAAS,CAAA,GAAI,KAAK,IAAA,CAAK,IAAI,IAAI,MAAM,CAAA,CAAA;AAC5D;AASA,SAAS,0BAAA,CAA2B,MAAA,EAA6B,SAAA,GAAY,EAAA,EAAY;AACvF,EAAA,MAAM,KAAA,GAAQ,OAAO,CAAC,CAAA;AACtB,EAAA,IAAI,MAAA,CAAO,UAAU,CAAA,EAAG;AACtB,IAAA,OAAO,OAAO,KAAA,IAAS,MAAA;AAAA,EACzB;AAEA,EAAA,MAAM,IAAA,GAAO,OAAO,GAAA,CAAI,CAAC,UAAU,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,UAAK,CAAA;AAC1D,EAAA,IAAI,IAAA,CAAK,UAAU,SAAA,EAAW;AAC5B,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,EAAA,CAAG,EAAE,CAAA;AACzB,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,EAAA,CAAG,EAAE,CAAA;AAC/B,EAAA,IAAI,MAAA,CAAO,MAAA,GAAS,CAAA,IAAK,KAAA,IAAS,QAAQ,UAAA,EAAY;AACpD,IAAA,OAAO,CAAA,EAAG,MAAM,KAAK,CAAA,sBAAA,EAAU,WAAW,KAAK,CAAA,QAAA,EAAM,KAAK,KAAK,CAAA,CAAA;AAAA,EACjE;AAEA,EAAA,OAAO,GAAG,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,SAAA,GAA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AA,EAAU,gBAAA;AAAA,sBACV,gBAAc,IAAA,CAAK,EAAA;AAAA,sBACnB,OAAA,EAAS,MAAM,WAAA,GAAc,IAAI,CAAA;AAAA,sBACjC,SAAA,EAAW,EAAA;AAAA,wBACT,iBAAA;AAAA,wBACA,qBAAA;AAAA,wBACA,WAAA,IAAe;AAAA,uBACjB;AAAA,sBAEA,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yBAAA,EAA2B,eAAK,KAAA,EAAM;AAAA;AAAA,mBACxD,EAAA,EA7CK,KAAK,EA+Cd,CAAA;AAAA,gBAEJ,CAAC,GACH,CAAA,EACF;AAAA;AAAA,aAAA;AAAA,YA7HK,KAAA,CAAM;AAAA,WA8Hb;AAAA,QAEJ,CAAC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"push-menu.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\nimport { IconClose } from '../icons/close.js'\nimport { IconWest } from '../icons/west.js'\n\n/**\n * Default slide duration for level transitions, in milliseconds — the default\n * of the `durationMs` prop.\n *\n * COUPLING: `durationMs` drives BOTH the `--push-menu-duration` custom\n * property (set inline on the root, read by the CSS transition) and the state\n * machine's `setTimeout`s (which settle the animation state, pop levels, and\n * schedule focus restoration). Do not override the custom property directly —\n * that changes only the visual duration while the state machine still settles\n * on `durationMs`, desyncing the two; pass `durationMs` instead. Under\n * `prefers-reduced-motion` the slide is skipped (the transition is applied\n * under `motion-safe:` only) but the state machine still waits the full\n * duration; the menu is simply \"settled early\" for those users, never broken.\n */\nconst PUSH_MENU_DURATION_MS = 300\n\n/** A node in the menu tree. Items with `links` drill in; items with `href` navigate. */\ntype PushMenuItem = {\n /** Unique across the whole tree — level ids and focus restoration track items by id. */\n id: string\n /** Visible label. */\n title: string\n /** Navigation target for leaf items. Ignored for drilling when `links` is non-empty. */\n href?: string\n /** Child items. A non-empty array makes this item a drill-in button, not a link. */\n links?: PushMenuItem[]\n}\n\n/** One entry in the level stack — the root level plus one per drill-in. */\ntype PushMenuLevel = {\n id: string\n title: string\n /** 1 for the root level, incrementing per drill-in. */\n depth: number\n items: PushMenuItem[]\n /** The item whose activation opened this level. Absent on the root level. */\n parentItem?: PushMenuItem\n}\n\ntype PushMenuAnimationState = 'idle' | 'sliding-forward' | 'sliding-backward'\n\nfunction buildLevelId(path: string[]): string {\n return `level-${path.length > 0 ? path.join('--') : 'root'}`\n}\n\n/**\n * Collapses a trail of level titles into a single \"A › B › C\" string, keeping\n * the ends and eliding the middle once it outgrows `maxLength`. Exported so an\n * app can render the same trail outside the menu (e.g. in a sheet header).\n * Prefixed with \"PushMenu\" to avoid colliding with a future breadcrumb\n * component in the package barrel.\n */\nfunction generatePushMenuBreadcrumb(levels: { title: string }[], maxLength = 50): string {\n const first = levels[0]\n if (levels.length <= 1) {\n return first?.title ?? 'Menu'\n }\n\n const full = levels.map((level) => level.title).join(' › ')\n if (full.length <= maxLength) {\n return full\n }\n\n const last = levels.at(-1)\n const secondLast = levels.at(-2)\n if (levels.length > 3 && first && last && secondLast) {\n return `${first.title} › … › ${secondLast.title} › ${last.title}`\n }\n\n return `${full.slice(0, maxLength - 1)}…`\n}\n\n/**\n * Dev-only guard, mirroring `warnIfIconButtonUnlabelled` in button.tsx. It\n * replaces the nswds-app source's rendered \"Navigation Error\" fallback panel:\n * malformed navigation data is a programming error, not a runtime state a user\n * should ever see, so the design system surfaces it to the developer console\n * and renders what it can instead of shipping error chrome. No-op in\n * production.\n */\nfunction warnIfNavigationMalformed(navigation: PushMenuItem[]) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!Array.isArray(navigation) || navigation.length === 0) {\n console.warn('[nswds/ui] PushMenu received no navigation items — the menu renders empty.')\n return\n }\n const seen = new Set<string>()\n const visit = (items: PushMenuItem[]) => {\n for (const item of items) {\n if (!item?.id || !item.title) {\n console.warn('[nswds/ui] PushMenu navigation item is missing an `id` or `title`:', item)\n continue\n }\n if (seen.has(item.id)) {\n console.warn(\n `[nswds/ui] PushMenu navigation contains duplicate id \"${item.id}\" — level ids and focus restoration track items by id, so ids must be unique across the whole tree.`,\n )\n }\n seen.add(item.id)\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] PushMenu item \"${item.id}\" has neither an href nor children — it renders as a button that only fires onItemClick.`,\n )\n }\n if (item.links?.length) {\n visit(item.links)\n }\n }\n }\n visit(navigation)\n}\n\n// One treatment for every row — drill-in buttons and leaf links alike — so the\n// two read as a single list. Tokenized from the nswds-app source's\n// border-l + primary-800 active pattern, with dark-mode equivalents the app\n// lacked (its grey-800-on-white text disappeared in dark mode).\nconst itemBaseClassName = [\n // min-h-11 guarantees the 44px minimum target size (WCAG 2.2, 2.5.8 Target\n // Size) even for single-line rows with compact padding overrides.\n 'relative flex min-h-11 w-full cursor-pointer items-center justify-between gap-x-6 border-l p-4 text-left text-base',\n 'motion-safe:transition-colors',\n 'hover:border-primary-800 hover:bg-primary-800/10 dark:hover:border-primary-200 dark:hover:bg-primary-200/10',\n // Inset outline (negative offset): the levels scroll inside an\n // overflow-hidden root, so an outward offset would be clipped on the first\n // and last rows (WCAG 2.2, 2.4.13 Focus Appearance).\n 'focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary-800 dark:focus-visible:outline-primary-200',\n].join(' ')\n\nconst itemActiveClassName =\n 'border-primary-800 bg-primary-800/10 font-semibold text-primary-800 dark:border-primary-200 dark:bg-primary-200/10 dark:text-primary-200'\n\nconst itemInactiveClassName = 'border-transparent text-popover-foreground'\n\ntype PushMenuProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children' | 'title'> & {\n /** The menu tree. Item ids must be unique across the whole tree. */\n navigation: PushMenuItem[]\n /**\n * The app's current pathname. Leaf links whose `href` matches get\n * `aria-current=\"page\"` and the active treatment. Replaces the nswds-app\n * source's `usePathname()` — the design system is framework-free, so the\n * router value is passed in rather than read from next/navigation.\n */\n currentHref?: string\n /** Root level title, shown in the header row. Also the default `aria-label`. */\n title?: string\n /** Fired when a leaf item (link or child-less button) is activated. */\n onItemClick?: (item: PushMenuItem) => void\n /** Fired after a forward/back slide settles on a level. */\n onNavigate?: (level: PushMenuLevel, history: PushMenuLevel[]) => void\n /**\n * Renders a close button in the header row when provided. Unlike the\n * nswds-app source — which only offered close on sub-levels, leaving the\n * root level uncloseable — the button renders on every level.\n */\n onClose?: () => void\n /** Show the \"A › B › C\" trail under the header on sub-levels. Defaults to `true`. */\n showBreadcrumbs?: boolean\n /**\n * Slide duration in milliseconds, defaulting to `PUSH_MENU_DURATION_MS`\n * (300). Drives both the `--push-menu-duration` custom property and the\n * state machine's timeouts — tune the slide here, never by overriding the\n * custom property (see the coupling note on the constant).\n */\n durationMs?: number\n /** Label for the Back button on sub-levels. Defaults to `'Back'`. */\n backLabel?: string\n /** Accessible label for the close button. Defaults to `'Close menu'`. */\n closeLabel?: string\n /**\n * Heading level for the per-level title, following `FooterNavColumn`'s\n * precedent (the nswds-app source used a `Heading` component this package\n * does not ship). Defaults to `2`; `1` is excluded because a menu panel\n * title is never the page's own title.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Multi-level slide-in-place drill-down menu (\"push menu\") for mobile\n * navigation, ported from nswds-app's `MultiLevelPushMenu`. Items with\n * children render as buttons that slide a new level in from the right; leaf\n * items render as links through `Link`, so apps can inject their framework\n * link component via `LinkProvider`. Fill height from its container — compose\n * it inside `SheetContent side=\"left\"` for the classic mobile drawer.\n *\n * Accessibility contract (all improvements over the nswds-app source, which\n * got several of these wrong):\n *\n * - The root is a `nav` landmark named by `title` (override with `aria-label`).\n * - Non-current levels carry the `inert` attribute, so a hidden level's links\n * are neither tabbable nor exposed to assistive tech. The app left every\n * mounted level in the tab order, letting keyboard users tab into invisible\n * history levels (WCAG 2.2, 2.4.3 Focus Order).\n * - Focus moves with the level change (2.4.3): drilling forward focuses the\n * new level's Back button; going back focuses the item that opened the\n * level just left, tracked by item id and restored after the slide settles.\n * Without this, `inert` on the old level would silently drop focus to\n * `<body>`. The Back button is the only route back (the breadcrumb is\n * decorative), so it always renders on sub-levels — hiding it would make\n * drill-down one-way.\n * - A single visually-hidden `aria-live=\"polite\"` region at the root announces\n * the current level's title, suffixed with the level number below the root.\n * A live attribute on the per-level headings would not work: each level's\n * heading is freshly mounted, and newly-mounted live regions are not\n * reliably announced.\n * - Level lists are `<ul role=\"list\">` — `list-style: none` strips list\n * semantics in some screen reader/browser pairings (notably VoiceOver), and\n * the explicit role restores them.\n * - Every row is at least 44px tall (2.5.8 Target Size); Back/close buttons\n * inherit `Button`'s 44px touch target.\n * - During the slide, rows get `pointer-events-none` and the state machine\n * ignores re-entrant navigation, but nothing is ever `disabled` — disabling\n * the focused Back button mid-animation would eject keyboard focus.\n * - Slides are CSS transforms applied under `motion-safe:`, replacing the app's\n * inline transition strings (which ignored reduced motion).\n *\n * Departures from the nswds-app source, beyond the above:\n *\n * - The footer/stats block (Level N, item counts, progress dots, lucide\n * icons) is cut, along with its `showStats`/`showFooter` props: it was demo\n * chrome for the sandbox, not part of a navigation component's job. The\n * breadcrumb trail it hosted moves under the header row.\n * - The rendered \"Navigation Error\" fallback for malformed data is replaced\n * by a dev-only console warning (`warnIfNavigationMalformed`), mirroring\n * button.tsx's `warnIfIconButtonUnlabelled`.\n * - The breadcrumb trail is `aria-hidden`: it repeats what the heading and\n * live region already announce, and \"›\" separators read poorly in AT.\n *\n * The level stack is seeded from `navigation`/`title` on mount; pass a `key`\n * to remount (and reset to the root level) if either changes at runtime.\n */\nfunction PushMenu({\n navigation,\n currentHref,\n title = 'Menu',\n onItemClick,\n onNavigate,\n onClose,\n showBreadcrumbs = true,\n durationMs = PUSH_MENU_DURATION_MS,\n backLabel = 'Back',\n closeLabel = 'Close menu',\n headingLevel = 2,\n className,\n style,\n 'aria-label': ariaLabel,\n ref,\n ...props\n}: PushMenuProps) {\n const [navigationHistory, setNavigationHistory] = React.useState<PushMenuLevel[]>(() => [\n { items: navigation, title, depth: 1, id: buildLevelId([]) },\n ])\n const [animationState, setAnimationState] = React.useState<PushMenuAnimationState>('idle')\n const [isAnimationStarted, setIsAnimationStarted] = React.useState(false)\n\n const containerRef = React.useRef<HTMLElement | null>(null)\n const timeoutRef = React.useRef<number | null>(null)\n // Focus target applied by the effect below, after React commits the level\n // change — the target element must exist and must no longer be inert.\n const pendingFocusRef = React.useRef<{ levelId: string; itemId?: string } | null>(null)\n\n warnIfNavigationMalformed(navigation)\n\n React.useEffect(() => {\n return () => {\n if (timeoutRef.current !== null) {\n window.clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n // Layout effect, not a passive one: the same commit that queues a focus\n // move can also flip the previously-focused element inert (drilling turns\n // the old level inert; going back turns the departing level inert), and the\n // browser blurs an element the moment it becomes inert. Applying the new\n // focus before paint means AT never observes the intermediate\n // focus-on-body state, and a containing dialog's focus guards (Base UI\n // Sheet) see focus already inside the popup when their async handlers run.\n React.useLayoutEffect(() => {\n const pending = pendingFocusRef.current\n if (!pending) {\n return\n }\n pendingFocusRef.current = null\n const level = containerRef.current?.querySelector<HTMLElement>(\n `[data-level-id=\"${CSS.escape(pending.levelId)}\"]`,\n )\n if (!level) {\n return\n }\n const target = pending.itemId\n ? level.querySelector<HTMLElement>(`[data-item-id=\"${CSS.escape(pending.itemId)}\"]`)\n : (level.querySelector<HTMLElement>('[data-slot=\"push-menu-back-button\"]') ??\n level.querySelector<HTMLElement>(\n '[data-slot=\"push-menu-item\"], [data-slot=\"push-menu-link\"]',\n ))\n // preventScroll: a level mid-slide sits at translateX(100%) inside an\n // overflow-hidden root; letting focus scroll it into view would desync the\n // container's scroll position from the transform.\n target?.focus({ preventScroll: true })\n // animationState is a dependency because back-navigation queues its focus\n // move on the slide START (an animationState commit), not on the level\n // pop — see navigateBack.\n }, [navigationHistory, animationState])\n\n const breadcrumb = React.useMemo(\n // During a back slide the trail already excludes the departing level —\n // the breadcrumb tracks the level the user is arriving at (see\n // activeIndex below), same as the live region.\n () =>\n generatePushMenuBreadcrumb(\n animationState === 'sliding-backward' ? navigationHistory.slice(0, -1) : navigationHistory,\n ),\n [navigationHistory, animationState],\n )\n\n function navigateToSubmenu(item: PushMenuItem) {\n if (!item.links?.length || animationState !== 'idle') {\n return\n }\n const levelPath = [\n ...navigationHistory.flatMap((level) => (level.parentItem ? [level.parentItem.id] : [])),\n item.id,\n ]\n const currentDepth = navigationHistory.at(-1)?.depth ?? 1\n const newLevel: PushMenuLevel = {\n items: item.links,\n title: item.title,\n parentItem: item,\n depth: currentDepth + 1,\n id: buildLevelId(levelPath),\n }\n const newHistory = [...navigationHistory, newLevel]\n\n // Focus moves as soon as the new level commits (see the effect above):\n // waiting for the slide to finish would leave focus on the old level,\n // which turns inert in the same commit and would eject focus to <body>.\n pendingFocusRef.current = { levelId: newLevel.id }\n setNavigationHistory(newHistory)\n setAnimationState('sliding-forward')\n setIsAnimationStarted(false)\n\n // Two-step start: the new level mounts at translateX(100%) with no\n // transition, then flips to 0 with the transition on. The layout read in\n // between is LOAD-BEARING: without it, nothing forces the browser to\n // compute styles for the mounted-at-100% frame, and when both states land\n // in one style recalc there is no transition — the panel snaps into\n // place instead of sliding (an intermittent, timing-dependent jump).\n // Reading layout inside the rAF forces that recalc deterministically.\n requestAnimationFrame(() => {\n containerRef.current?.getBoundingClientRect()\n setIsAnimationStarted(true)\n })\n\n timeoutRef.current = window.setTimeout(() => {\n setAnimationState('idle')\n setIsAnimationStarted(false)\n onNavigate?.(newLevel, newHistory)\n }, durationMs)\n }\n\n function navigateBack() {\n if (navigationHistory.length <= 1 || animationState !== 'idle') {\n return\n }\n const popped = navigationHistory.at(-1)\n const revealed = navigationHistory.at(-2)\n if (!revealed) {\n return\n }\n\n // Focus moves at slide START, symmetric with drilling forward: the\n // 'sliding-backward' commit un-inerts the revealed level (see the\n // activeIndex logic below) and the effect above focuses the item that\n // opened the departing level. Restoring focus at the POP instead — while\n // focus still sat on the departing level's Back button — meant the\n // focused node was removed from a live dialog, and Base UI's focus\n // containment would re-grab focus to the dialog popup a frame after our\n // restoration, silently overriding it (observed inside Sheet).\n pendingFocusRef.current = { levelId: revealed.id, itemId: popped?.parentItem?.id }\n setAnimationState('sliding-backward')\n\n timeoutRef.current = window.setTimeout(() => {\n const newHistory = navigationHistory.slice(0, -1)\n setNavigationHistory(newHistory)\n setAnimationState('idle')\n onNavigate?.(revealed, newHistory)\n }, durationMs)\n }\n\n const currentLevel = navigationHistory.at(-1)\n if (!currentLevel) {\n return null\n }\n\n const isAnimating = animationState !== 'idle'\n // The level the user is arriving AT — the stack top, except during a back\n // slide, where the user's intent has already committed to the level being\n // revealed underneath. data-current, inert, the live region and the\n // breadcrumb all follow this index so focus can land on the revealed level\n // at slide start and AT hears the destination, not the departing level.\n const activeIndex =\n animationState === 'sliding-backward'\n ? navigationHistory.length - 2\n : navigationHistory.length - 1\n const activeLevel = navigationHistory[activeIndex] ?? currentLevel\n const HeadingTag = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='push-menu'\n aria-label={ariaLabel ?? title}\n // Present while a slide is running (matches header's present-or-absent\n // data-scrolled convention). Consumers can style the transition off it;\n // tests use it to wait for the state machine to go idle — clicks during\n // a slide are dropped by design, and pointer-events-none does not stop\n // a programmatic .click().\n data-animating={isAnimating || undefined}\n {...props}\n className={cn(\n 'relative isolate h-full overflow-hidden bg-popover text-popover-foreground',\n className,\n )}\n // The slide duration custom property is set from durationMs so the CSS\n // transition and the setTimeout state machine can never disagree — see\n // the coupling note on PUSH_MENU_DURATION_MS.\n style={{ ...style, '--push-menu-duration': `${durationMs}ms` } as React.CSSProperties}\n ref={(node) => {\n containerRef.current = node\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ;(ref as React.RefObject<HTMLElement | null>).current = node\n }\n }}\n >\n {/* Persistent live region: announces level changes to AT without\n stealing focus from the managed focus moves. The level number is\n appended below the root because live regions only re-announce when\n their content actually changes — navigating between identically-\n titled levels would otherwise announce nothing. Consecutive levels\n always differ in depth, so consecutive announcements always differ. */}\n <div data-slot='push-menu-live-region' aria-live='polite' className='sr-only'>\n {activeLevel.depth > 1\n ? `${activeLevel.title}, level ${activeLevel.depth}`\n : activeLevel.title}\n </div>\n\n {navigationHistory.map((level, index) => {\n // The stack top is the level that MOVES (slides in forward, slides\n // out backward); the active level is the one the user is arriving at\n // — they differ only during a back slide.\n const isTopLevel = index === navigationHistory.length - 1\n const isActiveLevel = index === activeIndex\n // Always shown below the root: the Back button is the ONLY route back\n // (the breadcrumb is aria-hidden and there is no keyboard binding or\n // imperative API), so making it optional would strand users.\n const shouldShowBackButton = level.depth > 1\n\n let translateX = 0\n if (animationState === 'sliding-forward') {\n translateX = isTopLevel ? (isAnimationStarted ? 0 : 100) : 0\n } else if (animationState === 'sliding-backward') {\n translateX = isTopLevel ? 100 : 0\n }\n\n // Only the moving (top) level transitions; forward slides wait for\n // the second frame so the mount position is applied untransitioned.\n const isSliding =\n isTopLevel &&\n (animationState === 'sliding-backward' ||\n (animationState === 'sliding-forward' && isAnimationStarted))\n\n return (\n <div\n key={level.id}\n data-slot='push-menu-level'\n data-level-id={level.id}\n data-current={isActiveLevel || undefined}\n // Non-active levels must be invisible to keyboard and AT, not\n // just to the eye. Keying this on the ACTIVE level (not the stack\n // top) un-inerts the revealed level at back-slide start, so focus\n // can move there immediately — and the focused Back button is\n // never removed from a live dialog while still focused.\n inert={!isActiveLevel}\n className={cn(\n 'absolute inset-0 flex h-full w-full flex-col bg-popover will-change-transform',\n isSliding\n ? 'duration-(--push-menu-duration) ease-out motion-safe:transition-transform'\n : 'transition-none',\n )}\n style={{ transform: `translateX(${translateX}%)`, zIndex: index + 1 }}\n >\n <div\n data-slot='push-menu-header'\n className='flex min-h-11 items-center gap-1 border-b border-border px-2 py-2'\n >\n {shouldShowBackButton && (\n <Button\n data-slot='push-menu-back-button'\n variant='ghost'\n color='primary'\n size='sm'\n leadingVisual={IconWest}\n onClick={navigateBack}\n className={cn(isAnimating && 'pointer-events-none')}\n >\n {backLabel}\n </Button>\n )}\n <HeadingTag\n data-slot='push-menu-title'\n className='min-w-0 flex-1 truncate px-2 text-base font-semibold'\n >\n {level.title}\n </HeadingTag>\n {onClose && (\n <Button\n data-slot='push-menu-close-button'\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={closeLabel}\n leadingVisual={IconClose}\n onClick={onClose}\n />\n )}\n </div>\n\n {showBreadcrumbs && isActiveLevel && level.depth > 1 && (\n // aria-hidden: the trail repeats what the heading and live\n // region already announce, and \"›\" separators read poorly in AT.\n <p\n data-slot='push-menu-breadcrumb'\n aria-hidden='true'\n className='truncate border-b border-border px-4 py-2 text-xs text-muted-foreground'\n >\n {breadcrumb}\n </p>\n )}\n\n <div data-slot='push-menu-items' className='flex-1 overflow-y-auto'>\n {/* role='list' restores list semantics stripped by list-none. */}\n <ul role='list' className='m-0 list-none divide-y divide-border p-0'>\n {level.items.map((item) => {\n const hasChildren = Boolean(item.links?.length)\n const isActive = item.href != null && item.href === currentHref\n\n return (\n <li key={item.id}>\n {hasChildren ? (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => navigateToSubmenu(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n <IconChevronRight aria-hidden='true' className='size-5 shrink-0' />\n </button>\n ) : item.href ? (\n <Link\n variant='unstyled'\n data-slot='push-menu-link'\n data-item-id={item.id}\n href={item.href}\n aria-current={isActive ? 'page' : undefined}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </Link>\n ) : (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </button>\n )}\n </li>\n )\n })}\n </ul>\n </div>\n </div>\n )\n })}\n </nav>\n )\n}\n\nexport { generatePushMenuBreadcrumb, PUSH_MENU_DURATION_MS, PushMenu }\nexport type { PushMenuItem, PushMenuLevel, PushMenuProps }\n"]}
1
+ {"version":3,"sources":["../../src/components/push-menu.tsx"],"names":[],"mappings":";;;;;;;;;AA0BA,MAAM,qBAAA,GAAwB;AA2B9B,SAAS,aAAa,IAAA,EAAwB;AAC5C,EAAA,OAAO,CAAA,MAAA,EAAS,KAAK,MAAA,GAAS,CAAA,GAAI,KAAK,IAAA,CAAK,IAAI,IAAI,MAAM,CAAA,CAAA;AAC5D;AAkBA,SAAS,oBAAA,CAAqB,OAAe,SAAA,EAA2B;AACtE,EAAA,IAAI,YAAY,CAAA,EAAG;AACjB,IAAA,OAAO,EAAA;AAAA,EACT;AACA,EAAA,MAAM,SAAS,SAAA,GAAY,CAAA;AAC3B,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,KAAA,MAAW,aAAa,KAAA,EAAO;AAC7B,IAAA,IAAI,GAAA,CAAI,MAAA,GAAS,SAAA,CAAU,MAAA,GAAS,MAAA,EAAQ;AAC1C,MAAA;AAAA,IACF;AACA,IAAA,GAAA,IAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,GAAG,GAAG,CAAA,MAAA,CAAA;AACf;AAgBA,SAAS,0BAAA,CAA2B,MAAA,EAA6B,SAAA,GAAY,EAAA,EAAY;AACvF,EAAA,MAAM,KAAA,GAAQ,OAAO,CAAC,CAAA;AACtB,EAAA,IAAI,MAAA,CAAO,UAAU,CAAA,EAAG;AACtB,IAAA,OAAO,OAAO,KAAA,IAAS,MAAA;AAAA,EACzB;AAEA,EAAA,MAAM,IAAA,GAAO,OA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AA,mBACP,GAAA;AAAA,oBAAC,IAAA;AAAA,oBAAA;AAAA,sBACC,OAAA,EAAQ,UAAA;AAAA,sBACR,WAAA,EAAU,gBAAA;AAAA,sBACV,gBAAc,IAAA,CAAK,EAAA;AAAA,sBACnB,MAAM,IAAA,CAAK,IAAA;AAAA,sBACX,cAAA,EAAc,WAAW,MAAA,GAAS,MAAA;AAAA,sBAClC,OAAA,EAAS,MAAM,WAAA,GAAc,IAAI,CAAA;AAAA,sBACjC,SAAA,EAAW,EAAA;AAAA,wBACT,iBAAA;AAAA,wBACA,WAAW,mBAAA,GAAsB,qBAAA;AAAA,wBACjC,WAAA,IAAe;AAAA,uBACjB;AAAA,sBAEA,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yBAAA,EAA2B,eAAK,KAAA,EAAM;AAAA;AAAA,mBACxD,mBAEA,GAAA;AAAA,oBAAC,QAAA;AAAA,oBAAA;AAAA,sBACC,IAAA,EAAK,QAAA;AAAA,sBACL,WAAA,EAAU,gBAAA;AAAA,sBACV,gBAAc,IAAA,CAAK,EAAA;AAAA,sBACnB,OAAA,EAAS,MAAM,WAAA,GAAc,IAAI,CAAA;AAAA,sBACjC,SAAA,EAAW,EAAA;AAAA,wBACT,iBAAA;AAAA,wBACA,qBAAA;AAAA,wBACA,WAAA,IAAe;AAAA,uBACjB;AAAA,sBAEA,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yBAAA,EAA2B,eAAK,KAAA,EAAM;AAAA;AAAA,mBACxD,EAAA,EA7CK,KAAK,EA+Cd,CAAA;AAAA,gBAEJ,CAAC,GACH,CAAA,EACF;AAAA;AAAA,aAAA;AAAA,YA7HK,KAAA,CAAM;AAAA,WA8Hb;AAAA,QAEJ,CAAC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"push-menu.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\nimport { IconClose } from '../icons/close.js'\nimport { IconWest } from '../icons/west.js'\n\n/**\n * Default slide duration for level transitions, in milliseconds — the default\n * of the `durationMs` prop.\n *\n * COUPLING: `durationMs` drives BOTH the `--push-menu-duration` custom\n * property (set inline on the root, read by the CSS transition) and the state\n * machine's `setTimeout`s (which settle the animation state, pop levels, and\n * schedule focus restoration). Do not override the custom property directly —\n * that changes only the visual duration while the state machine still settles\n * on `durationMs`, desyncing the two; pass `durationMs` instead. Under\n * `prefers-reduced-motion` the slide is skipped (the transition is applied\n * under `motion-safe:` only) but the state machine still waits the full\n * duration; the menu is simply \"settled early\" for those users, never broken.\n */\nconst PUSH_MENU_DURATION_MS = 300\n\n/** A node in the menu tree. Items with `links` drill in; items with `href` navigate. */\ntype PushMenuItem = {\n /** Unique across the whole tree — level ids and focus restoration track items by id. */\n id: string\n /** Visible label. */\n title: string\n /** Navigation target for leaf items. Ignored for drilling when `links` is non-empty. */\n href?: string\n /** Child items. A non-empty array makes this item a drill-in button, not a link. */\n links?: PushMenuItem[]\n}\n\n/** One entry in the level stack — the root level plus one per drill-in. */\ntype PushMenuLevel = {\n id: string\n title: string\n /** 1 for the root level, incrementing per drill-in. */\n depth: number\n items: PushMenuItem[]\n /** The item whose activation opened this level. Absent on the root level. */\n parentItem?: PushMenuItem\n}\n\ntype PushMenuAnimationState = 'idle' | 'sliding-forward' | 'sliding-backward'\n\nfunction buildLevelId(path: string[]): string {\n return `level-${path.length > 0 ? path.join('--') : 'root'}`\n}\n\n/**\n * Truncates to at most `maxLength` UTF-16 units, ellipsis included in the\n * budget.\n *\n * Iterates CODE POINTS (`for…of` over a string) rather than slicing by index:\n * a plain `slice` can cut between the two halves of a surrogate pair, leaving\n * a lone surrogate that renders as U+FFFD (an emoji in a level title was\n * enough to reproduce it). Accumulating whole code points and checking the\n * running UTF-16 length keeps both properties at once — never a split pair,\n * and never over budget.\n *\n * Code points, not grapheme clusters: a base character can still be separated\n * from a following combining mark. That degrades to an odd-looking glyph\n * rather than the U+FFFD this fixes, and `Intl.Segmenter` is too recent to\n * hand to registry consumers (who copy this source) without a fallback.\n */\nfunction truncateWithEllipsis(value: string, maxLength: number): string {\n if (maxLength < 1) {\n return ''\n }\n const budget = maxLength - 1\n let out = ''\n for (const codePoint of value) {\n if (out.length + codePoint.length > budget) {\n break\n }\n out += codePoint\n }\n return `${out}…`\n}\n\n/**\n * Collapses a trail of level titles into a single \"A › B › C\" string, keeping\n * the ends and eliding the middle once it outgrows `maxLength`. Exported so an\n * app can render the same trail outside the menu (e.g. in a sheet header).\n * Prefixed with \"PushMenu\" to avoid colliding with a future breadcrumb\n * component in the package barrel.\n *\n * `maxLength` is a HARD bound on the returned string, measured in UTF-16 units\n * (`String.length`) — the one exception is a single level, whose title is\n * returned verbatim because there is nothing to collapse. Callers rendering the\n * trail in a fixed-width slot can rely on that. Middle-elision is attempted\n * first because it reads better; when it does not fit, the full trail is\n * truncated from the end.\n */\nfunction generatePushMenuBreadcrumb(levels: { title: string }[], maxLength = 50): string {\n const first = levels[0]\n if (levels.length <= 1) {\n return first?.title ?? 'Menu'\n }\n\n const full = levels.map((level) => level.title).join(' › ')\n if (full.length <= maxLength) {\n return full\n }\n\n // Only worth eliding if it actually gets under the budget. With exactly four\n // levels it replaces ONE title with \"…\", which saves nothing when that title\n // is short — \"A › B › C › D\" and \"A › … › C › D\" are the same length — and\n // with long titles the elided form can still run well over. Returning it\n // unchecked is what broke the bound.\n const last = levels.at(-1)\n const secondLast = levels.at(-2)\n if (levels.length > 3 && first && last && secondLast) {\n const elided = `${first.title} › … › ${secondLast.title} › ${last.title}`\n if (elided.length <= maxLength) {\n return elided\n }\n }\n\n return truncateWithEllipsis(full, maxLength)\n}\n\n/**\n * Dev-only guard, mirroring `warnIfIconButtonUnlabelled` in button.tsx. It\n * replaces the nswds-app source's rendered \"Navigation Error\" fallback panel:\n * malformed navigation data is a programming error, not a runtime state a user\n * should ever see, so the design system surfaces it to the developer console\n * and renders what it can instead of shipping error chrome. No-op in\n * production.\n */\nfunction warnIfNavigationMalformed(navigation: PushMenuItem[]) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!Array.isArray(navigation) || navigation.length === 0) {\n console.warn('[nswds/ui] PushMenu received no navigation items — the menu renders empty.')\n return\n }\n const seen = new Set<string>()\n const visit = (items: PushMenuItem[]) => {\n for (const item of items) {\n if (!item?.id || !item.title) {\n console.warn('[nswds/ui] PushMenu navigation item is missing an `id` or `title`:', item)\n continue\n }\n if (seen.has(item.id)) {\n console.warn(\n `[nswds/ui] PushMenu navigation contains duplicate id \"${item.id}\" — level ids and focus restoration track items by id, so ids must be unique across the whole tree.`,\n )\n }\n seen.add(item.id)\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] PushMenu item \"${item.id}\" has neither an href nor children — it renders as a button that only fires onItemClick.`,\n )\n }\n if (item.links?.length) {\n visit(item.links)\n }\n }\n }\n visit(navigation)\n}\n\n// One treatment for every row — drill-in buttons and leaf links alike — so the\n// two read as a single list. Tokenized from the nswds-app source's\n// border-l + primary-800 active pattern, with dark-mode equivalents the app\n// lacked (its grey-800-on-white text disappeared in dark mode).\nconst itemBaseClassName = [\n // min-h-11 guarantees the 44px minimum target size (WCAG 2.2, 2.5.8 Target\n // Size) even for single-line rows with compact padding overrides.\n 'relative flex min-h-11 w-full cursor-pointer items-center justify-between gap-x-6 border-l p-4 text-left text-base',\n 'motion-safe:transition-colors',\n 'hover:border-primary-800 hover:bg-primary-800/10 dark:hover:border-primary-200 dark:hover:bg-primary-200/10',\n // Inset outline (negative offset): the levels scroll inside an\n // overflow-hidden root, so an outward offset would be clipped on the first\n // and last rows (WCAG 2.2, 2.4.13 Focus Appearance).\n 'focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary-800 dark:focus-visible:outline-primary-200',\n].join(' ')\n\nconst itemActiveClassName =\n 'border-primary-800 bg-primary-800/10 font-semibold text-primary-800 dark:border-primary-200 dark:bg-primary-200/10 dark:text-primary-200'\n\nconst itemInactiveClassName = 'border-transparent text-popover-foreground'\n\ntype PushMenuProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children' | 'title'> & {\n /** The menu tree. Item ids must be unique across the whole tree. */\n navigation: PushMenuItem[]\n /**\n * The app's current pathname. Leaf links whose `href` matches get\n * `aria-current=\"page\"` and the active treatment. Replaces the nswds-app\n * source's `usePathname()` — the design system is framework-free, so the\n * router value is passed in rather than read from next/navigation.\n */\n currentHref?: string\n /** Root level title, shown in the header row. Also the default `aria-label`. */\n title?: string\n /** Fired when a leaf item (link or child-less button) is activated. */\n onItemClick?: (item: PushMenuItem) => void\n /** Fired after a forward/back slide settles on a level. */\n onNavigate?: (level: PushMenuLevel, history: PushMenuLevel[]) => void\n /**\n * Renders a close button in the header row when provided. Unlike the\n * nswds-app source — which only offered close on sub-levels, leaving the\n * root level uncloseable — the button renders on every level.\n */\n onClose?: () => void\n /** Show the \"A › B › C\" trail under the header on sub-levels. Defaults to `true`. */\n showBreadcrumbs?: boolean\n /**\n * Slide duration in milliseconds, defaulting to `PUSH_MENU_DURATION_MS`\n * (300). Drives both the `--push-menu-duration` custom property and the\n * state machine's timeouts — tune the slide here, never by overriding the\n * custom property (see the coupling note on the constant).\n */\n durationMs?: number\n /** Label for the Back button on sub-levels. Defaults to `'Back'`. */\n backLabel?: string\n /** Accessible label for the close button. Defaults to `'Close menu'`. */\n closeLabel?: string\n /**\n * Heading level for the per-level title, following `FooterNavColumn`'s\n * precedent (the nswds-app source used a `Heading` component this package\n * does not ship). Defaults to `2`; `1` is excluded because a menu panel\n * title is never the page's own title.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Multi-level slide-in-place drill-down menu (\"push menu\") for mobile\n * navigation, ported from nswds-app's `MultiLevelPushMenu`. Items with\n * children render as buttons that slide a new level in from the right; leaf\n * items render as links through `Link`, so apps can inject their framework\n * link component via `LinkProvider`. Fill height from its container — compose\n * it inside `SheetContent side=\"left\"` for the classic mobile drawer.\n *\n * Accessibility contract (all improvements over the nswds-app source, which\n * got several of these wrong):\n *\n * - The root is a `nav` landmark named by `title` (override with `aria-label`).\n * - Non-current levels carry the `inert` attribute, so a hidden level's links\n * are neither tabbable nor exposed to assistive tech. The app left every\n * mounted level in the tab order, letting keyboard users tab into invisible\n * history levels (WCAG 2.2, 2.4.3 Focus Order).\n * - Focus moves with the level change (2.4.3): drilling forward focuses the\n * new level's Back button; going back focuses the item that opened the\n * level just left, tracked by item id and restored after the slide settles.\n * Without this, `inert` on the old level would silently drop focus to\n * `<body>`. The Back button is the only route back (the breadcrumb is\n * decorative), so it always renders on sub-levels — hiding it would make\n * drill-down one-way.\n * - A single visually-hidden `aria-live=\"polite\"` region at the root announces\n * the current level's title, suffixed with the level number below the root.\n * A live attribute on the per-level headings would not work: each level's\n * heading is freshly mounted, and newly-mounted live regions are not\n * reliably announced.\n * - Level lists are `<ul role=\"list\">` — `list-style: none` strips list\n * semantics in some screen reader/browser pairings (notably VoiceOver), and\n * the explicit role restores them.\n * - Every row is at least 44px tall (2.5.8 Target Size); Back/close buttons\n * inherit `Button`'s 44px touch target.\n * - During the slide, rows get `pointer-events-none` and the state machine\n * ignores re-entrant navigation, but nothing is ever `disabled` — disabling\n * the focused Back button mid-animation would eject keyboard focus.\n * - Slides are CSS transforms applied under `motion-safe:`, replacing the app's\n * inline transition strings (which ignored reduced motion).\n *\n * Departures from the nswds-app source, beyond the above:\n *\n * - The footer/stats block (Level N, item counts, progress dots, lucide\n * icons) is cut, along with its `showStats`/`showFooter` props: it was demo\n * chrome for the sandbox, not part of a navigation component's job. The\n * breadcrumb trail it hosted moves under the header row.\n * - The rendered \"Navigation Error\" fallback for malformed data is replaced\n * by a dev-only console warning (`warnIfNavigationMalformed`), mirroring\n * button.tsx's `warnIfIconButtonUnlabelled`.\n * - The breadcrumb trail is `aria-hidden`: it repeats what the heading and\n * live region already announce, and \"›\" separators read poorly in AT.\n *\n * The level stack is seeded from `navigation`/`title` on mount; pass a `key`\n * to remount (and reset to the root level) if either changes at runtime.\n */\nfunction PushMenu({\n navigation,\n currentHref,\n title = 'Menu',\n onItemClick,\n onNavigate,\n onClose,\n showBreadcrumbs = true,\n durationMs = PUSH_MENU_DURATION_MS,\n backLabel = 'Back',\n closeLabel = 'Close menu',\n headingLevel = 2,\n className,\n style,\n 'aria-label': ariaLabel,\n ref,\n ...props\n}: PushMenuProps) {\n const [navigationHistory, setNavigationHistory] = React.useState<PushMenuLevel[]>(() => [\n { items: navigation, title, depth: 1, id: buildLevelId([]) },\n ])\n const [animationState, setAnimationState] = React.useState<PushMenuAnimationState>('idle')\n const [isAnimationStarted, setIsAnimationStarted] = React.useState(false)\n\n const containerRef = React.useRef<HTMLElement | null>(null)\n const timeoutRef = React.useRef<number | null>(null)\n // Focus target applied by the effect below, after React commits the level\n // change — the target element must exist and must no longer be inert.\n const pendingFocusRef = React.useRef<{ levelId: string; itemId?: string } | null>(null)\n\n warnIfNavigationMalformed(navigation)\n\n React.useEffect(() => {\n return () => {\n if (timeoutRef.current !== null) {\n window.clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n // Layout effect, not a passive one: the same commit that queues a focus\n // move can also flip the previously-focused element inert (drilling turns\n // the old level inert; going back turns the departing level inert), and the\n // browser blurs an element the moment it becomes inert. Applying the new\n // focus before paint means AT never observes the intermediate\n // focus-on-body state, and a containing dialog's focus guards (Base UI\n // Sheet) see focus already inside the popup when their async handlers run.\n React.useLayoutEffect(() => {\n const pending = pendingFocusRef.current\n if (!pending) {\n return\n }\n pendingFocusRef.current = null\n const level = containerRef.current?.querySelector<HTMLElement>(\n `[data-level-id=\"${CSS.escape(pending.levelId)}\"]`,\n )\n if (!level) {\n return\n }\n const target = pending.itemId\n ? level.querySelector<HTMLElement>(`[data-item-id=\"${CSS.escape(pending.itemId)}\"]`)\n : (level.querySelector<HTMLElement>('[data-slot=\"push-menu-back-button\"]') ??\n level.querySelector<HTMLElement>(\n '[data-slot=\"push-menu-item\"], [data-slot=\"push-menu-link\"]',\n ))\n // preventScroll: a level mid-slide sits at translateX(100%) inside an\n // overflow-hidden root; letting focus scroll it into view would desync the\n // container's scroll position from the transform.\n target?.focus({ preventScroll: true })\n // animationState is a dependency because back-navigation queues its focus\n // move on the slide START (an animationState commit), not on the level\n // pop — see navigateBack.\n }, [navigationHistory, animationState])\n\n const breadcrumb = React.useMemo(\n // During a back slide the trail already excludes the departing level —\n // the breadcrumb tracks the level the user is arriving at (see\n // activeIndex below), same as the live region.\n () =>\n generatePushMenuBreadcrumb(\n animationState === 'sliding-backward' ? navigationHistory.slice(0, -1) : navigationHistory,\n ),\n [navigationHistory, animationState],\n )\n\n function navigateToSubmenu(item: PushMenuItem) {\n if (!item.links?.length || animationState !== 'idle') {\n return\n }\n const levelPath = [\n ...navigationHistory.flatMap((level) => (level.parentItem ? [level.parentItem.id] : [])),\n item.id,\n ]\n const currentDepth = navigationHistory.at(-1)?.depth ?? 1\n const newLevel: PushMenuLevel = {\n items: item.links,\n title: item.title,\n parentItem: item,\n depth: currentDepth + 1,\n id: buildLevelId(levelPath),\n }\n const newHistory = [...navigationHistory, newLevel]\n\n // Focus moves as soon as the new level commits (see the effect above):\n // waiting for the slide to finish would leave focus on the old level,\n // which turns inert in the same commit and would eject focus to <body>.\n pendingFocusRef.current = { levelId: newLevel.id }\n setNavigationHistory(newHistory)\n setAnimationState('sliding-forward')\n setIsAnimationStarted(false)\n\n // Two-step start: the new level mounts at translateX(100%) with no\n // transition, then flips to 0 with the transition on. The layout read in\n // between is LOAD-BEARING: without it, nothing forces the browser to\n // compute styles for the mounted-at-100% frame, and when both states land\n // in one style recalc there is no transition — the panel snaps into\n // place instead of sliding (an intermittent, timing-dependent jump).\n // Reading layout inside the rAF forces that recalc deterministically.\n requestAnimationFrame(() => {\n containerRef.current?.getBoundingClientRect()\n setIsAnimationStarted(true)\n })\n\n timeoutRef.current = window.setTimeout(() => {\n setAnimationState('idle')\n setIsAnimationStarted(false)\n onNavigate?.(newLevel, newHistory)\n }, durationMs)\n }\n\n function navigateBack() {\n if (navigationHistory.length <= 1 || animationState !== 'idle') {\n return\n }\n const popped = navigationHistory.at(-1)\n const revealed = navigationHistory.at(-2)\n if (!revealed) {\n return\n }\n\n // Focus moves at slide START, symmetric with drilling forward: the\n // 'sliding-backward' commit un-inerts the revealed level (see the\n // activeIndex logic below) and the effect above focuses the item that\n // opened the departing level. Restoring focus at the POP instead — while\n // focus still sat on the departing level's Back button — meant the\n // focused node was removed from a live dialog, and Base UI's focus\n // containment would re-grab focus to the dialog popup a frame after our\n // restoration, silently overriding it (observed inside Sheet).\n pendingFocusRef.current = { levelId: revealed.id, itemId: popped?.parentItem?.id }\n setAnimationState('sliding-backward')\n\n timeoutRef.current = window.setTimeout(() => {\n const newHistory = navigationHistory.slice(0, -1)\n setNavigationHistory(newHistory)\n setAnimationState('idle')\n onNavigate?.(revealed, newHistory)\n }, durationMs)\n }\n\n const currentLevel = navigationHistory.at(-1)\n if (!currentLevel) {\n return null\n }\n\n const isAnimating = animationState !== 'idle'\n // The level the user is arriving AT — the stack top, except during a back\n // slide, where the user's intent has already committed to the level being\n // revealed underneath. data-current, inert, the live region and the\n // breadcrumb all follow this index so focus can land on the revealed level\n // at slide start and AT hears the destination, not the departing level.\n const activeIndex =\n animationState === 'sliding-backward'\n ? navigationHistory.length - 2\n : navigationHistory.length - 1\n const activeLevel = navigationHistory[activeIndex] ?? currentLevel\n const HeadingTag = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='push-menu'\n aria-label={ariaLabel ?? title}\n // Present while a slide is running (matches header's present-or-absent\n // data-scrolled convention). Consumers can style the transition off it;\n // tests use it to wait for the state machine to go idle — clicks during\n // a slide are dropped by design, and pointer-events-none does not stop\n // a programmatic .click().\n data-animating={isAnimating || undefined}\n {...props}\n className={cn(\n 'relative isolate h-full overflow-hidden bg-popover text-popover-foreground',\n className,\n )}\n // The slide duration custom property is set from durationMs so the CSS\n // transition and the setTimeout state machine can never disagree — see\n // the coupling note on PUSH_MENU_DURATION_MS.\n style={{ ...style, '--push-menu-duration': `${durationMs}ms` } as React.CSSProperties}\n ref={(node) => {\n containerRef.current = node\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ;(ref as React.RefObject<HTMLElement | null>).current = node\n }\n }}\n >\n {/* Persistent live region: announces level changes to AT without\n stealing focus from the managed focus moves. The level number is\n appended below the root because live regions only re-announce when\n their content actually changes — navigating between identically-\n titled levels would otherwise announce nothing. Consecutive levels\n always differ in depth, so consecutive announcements always differ. */}\n <div data-slot='push-menu-live-region' aria-live='polite' className='sr-only'>\n {activeLevel.depth > 1\n ? `${activeLevel.title}, level ${activeLevel.depth}`\n : activeLevel.title}\n </div>\n\n {navigationHistory.map((level, index) => {\n // The stack top is the level that MOVES (slides in forward, slides\n // out backward); the active level is the one the user is arriving at\n // — they differ only during a back slide.\n const isTopLevel = index === navigationHistory.length - 1\n const isActiveLevel = index === activeIndex\n // Always shown below the root: the Back button is the ONLY route back\n // (the breadcrumb is aria-hidden and there is no keyboard binding or\n // imperative API), so making it optional would strand users.\n const shouldShowBackButton = level.depth > 1\n\n let translateX = 0\n if (animationState === 'sliding-forward') {\n translateX = isTopLevel ? (isAnimationStarted ? 0 : 100) : 0\n } else if (animationState === 'sliding-backward') {\n translateX = isTopLevel ? 100 : 0\n }\n\n // Only the moving (top) level transitions; forward slides wait for\n // the second frame so the mount position is applied untransitioned.\n const isSliding =\n isTopLevel &&\n (animationState === 'sliding-backward' ||\n (animationState === 'sliding-forward' && isAnimationStarted))\n\n return (\n <div\n key={level.id}\n data-slot='push-menu-level'\n data-level-id={level.id}\n data-current={isActiveLevel || undefined}\n // Non-active levels must be invisible to keyboard and AT, not\n // just to the eye. Keying this on the ACTIVE level (not the stack\n // top) un-inerts the revealed level at back-slide start, so focus\n // can move there immediately — and the focused Back button is\n // never removed from a live dialog while still focused.\n inert={!isActiveLevel}\n className={cn(\n 'absolute inset-0 flex h-full w-full flex-col bg-popover will-change-transform',\n isSliding\n ? 'duration-(--push-menu-duration) ease-out motion-safe:transition-transform'\n : 'transition-none',\n )}\n style={{ transform: `translateX(${translateX}%)`, zIndex: index + 1 }}\n >\n <div\n data-slot='push-menu-header'\n className='flex min-h-11 items-center gap-1 border-b border-border px-2 py-2'\n >\n {shouldShowBackButton && (\n <Button\n data-slot='push-menu-back-button'\n variant='ghost'\n color='primary'\n size='sm'\n leadingVisual={IconWest}\n onClick={navigateBack}\n className={cn(isAnimating && 'pointer-events-none')}\n >\n {backLabel}\n </Button>\n )}\n <HeadingTag\n data-slot='push-menu-title'\n className='min-w-0 flex-1 truncate px-2 text-base font-semibold'\n >\n {level.title}\n </HeadingTag>\n {onClose && (\n <Button\n data-slot='push-menu-close-button'\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={closeLabel}\n leadingVisual={IconClose}\n onClick={onClose}\n />\n )}\n </div>\n\n {showBreadcrumbs && isActiveLevel && level.depth > 1 && (\n // aria-hidden: the trail repeats what the heading and live\n // region already announce, and \"›\" separators read poorly in AT.\n <p\n data-slot='push-menu-breadcrumb'\n aria-hidden='true'\n className='truncate border-b border-border px-4 py-2 text-xs text-muted-foreground'\n >\n {breadcrumb}\n </p>\n )}\n\n <div data-slot='push-menu-items' className='flex-1 overflow-y-auto'>\n {/* role='list' restores list semantics stripped by list-none. */}\n <ul role='list' className='m-0 list-none divide-y divide-border p-0'>\n {level.items.map((item) => {\n const hasChildren = Boolean(item.links?.length)\n const isActive = item.href != null && item.href === currentHref\n\n return (\n <li key={item.id}>\n {hasChildren ? (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => navigateToSubmenu(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n <IconChevronRight aria-hidden='true' className='size-5 shrink-0' />\n </button>\n ) : item.href ? (\n <Link\n variant='unstyled'\n data-slot='push-menu-link'\n data-item-id={item.id}\n href={item.href}\n aria-current={isActive ? 'page' : undefined}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </Link>\n ) : (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </button>\n )}\n </li>\n )\n })}\n </ul>\n </div>\n </div>\n )\n })}\n </nav>\n )\n}\n\nexport { generatePushMenuBreadcrumb, PUSH_MENU_DURATION_MS, PushMenu }\nexport type { PushMenuItem, PushMenuLevel, PushMenuProps }\n"]}
@@ -3,7 +3,7 @@ import { VariantProps } from 'class-variance-authority';
3
3
  import React__default from 'react';
4
4
 
5
5
  declare const skipLinkVariants: (props?: ({
6
- color?: "light" | "white" | "grey" | "dark" | null | undefined;
6
+ color?: "white" | "grey" | "light" | "dark" | null | undefined;
7
7
  } & class_variance_authority_types.ClassProp) | undefined) => string;
8
8
  type SkipLinkProps = React__default.ComponentPropsWithoutRef<'a'> & VariantProps<typeof skipLinkVariants> & {
9
9
  /** Same-page fragment target, e.g. `"#content"`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nswds/ui",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "UI components for NSW Government digital products, providing reusable design elements and patterns for consistent user interfaces.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/digitalnsw/nswds-ui#readme",
@@ -43,6 +43,7 @@
43
43
  "build:css": "tailwindcss -i ./src/styles/package.css -o ./dist/styles.css --minify",
44
44
  "build:js": "tsup",
45
45
  "verify:dist": "node scripts/verify-dist.mjs",
46
+ "test": "node --test \"tests/**/*.test.mjs\"",
46
47
  "check:cascade": "node scripts/check-cascade-safety.mjs",
47
48
  "check:drift": "node scripts/check-component-drift.mjs",
48
49
  "check:registry-resolves": "node scripts/check-registry-resolves.mjs",
@@ -70,8 +71,8 @@
70
71
  "devDependencies": {
71
72
  "@arethetypeswrong/cli": "^0.18.3",
72
73
  "@nswds/tokens": "^5.0.0",
73
- "@storybook/addon-docs": "10.5.8",
74
- "@storybook/react-vite": "10.5.8",
74
+ "@storybook/addon-docs": "10.5.9",
75
+ "@storybook/react-vite": "10.5.9",
75
76
  "@tailwindcss/cli": "^4.3.0",
76
77
  "@tailwindcss/postcss": "^4.1.18",
77
78
  "@turbo/gen": "^2.8.1",
@@ -85,7 +86,7 @@
85
86
  "react": "^19.2.4",
86
87
  "react-dom": "^19.2.4",
87
88
  "shadcn": "^4.8.0",
88
- "storybook": "10.5.8",
89
+ "storybook": "10.5.9",
89
90
  "tailwindcss": "^4.1.18",
90
91
  "tsup": "^8.5.1",
91
92
  "tw-animate-css": "^1.4.0",