@astryxdesign/core 0.7.2-canary.fbc03f7 → 0.7.2-canary.fdd384f

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.
Files changed (58) hide show
  1. package/dist/AppShell/AppShell.d.ts.map +1 -1
  2. package/dist/AppShell/AppShell.js +40 -1
  3. package/dist/CommandPalette/CommandPaletteInput.d.ts +1 -1
  4. package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
  5. package/dist/CommandPalette/CommandPaletteInput.js +37 -5
  6. package/dist/Heading/Heading.d.ts.map +1 -1
  7. package/dist/Heading/Heading.js +4 -2
  8. package/dist/MobileNav/MobileNav.d.ts +9 -0
  9. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  10. package/dist/MobileNav/MobileNav.js +30 -3
  11. package/dist/SideNav/SideNavItem.d.ts +8 -1
  12. package/dist/SideNav/SideNavItem.d.ts.map +1 -1
  13. package/dist/SideNav/SideNavItem.js +71 -9
  14. package/dist/Text/Text.d.ts.map +1 -1
  15. package/dist/Text/Text.js +4 -2
  16. package/dist/TopNav/TopNavMegaMenu.d.ts.map +1 -1
  17. package/dist/TopNav/TopNavMegaMenu.js +3 -3
  18. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  19. package/dist/TopNav/TopNavMenu.js +3 -3
  20. package/dist/TreeList/TreeList.d.ts.map +1 -1
  21. package/dist/TreeList/TreeList.js +1 -0
  22. package/dist/TreeList/TreeListBranches.d.ts.map +1 -1
  23. package/dist/TreeList/TreeListBranches.js +2 -2
  24. package/dist/TreeList/TreeListItem.d.ts.map +1 -1
  25. package/dist/TreeList/TreeListItem.js +57 -9
  26. package/dist/astryx.css +11 -1
  27. package/package.json +3 -3
  28. package/src/AppShell/AppShell.tsx +45 -1
  29. package/src/Breadcrumbs/Breadcrumbs.test.tsx +30 -1
  30. package/src/Card/Card.doc.mjs +1 -1
  31. package/src/CommandPalette/CommandPaletteInput.test.tsx +53 -4
  32. package/src/CommandPalette/CommandPaletteInput.tsx +33 -3
  33. package/src/CommandPalette/__tests__/CommandPaletteInputAudit.a11y.chromium.spec.ts +335 -0
  34. package/src/CommandPalette/__tests__/CommandPaletteItemAudit.a11y.chromium.spec.ts +292 -0
  35. package/src/ContextMenu/ContextMenu.doc.mjs +2 -3
  36. package/src/ContextMenu/__tests__/ContextMenuAudit.a11y.chromium.spec.ts +438 -0
  37. package/src/DropdownMenu/DropdownMenu.test.tsx +41 -1
  38. package/src/DropdownMenu/DropdownMenuDivider.spec.md +192 -0
  39. package/src/DropdownMenu/__tests__/DropdownMenuDividerAudit.a11y.chromium.spec.ts +280 -0
  40. package/src/Heading/Heading.test.tsx +57 -0
  41. package/src/Heading/Heading.tsx +6 -2
  42. package/src/MobileNav/MobileNav.tsx +30 -3
  43. package/src/MobileNav/MobileNavCloseEdgeCases.test.tsx +173 -15
  44. package/src/SideNav/SideNav.test.tsx +179 -0
  45. package/src/SideNav/SideNavItem.doc.mjs +2 -2
  46. package/src/SideNav/SideNavItem.tsx +96 -17
  47. package/src/Text/Text.test.tsx +57 -0
  48. package/src/Text/Text.tsx +6 -2
  49. package/src/TopNav/TopNavMegaMenu.test.tsx +22 -0
  50. package/src/TopNav/TopNavMegaMenu.tsx +7 -3
  51. package/src/TopNav/TopNavMenu.test.tsx +19 -0
  52. package/src/TopNav/TopNavMenu.tsx +11 -3
  53. package/src/TreeList/TreeList.doc.mjs +1 -0
  54. package/src/TreeList/TreeList.test.tsx +327 -6
  55. package/src/TreeList/TreeList.tsx +5 -1
  56. package/src/TreeList/TreeListBranches.tsx +6 -0
  57. package/src/TreeList/TreeListItem.tsx +88 -13
  58. package/src/theme/derivedVarRegistry.test.ts +4 -0
@@ -26,7 +26,7 @@ import {
26
26
  beforeEach,
27
27
  afterEach,
28
28
  } from 'vitest';
29
- import {StrictMode} from 'react';
29
+ import {StrictMode, useLayoutEffect} from 'react';
30
30
  import {render, screen, fireEvent, act} from '@testing-library/react';
31
31
  import {MobileNav} from './MobileNav';
32
32
  import {AppShell} from '../AppShell/AppShell';
@@ -136,6 +136,42 @@ describe('MobileNav close path edge cases', () => {
136
136
  }
137
137
  });
138
138
 
139
+ // A browser that does not hold a discrete `display` transition (WebKit)
140
+ // drops the dialog to `display: none` the moment the open styling goes, while
141
+ // it is still an open modal: nothing is visible, yet the page stays inert
142
+ // until the close timer fires. So the dialog's own open styling has to be
143
+ // held by the component, not left to that transition. jsdom applies no
144
+ // StyleX styles, so this reads the readable class names StyleX emits in
145
+ // tests: the `open` class (display) is held through the closing commit, the
146
+ // `backdropOpen` class is not, and the hold ends when the dialog closes.
147
+ it('keeps the dialog rendered until its delayed close has run', () => {
148
+ vi.useFakeTimers();
149
+ try {
150
+ const {rerender} = render(<Drawer isOpen />);
151
+ const dialog = screen.getByTestId('mobile-nav');
152
+ expect(dialog.className).toMatch(/styles\.open/);
153
+ expect(dialog.className).toMatch(/styles\.backdropOpen/);
154
+
155
+ act(() => {
156
+ rerender(<Drawer isOpen={false} />);
157
+ });
158
+ // Still an open modal, so still rendered; only the backdrop's open
159
+ // styling (the fade-out) has gone.
160
+ expect(dialog).toHaveAttribute('open');
161
+ expect(dialog.className).toMatch(/styles\.open/);
162
+ expect(dialog.className).not.toMatch(/styles\.backdropOpen/);
163
+
164
+ act(() => {
165
+ vi.advanceTimersByTime(300);
166
+ });
167
+ // Closed: the hold is released along with the dialog.
168
+ expect(dialog).not.toHaveAttribute('open');
169
+ expect(dialog.className).not.toMatch(/styles\.open/);
170
+ } finally {
171
+ vi.useRealTimers();
172
+ }
173
+ });
174
+
139
175
  it('closes the dialog when unmounted while fully open', () => {
140
176
  const {unmount} = render(<Drawer isOpen />);
141
177
  const dialog = screen.getByTestId('mobile-nav');
@@ -401,26 +437,148 @@ describe('MobileNav close path edge cases', () => {
401
437
  });
402
438
 
403
439
  it('closes the AppShell drawer when dismissed with Escape', () => {
404
- render(<TestShell />);
405
- fireEvent.click(screen.getByRole('button', {name: /open navigation/i}));
406
- const dialog = screen.getAllByRole('dialog', {hidden: true})[0];
407
- expect(dialog).toHaveAttribute('open');
440
+ // Fake timers: AppShell now defers hiding this drawer's Activity boundary
441
+ // (#5701) so MobileNav's own close effect gets a real chance to run —
442
+ // the dialog closes via its normal deferred setTimeout, not synchronously.
443
+ vi.useFakeTimers();
444
+ try {
445
+ render(<TestShell />);
446
+ act(() => {
447
+ fireEvent.click(screen.getByRole('button', {name: /open navigation/i}));
448
+ });
449
+ const dialog = screen.getAllByRole('dialog', {hidden: true})[0];
450
+ expect(dialog).toHaveAttribute('open');
408
451
 
409
- fireEvent(dialog, new Event('cancel', {cancelable: true, bubbles: false}));
452
+ act(() => {
453
+ fireEvent(
454
+ dialog,
455
+ new Event('cancel', {cancelable: true, bubbles: false}),
456
+ );
457
+ });
458
+ act(() => {
459
+ vi.advanceTimersByTime(300);
460
+ });
410
461
 
411
- expect(dialog).not.toHaveAttribute('open');
462
+ expect(dialog).not.toHaveAttribute('open');
463
+ } finally {
464
+ vi.useRealTimers();
465
+ }
412
466
  });
413
467
 
414
468
  it('closes the AppShell drawer when the backdrop is clicked', () => {
415
- render(<TestShell />);
416
- fireEvent.click(screen.getByRole('button', {name: /open navigation/i}));
417
- const dialog = screen.getAllByRole('dialog', {hidden: true})[0];
418
- expect(dialog).toHaveAttribute('open');
469
+ vi.useFakeTimers();
470
+ try {
471
+ render(<TestShell />);
472
+ act(() => {
473
+ fireEvent.click(screen.getByRole('button', {name: /open navigation/i}));
474
+ });
475
+ const dialog = screen.getAllByRole('dialog', {hidden: true})[0];
476
+ expect(dialog).toHaveAttribute('open');
419
477
 
420
- // A click landing on the dialog itself, not the drawer panel, is a
421
- // backdrop dismiss.
422
- fireEvent.click(dialog);
478
+ // A click landing on the dialog itself, not the drawer panel, is a
479
+ // backdrop dismiss.
480
+ act(() => {
481
+ fireEvent.click(dialog);
482
+ });
483
+ act(() => {
484
+ vi.advanceTimersByTime(300);
485
+ });
423
486
 
424
- expect(dialog).not.toHaveAttribute('open');
487
+ expect(dialog).not.toHaveAttribute('open');
488
+ } finally {
489
+ vi.useRealTimers();
490
+ }
491
+ });
492
+
493
+ // #5701: AppShell mounts the drawer inside a React.Activity boundary that
494
+ // used to flip to mode="hidden" in the SAME commit as the close, which
495
+ // forced this file's own unmount-only safety-net effect to call
496
+ // dialog.close() synchronously — closing correctly, but skipping the
497
+ // slide-out transition entirely, because Activity's display:none landed
498
+ // before any transition could run. AppShell now defers that flip, so the
499
+ // dialog should still be open (and rendered) for a beat after closing,
500
+ // not synchronously cut off.
501
+ it('keeps the drawer open long enough for its close transition to run (#5701)', () => {
502
+ vi.useFakeTimers();
503
+ try {
504
+ render(<TestShell />);
505
+ act(() => {
506
+ fireEvent.click(screen.getByRole('button', {name: /open navigation/i}));
507
+ });
508
+ const dialog = screen.getAllByRole('dialog', {hidden: true})[0];
509
+ expect(dialog).toHaveAttribute('open');
510
+
511
+ act(() => {
512
+ fireEvent.click(
513
+ screen.getByRole('button', {name: /close navigation/i}),
514
+ );
515
+ });
516
+
517
+ // Immediately after closing, with no timers advanced: the old
518
+ // synchronous-hide bug closed the dialog on this exact tick. The fix
519
+ // means it must still be open here — Activity hasn't hidden the
520
+ // subtree yet, so MobileNav's own deferred close effect is still the
521
+ // one in control.
522
+ expect(dialog).toHaveAttribute('open');
523
+
524
+ // MobileNav's own close delay (capped at 250ms) runs first: about
525
+ // 260ms after the click the dialog has closed on its own timing while
526
+ // AppShell's Activity boundary (held for 250ms + 50ms) still shows the
527
+ // subtree. Hiding first would cut off that close (#5701).
528
+ act(() => {
529
+ vi.advanceTimersByTime(260);
530
+ });
531
+ expect(dialog).not.toHaveAttribute('open');
532
+ // Activity hides its subtree with an inline `display: none`; a closed
533
+ // dialog's own UA style does not count here.
534
+ expect(dialog.style.display).not.toBe('none');
535
+
536
+ // After the hold, Activity hides the subtree.
537
+ act(() => {
538
+ vi.advanceTimersByTime(60);
539
+ });
540
+ expect(dialog.style.display).toBe('none');
541
+ } finally {
542
+ vi.useRealTimers();
543
+ }
544
+ });
545
+ // A controlled open must be visible in the commit that carries it. The
546
+ // Activity boundary only defers the CLOSE; if opening waited for an effect
547
+ // to copy the open state, the drawer would render hidden for one commit
548
+ // with `isOpen` already true.
549
+ it('shows a controlled open in the same commit, not one effect later', () => {
550
+ const commits: {isOpen: boolean; isHidden: boolean}[] = [];
551
+ function Probe({isOpen}: {isOpen: boolean}) {
552
+ useLayoutEffect(() => {
553
+ const drawer = document.querySelector('dialog');
554
+ commits.push({
555
+ isOpen,
556
+ isHidden:
557
+ drawer != null && getComputedStyle(drawer).display === 'none',
558
+ });
559
+ });
560
+ return null;
561
+ }
562
+ const shell = (isOpen: boolean) => (
563
+ <AppShell
564
+ sideNav={
565
+ <SideNav>
566
+ <SideNavSection title="Test" isHeaderHidden>
567
+ <SideNavItem label="Home" />
568
+ </SideNavSection>
569
+ </SideNav>
570
+ }
571
+ mobileNav={{breakpoint: 'md', isOpen, onOpenChange: () => {}}}>
572
+ <Probe isOpen={isOpen} />
573
+ <div>Content</div>
574
+ </AppShell>
575
+ );
576
+
577
+ const {rerender} = render(shell(false));
578
+ rerender(shell(true));
579
+
580
+ const openCommits = commits.filter(commit => commit.isOpen);
581
+ expect(openCommits.length).toBeGreaterThan(0);
582
+ expect(openCommits.every(commit => !commit.isHidden)).toBe(true);
425
583
  });
426
584
  });
@@ -828,6 +828,169 @@ describe('SideNavItem', () => {
828
828
  expect(screen.getByText('Security')).toBeInTheDocument();
829
829
  });
830
830
 
831
+ it('keeps nested rows full width and indents their content inside the row', () => {
832
+ render(
833
+ <SideNavItem label="Settings">
834
+ <SideNavItem label="General" href="/settings/general">
835
+ <SideNavItem label="Advanced" href="/settings/general/advanced" />
836
+ </SideNavItem>
837
+ </SideNavItem>,
838
+ );
839
+
840
+ // The children group adds no inset of its own, so a nested row's hover
841
+ // and selected fill spans the nav list like a top-level row's.
842
+ const groups = screen.getAllByRole('group', {hidden: true});
843
+ for (const group of groups) {
844
+ expect(declaredOn(group, 'padding-inline-start')).toEqual([]);
845
+ expect(
846
+ declaredOn(group.firstElementChild!, 'padding-inline-start'),
847
+ ).toEqual([]);
848
+ }
849
+
850
+ // The indent lives inside each row instead, one step per nesting level.
851
+ // An ordinary row is the link itself: its own padding plus the steps.
852
+ const top = screen.getByRole('button', {name: 'Settings'});
853
+ const general = screen.getByRole('link', {name: 'General'});
854
+ const advanced = screen.getByRole('link', {name: 'Advanced'});
855
+ expect(indentOf(top)).toBeNull();
856
+ expect(indentOf(advanced)).toBe(
857
+ 'calc(var(--spacing-2) + 2 * var(--spacing-6))',
858
+ );
859
+
860
+ // A split row (own href plus children) keeps the wrapper's base padding
861
+ // and puts the steps on the link, so the whole indent is clickable
862
+ // instead of dead space that still shows hover and press feedback.
863
+ expect(indentOf(general.parentElement!)).toBeNull();
864
+ expect(indentOf(general)).toBe('calc(1 * var(--spacing-6))');
865
+ });
866
+
867
+ it('clips the children group only while it is collapsed', async () => {
868
+ // Nested rows sit flush with the group, so a permanent clip would cut off
869
+ // their focus ring. The group clips for the collapse animation only.
870
+ const user = userEvent.setup();
871
+ render(
872
+ <SideNavItem label="Settings" collapsible>
873
+ <SideNavItem label="General" href="/settings/general" />
874
+ </SideNavItem>,
875
+ );
876
+ const group = () => screen.getByRole('group', {hidden: true});
877
+ expect(declaredOn(group(), 'overflow')).toEqual(['visible']);
878
+ expect(declaredOn(group().firstElementChild!, 'overflow')).toEqual([]);
879
+
880
+ await user.click(screen.getByRole('button', {name: 'Settings'}));
881
+ expect(declaredOn(group(), 'overflow')).toEqual(['hidden']);
882
+ });
883
+
884
+ it('puts the indent on the primary link of a nested actions row', () => {
885
+ render(
886
+ <SideNavItem label="Projects">
887
+ <SideNavItem
888
+ label="Alpha"
889
+ href="/projects/alpha"
890
+ actions={
891
+ <button type="button" aria-label="Alpha actions">
892
+ More
893
+ </button>
894
+ }
895
+ />
896
+ </SideNavItem>,
897
+ );
898
+ const alpha = screen.getByRole('link', {name: 'Alpha'});
899
+ expect(indentOf(alpha.parentElement!)).toBeNull();
900
+ expect(indentOf(alpha)).toBe('calc(1 * var(--spacing-6))');
901
+ });
902
+
903
+ it("composes a caller's style with the indent on a nested row", () => {
904
+ render(
905
+ <SideNavItem label="Settings">
906
+ <SideNavItem
907
+ label="General"
908
+ href="/settings/general"
909
+ style={{color: 'rebeccapurple'}}
910
+ />
911
+ <SideNavItem
912
+ label="Security"
913
+ href="/settings/security"
914
+ style={{color: 'rebeccapurple'}}>
915
+ <SideNavItem label="Keys" href="/settings/security/keys" />
916
+ </SideNavItem>
917
+ </SideNavItem>,
918
+ );
919
+ // Ordinary row: the link is the row.
920
+ const general = screen.getByRole('link', {name: 'General'});
921
+ expect(general.style.color).toBe('rebeccapurple');
922
+ expect(indentOf(general)).toBe(
923
+ 'calc(var(--spacing-2) + 1 * var(--spacing-6))',
924
+ );
925
+ // Split row: the caller's style still lands on the primary link.
926
+ const security = screen.getByRole('link', {name: 'Security'});
927
+ expect(security.style.color).toBe('rebeccapurple');
928
+ expect(indentOf(security)).toBe('calc(1 * var(--spacing-6))');
929
+ });
930
+
931
+ it("lets a caller's inline-start padding replace the indent", () => {
932
+ // The caller's `style` composes after the indent: a caller-set
933
+ // inline-start padding is an inline declaration, so it wins over the
934
+ // indent's class rule on the element that carries the indent, on both
935
+ // the ordinary and the split row path.
936
+ render(
937
+ <SideNavItem label="Settings">
938
+ <SideNavItem
939
+ label="General"
940
+ href="/settings/general"
941
+ style={{paddingInlineStart: '20px'}}
942
+ />
943
+ <SideNavItem
944
+ label="Security"
945
+ href="/settings/security"
946
+ style={{paddingInlineStart: '20px'}}>
947
+ <SideNavItem label="Keys" href="/settings/security/keys" />
948
+ </SideNavItem>
949
+ </SideNavItem>,
950
+ );
951
+ const general = screen.getByRole('link', {name: 'General'});
952
+ expect(general.style.paddingInlineStart).toBe('20px');
953
+ const security = screen.getByRole('link', {name: 'Security'});
954
+ expect(security.style.paddingInlineStart).toBe('20px');
955
+ // A row whose caller sets no padding keeps its indent.
956
+ expect(indentOf(screen.getByRole('link', {name: 'Keys'}))).toBe(
957
+ 'calc(var(--spacing-2) + 2 * var(--spacing-6))',
958
+ );
959
+ });
960
+
961
+ it('indents a small nested row from the small row padding', () => {
962
+ render(
963
+ <SideNavItem label="Settings">
964
+ <SideNavItem label="General" href="/settings/general" size="sm" />
965
+ </SideNavItem>,
966
+ );
967
+ expect(indentOf(screen.getByRole('link', {name: 'General'}))).toBe(
968
+ 'calc(var(--spacing-1) + 1 * var(--spacing-6))',
969
+ );
970
+ });
971
+
972
+ it('does not indent the first level of a collapsed rail flyout', async () => {
973
+ const user = userEvent.setup();
974
+ renderCollapsed(
975
+ <SideNavItem label="Settings" icon={StubIcon}>
976
+ <SideNavItem label="General" href="/settings/general">
977
+ <SideNavItem label="Advanced" href="/settings/general/advanced" />
978
+ </SideNavItem>
979
+ </SideNavItem>,
980
+ );
981
+ await user.click(screen.getByRole('button', {name: 'Settings'}));
982
+
983
+ // jsdom leaves the native popover `display: none`, hence `hidden: true`.
984
+ // The flyout lists the parent's children as its own top level.
985
+ const general = screen.getByRole('link', {name: 'General', hidden: true});
986
+ const advanced = screen.getByRole('link', {name: 'Advanced', hidden: true});
987
+ expect(indentOf(general)).toBeNull();
988
+ expect(indentOf(general.parentElement!)).toBeNull();
989
+ expect(indentOf(advanced)).toBe(
990
+ 'calc(var(--spacing-2) + 1 * var(--spacing-6))',
991
+ );
992
+ });
993
+
831
994
  it('passes data-testid', () => {
832
995
  render(<SideNavItem label="Dashboard" data-testid="nav-item" />);
833
996
  expect(screen.getByTestId('nav-item')).toBeInTheDocument();
@@ -2457,6 +2620,22 @@ function declaredOn(el: Element, prop: string): string[] {
2457
2620
  .filter(value => value != null);
2458
2621
  }
2459
2622
 
2623
+ /**
2624
+ * The nesting indent a row carries, or null for none. The indent is a
2625
+ * runtime StyleX value, so it rides the row's inline style as a custom
2626
+ * property; read the value rather than the generated property name.
2627
+ */
2628
+ function indentOf(el: HTMLElement): string | null {
2629
+ const {style} = el;
2630
+ for (let i = 0; i < style.length; i++) {
2631
+ const value = style.getPropertyValue(style[i]).trim();
2632
+ if (value.includes('var(--spacing-6)')) {
2633
+ return value;
2634
+ }
2635
+ }
2636
+ return null;
2637
+ }
2638
+
2460
2639
  /**
2461
2640
  * The selectors that actually paint the shared ring on `el`, read out of the
2462
2641
  * live stylesheet with StyleX's `:not(#\#)` specificity padding stripped so
@@ -90,7 +90,7 @@ export const docs = {
90
90
  {
91
91
  name: 'children',
92
92
  type: 'ReactNode',
93
- description: 'Sub-items for nesting.',
93
+ description: 'Sub-items for nesting. Nested items span the full width of the nav list, like top-level items; their content is indented one step per nesting level.',
94
94
  slotElements: [
95
95
  {
96
96
  __element: 'SideNavItem',
@@ -213,7 +213,7 @@ export const docsDense = {
213
213
  'Passive right-side content only (badges, counts). Interactive controls go in actions.',
214
214
  actions:
215
215
  'Row-level secondary controls (icon buttons, menus) rendered as siblings of the primary element, after the expand/collapse toggle and before nested children in DOM/focus order. Inherit the row control size via SizeContext (explicit size wins). Hidden when rail collapsed. Passive content goes in endContent; interactive content goes here.',
216
- children: 'Sub-items for nesting.',
216
+ children: 'Sub-items for nesting. Nested rows stay full width; content indents one step per level.',
217
217
  collapsible: 'Enables collapse for items w/ children. true=uncontrolled, object=controlled mode.',
218
218
  size: "Row size variant: 'sm' | 'md' | 'lg'.",
219
219
  },
@@ -17,6 +17,11 @@
17
17
  * `TopNavMenu` use). Hover is a progressive enhancement over the popover's
18
18
  * click behavior and is inert on coarse pointers.
19
19
  *
20
+ * Nested rows span the full width of the nav list, like top-level rows, so
21
+ * their hover and selected fill lines up with the rows above them. The
22
+ * nesting indent sits inside the row as extra inline-start padding, one step
23
+ * per level, tracked through a private depth context.
24
+ *
20
25
  * SYNC: When modified, update these files to stay in sync:
21
26
  * - /packages/core/src/SideNav/SideNav.doc.mjs
22
27
  * - /packages/core/src/SideNav/SideNav.test.tsx
@@ -26,6 +31,8 @@
26
31
  */
27
32
 
28
33
  import {
34
+ createContext,
35
+ use,
29
36
  useCallback,
30
37
  useId,
31
38
  useMemo,
@@ -108,26 +115,45 @@ const styles = stylex.create({
108
115
  gap: spacingVars['--spacing-1'],
109
116
  pointerEvents: 'auto',
110
117
  },
111
- children: {
112
- paddingInlineStart: spacingVars['--spacing-6'],
113
- },
118
+ // The group clips its rows only for the 0fr collapse animation. Nested rows
119
+ // sit flush with the group, so a permanent clip would cut off their focus
120
+ // ring, which paints outside the row. The expanded group therefore stops
121
+ // clipping once it has finished opening: `overflow` is discrete, so it rides
122
+ // the same transition with `allow-discrete` and a delay equal to the open
123
+ // duration, holding `hidden` until the rows' height has settled. Collapsing
124
+ // flips back to `hidden` at once (no delay on the collapsed state), so
125
+ // nothing spills while the group closes.
126
+ //
127
+ // Reduced fallback: a browser without `transition-behavior: allow-discrete`
128
+ // (the tier below current Baseline) cannot delay the switch, so the group
129
+ // stops clipping as soon as it starts opening and the opening rows briefly
130
+ // overlap the row below. The group still opens and the ring still shows.
114
131
  childrenCollapsible: {
115
132
  display: 'grid',
116
133
  gridTemplateRows: '1fr',
117
- transitionProperty: 'grid-template-rows',
134
+ overflow: 'visible',
135
+ transitionProperty: 'grid-template-rows, overflow',
136
+ transitionBehavior: 'allow-discrete',
118
137
  transitionDuration: {
119
- default: durationVars['--duration-medium'],
120
- '@media (prefers-reduced-motion: reduce)': '0s',
138
+ default: `${durationVars['--duration-medium']}, 0s`,
139
+ '@media (prefers-reduced-motion: reduce)': '0s, 0s',
140
+ },
141
+ transitionDelay: {
142
+ default: `0s, ${durationVars['--duration-medium']}`,
143
+ '@media (prefers-reduced-motion: reduce)': '0s, 0s',
121
144
  },
122
145
  transitionTimingFunction: easeVars['--ease-standard'],
123
146
  },
124
147
  childrenCollapsed: {
125
148
  gridTemplateRows: '0fr',
149
+ overflow: 'hidden',
150
+ transitionDelay: '0s, 0s',
126
151
  },
152
+ // No inline padding: nested rows fill the full width of the nav list, and
153
+ // each row carries its own indent (`indentStyles` below). `minHeight: 0`
154
+ // lets the 0fr track shrink this item to nothing; the group clips it.
127
155
  childrenInner: {
128
- overflow: 'hidden',
129
156
  minHeight: 0,
130
- paddingInlineStart: spacingVars['--spacing-6'],
131
157
  },
132
158
  expandChevron: {
133
159
  display: 'inline-flex',
@@ -232,6 +258,35 @@ const styles = stylex.create({
232
258
  },
233
259
  });
234
260
 
261
+ // Nesting indent, drawn inside the row: one `--spacing-6` step per nesting
262
+ // level. The row itself stays full width, so its hover and selected fill
263
+ // matches a top-level row's.
264
+ // - `sm` / `md` — the ordinary row, where the row element is the link or
265
+ // button: its own inline-start padding plus the steps.
266
+ // SYNC: the base padding matches navItemStyles.sm / .md / .lg.
267
+ // - `primary` — the row-wrapper path: the wrapper keeps its base padding and
268
+ // the steps go on the primary link or button, so the whole indent is part
269
+ // of the click target rather than dead space that still shows feedback.
270
+ const indentStyles = stylex.create({
271
+ sm: (depth: number) => ({
272
+ paddingInlineStart: `calc(${spacingVars['--spacing-1']} + ${depth} * ${spacingVars['--spacing-6']})`,
273
+ }),
274
+ md: (depth: number) => ({
275
+ paddingInlineStart: `calc(${spacingVars['--spacing-2']} + ${depth} * ${spacingVars['--spacing-6']})`,
276
+ }),
277
+ primary: (depth: number) => ({
278
+ paddingInlineStart: `calc(${depth} * ${spacingVars['--spacing-6']})`,
279
+ }),
280
+ });
281
+
282
+ /**
283
+ * How many SideNavItems deep the current item sits: 0 at the top level,
284
+ * 1 inside one parent, and so on. A collapsed rail's flyout resets it to 0,
285
+ * since the flyout lists a parent's children as its own top level.
286
+ */
287
+ const SideNavItemDepthContext = createContext(0);
288
+ SideNavItemDepthContext.displayName = 'SideNavItemDepthContext';
289
+
235
290
  /**
236
291
  * Cascaded to the `actions` slot through `SizeContext` so a consumer's row
237
292
  * controls come out the same height as the built-in expand/collapse toggle,
@@ -363,7 +418,9 @@ export interface SideNavItemProps extends BaseProps<HTMLElement> {
363
418
  */
364
419
  actions?: ReactNode;
365
420
  /**
366
- * Sub-items for nesting.
421
+ * Sub-items for nesting. Nested items span the full width of the nav
422
+ * list, like top-level items; their content is indented one step per
423
+ * nesting level.
367
424
  */
368
425
  children?: ReactNode;
369
426
  /**
@@ -455,6 +512,7 @@ export function SideNavItem({
455
512
  const id = useId();
456
513
  const hasChildren = !!children;
457
514
  const itemRef = useRef<HTMLDivElement>(null);
515
+ const depth = use(SideNavItemDepthContext);
458
516
 
459
517
  // Popover for collapsed items with children
460
518
  const popover = usePopover({
@@ -608,7 +666,9 @@ export function SideNavItem({
608
666
  onClick={() => popover.hide()}>
609
667
  <div {...stylex.props(styles.popoverHeader)}>{label}</div>
610
668
  <SideNavCollapseContext value={EXPANDED_COLLAPSE_STATE}>
611
- {children}
669
+ <SideNavItemDepthContext value={0}>
670
+ {children}
671
+ </SideNavItemDepthContext>
612
672
  </SideNavCollapseContext>
613
673
  </div>,
614
674
  {placement: 'end', alignment: 'start', xstyle: styles.popoverGap},
@@ -686,6 +746,14 @@ export function SideNavItem({
686
746
  isSelected && navItemStyles.selected,
687
747
  isDisabled && navItemStyles.disabled,
688
748
  ] as const;
749
+ const rowIndent =
750
+ depth > 0 && indentStyles[size === 'sm' ? 'sm' : 'md'](depth);
751
+ const primaryIndent = depth > 0 && indentStyles.primary(depth);
752
+
753
+ // The indent is a runtime value, so it reaches the element as an inline
754
+ // style. These props are spread after `rest`, so fold the caller's `style`
755
+ // back in (caller wins) rather than letting the indent replace it.
756
+ const callerStyle = {style: rest.style};
689
757
 
690
758
  // Three shapes of the same row appearance:
691
759
  // - `rowProps` — split-action path (toggle, no actions): presentational
@@ -702,7 +770,10 @@ export function SideNavItem({
702
770
  const focusableRowProps = {
703
771
  ...mergeProps(
704
772
  itemThemeProps,
705
- focusOutlineProps.focusVisible(...itemStyleArgs),
773
+ mergeProps(
774
+ focusOutlineProps.focusVisible(...itemStyleArgs, rowIndent),
775
+ callerStyle,
776
+ ),
706
777
  ),
707
778
  ...pressable,
708
779
  };
@@ -748,11 +819,17 @@ export function SideNavItem({
748
819
  onClick={handleClick}
749
820
  {...rest}
750
821
  {...rowPrimaryAriaProps}
751
- {...(hasActions
752
- ? // The wrapper rings for this element; suppressing here is what
753
- // keeps the UA's own ring from painting inside that one.
754
- focusOutlineProps.suppressed(styles.splitAction)
755
- : focusOutlineProps.focusVisible(styles.splitAction))}>
822
+ {...mergeProps(
823
+ hasActions
824
+ ? // The wrapper rings for this element; suppressing here is what
825
+ // keeps the UA's own ring from painting inside that one.
826
+ focusOutlineProps.suppressed(styles.splitAction, primaryIndent)
827
+ : focusOutlineProps.focusVisible(
828
+ styles.splitAction,
829
+ primaryIndent,
830
+ ),
831
+ callerStyle,
832
+ )}>
756
833
  {itemContent}
757
834
  </NavItemElement>
758
835
  {hasIndependentToggle && (
@@ -831,7 +908,9 @@ export function SideNavItem({
831
908
  <span id={`${id}-label`} hidden>
832
909
  {label}
833
910
  </span>
834
- {children}
911
+ <SideNavItemDepthContext value={depth + 1}>
912
+ {children}
913
+ </SideNavItemDepthContext>
835
914
  </div>
836
915
  </div>
837
916
  )}