@baukit/navigation 0.7.4 → 0.8.0

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.
@@ -60,7 +60,7 @@ function Fixture() {
60
60
  }}
61
61
  >
62
62
  <h1>Navigation fixture</h1>
63
- <SectionPicker item={section} pathname="/progress/history" />
63
+ <SectionPicker closeLabel="Close" item={section} pathname="/progress/history" />
64
64
  <button type="button" style={{ minWidth: 44, minHeight: 44 }}>
65
65
  Primary action
66
66
  </button>
@@ -234,7 +234,7 @@ it('keeps a long compact section menu between its picker and the bottom bar', as
234
234
  profile={{ label: 'Account', initials: 'AB', href: '/profile' }}
235
235
  />
236
236
  <main style={{ padding: 8, paddingTop: 200 }}>
237
- <SectionPicker item={cost} pathname="/cost/1" />
237
+ <SectionPicker closeLabel="Close" item={cost} pathname="/cost/1" />
238
238
  </main>
239
239
  </>,
240
240
  );
@@ -243,17 +243,26 @@ it('keeps a long compact section menu between its picker and the bottom bar', as
243
243
  const trigger = page.getByRole('button', { name: 'Cost, Cost page 1' });
244
244
  await act(async () => trigger.click());
245
245
  const menu = page.getByRole('menu', { name: 'Cost' }).element();
246
+ const panel = menu.closest('.bk-navigation-menu');
247
+ if (panel === null) throw new Error('Menu panel did not render');
248
+ const scroll = menu.querySelector<HTMLElement>('.bk-navigation-menu-items');
249
+ if (scroll === null) throw new Error('Menu scroll container did not render');
250
+ const close = page.getByRole('button', { name: 'Close', exact: true });
246
251
  const navigation = document.querySelector('.bk-navigation');
247
252
  if (navigation === null) throw new Error('Bottom navigation did not render');
248
- function expectBounds() {
249
- const menuBox = menu.getBoundingClientRect();
253
+ const expectBounds = () => {
254
+ const menuBox = panel.getBoundingClientRect();
250
255
  expect(menuBox.top).toBeGreaterThanOrEqual(
251
256
  trigger.element().getBoundingClientRect().bottom + 8,
252
257
  );
253
- expect(menuBox.bottom).toBeLessThanOrEqual(navigation?.getBoundingClientRect().top ?? 0);
254
- expect(menu.scrollHeight).toBeGreaterThan(menu.clientHeight);
255
- expect(getComputedStyle(menu).overflowY).toBe('auto');
256
- }
258
+ expect(menuBox.bottom).toBeLessThanOrEqual(navigation.getBoundingClientRect().top);
259
+ expect(scroll.scrollHeight).toBeGreaterThan(scroll.clientHeight);
260
+ expect(getComputedStyle(scroll).overflowY).toBe('auto');
261
+ const closeBox = close.element().getBoundingClientRect();
262
+ expect(closeBox.top).toBeGreaterThanOrEqual(scroll.getBoundingClientRect().bottom);
263
+ expect(closeBox.bottom).toBeLessThanOrEqual(menuBox.bottom);
264
+ expect(closeBox.height).toBeGreaterThanOrEqual(44);
265
+ };
257
266
  expectBounds();
258
267
  await act(async () => userEvent.keyboard('{End}'));
259
268
  const last = page.getByRole('menuitem', { name: 'Cost page 14' }).element();
@@ -261,7 +270,7 @@ it('keeps a long compact section menu between its picker and the bottom bar', as
261
270
  expect(last.getBoundingClientRect().bottom).toBeLessThanOrEqual(
262
271
  menu.getBoundingClientRect().bottom,
263
272
  );
264
- expect(menu.scrollTop).toBeGreaterThan(0);
273
+ expect(scroll.scrollTop).toBeGreaterThan(0);
265
274
  await act(async () => {
266
275
  await page.viewport(320, 480);
267
276
  await new Promise<void>((resolve) =>
@@ -273,7 +282,7 @@ it('keeps a long compact section menu between its picker and the bottom bar', as
273
282
  );
274
283
  });
275
284
  await expect
276
- .poll(() => menu.getBoundingClientRect().bottom <= navigation.getBoundingClientRect().top)
285
+ .poll(() => panel.getBoundingClientRect().bottom <= navigation.getBoundingClientRect().top)
277
286
  .toBe(true);
278
287
  expectBounds();
279
288
  const main = host.querySelector('main');
@@ -289,9 +298,14 @@ it('keeps a long compact section menu between its picker and the bottom bar', as
289
298
  );
290
299
  });
291
300
  await expect
292
- .poll(() => menu.getBoundingClientRect().bottom <= navigation.getBoundingClientRect().top)
301
+ .poll(() => panel.getBoundingClientRect().bottom <= navigation.getBoundingClientRect().top)
293
302
  .toBe(true);
294
303
  expectBounds();
304
+ await expect.element(close).toBeVisible();
305
+ await act(async () => {
306
+ await close.click();
307
+ });
308
+ await expect.element(page.getByRole('menu')).not.toBeInTheDocument();
295
309
  });
296
310
 
297
311
  it('ellipsizes long labels inside all six compact targets at 320 pixels', async () => {
@@ -467,7 +481,7 @@ it('uses the body font in a standalone section picker', async () => {
467
481
  document.body.append(host);
468
482
  root = createRoot(host);
469
483
  await act(() => {
470
- root?.render(<SectionPicker item={section} pathname="/progress" />);
484
+ root?.render(<SectionPicker closeLabel="Close" item={section} pathname="/progress" />);
471
485
  return Promise.resolve();
472
486
  });
473
487
  const picker = host.querySelector('.bk-navigation-picker');
@@ -475,3 +489,207 @@ it('uses the body font in a standalone section picker', async () => {
475
489
  if (picker === null) throw new Error('Section picker is missing');
476
490
  expect(getComputedStyle(picker).fontFamily).toBe(exampleTokens.typography.family.body);
477
491
  });
492
+
493
+ function SlotFixture({
494
+ brandLabel = 'Baukit',
495
+ accessoryLabel = 'Workout active',
496
+ dangerLabel = 'Delete account',
497
+ closeLabel = 'Menü schließen',
498
+ }: {
499
+ readonly brandLabel?: string;
500
+ readonly accessoryLabel?: string;
501
+ readonly dangerLabel?: string;
502
+ readonly closeLabel?: string;
503
+ } = {}) {
504
+ const [collapsed, setCollapsed] = useState(false);
505
+ const [barHeight, setBarHeight] = useState(64);
506
+ return (
507
+ <>
508
+ <AppNavigation
509
+ {...labels}
510
+ closeLabel={closeLabel}
511
+ items={items}
512
+ pathname="/delete"
513
+ collapsed={collapsed}
514
+ onCollapsedChange={setCollapsed}
515
+ onBarHeightChange={setBarHeight}
516
+ renderBrand={({ collapsed: small }) => <strong>{small ? 'B' : brandLabel}</strong>}
517
+ renderAccessory={({ collapsed: small }) => (
518
+ <span role="status" aria-label="Workout status">
519
+ {small ? '●' : accessoryLabel}
520
+ </span>
521
+ )}
522
+ profile={{
523
+ label: 'Account',
524
+ initials: 'AB',
525
+ menu: [
526
+ { id: 'settings', label: 'Settings', href: '/settings' },
527
+ { id: 'delete', label: dangerLabel, tone: 'danger', href: '/delete' },
528
+ { id: 'signout', label: 'Sign out', tone: 'danger', onSelect: () => undefined },
529
+ ],
530
+ }}
531
+ />
532
+ <main
533
+ style={{
534
+ marginLeft: window.innerWidth >= 1024 ? (collapsed ? 76 : 280) : 0,
535
+ paddingBottom: barHeight,
536
+ }}
537
+ >
538
+ <h1 style={{ overflowWrap: 'anywhere' }}>Navigation with slots</h1>
539
+ <SectionPicker closeLabel="Auswahl schließen" item={section} pathname="/progress" />
540
+ </main>
541
+ </>
542
+ );
543
+ }
544
+ it.each(
545
+ [1, 2].flatMap((scale) =>
546
+ [320, 1024].flatMap((width) => ['light', 'dark'].map((theme) => ({ scale, width, theme }))),
547
+ ),
548
+ )(
549
+ 'keeps slots and danger menus accessible at $width, font scale $scale, $theme',
550
+ async ({ scale, width, theme }) => {
551
+ await page.viewport(width, 900);
552
+ document.documentElement.lang = 'de';
553
+ document.documentElement.dataset['theme'] = theme;
554
+ styles = document.createElement('style');
555
+ styles.textContent = `${toCssVariables(exampleTokens)} ${stylesheet} html{font-size:${String(16 * scale)}px} body{margin:0;background:var(--bk-color-background-primary);color:var(--bk-color-text-primary)}`;
556
+ document.head.append(styles);
557
+ host = document.createElement('div');
558
+ document.body.append(host);
559
+ root = createRoot(host);
560
+ await act(() => {
561
+ root?.render(<SlotFixture />);
562
+ return Promise.resolve();
563
+ });
564
+ const navigation = page.getByTestId('primary-navigation').element();
565
+ const slots = navigation.querySelector('.bk-navigation-slots');
566
+ if (slots === null) throw new Error('Slots are missing');
567
+ expect(
568
+ page.getByText('Baukit', { exact: true }).element().getBoundingClientRect().width,
569
+ ).toBeGreaterThan(0);
570
+ const brandLines = document.createRange();
571
+ brandLines.selectNodeContents(page.getByText('Baukit', { exact: true }).element());
572
+ expect(brandLines.getClientRects()).toHaveLength(1);
573
+ expect(page.getByRole('status', { name: 'Workout status' }).element().textContent).toBe(
574
+ 'Workout active',
575
+ );
576
+ const home = page.getByRole('link', { name: 'Home' }).element();
577
+ expect(home.getBoundingClientRect().top).toBeGreaterThanOrEqual(
578
+ slots.getBoundingClientRect().bottom,
579
+ );
580
+ for (const slot of slots.children) {
581
+ const bounds = slot.getBoundingClientRect();
582
+ expect(bounds.left).toBeGreaterThanOrEqual(navigation.getBoundingClientRect().left);
583
+ expect(bounds.right).toBeLessThanOrEqual(navigation.getBoundingClientRect().right);
584
+ }
585
+ if (width === 320) {
586
+ const main = host.querySelector('main');
587
+ if (main === null) throw new Error('Content is missing');
588
+ await expect
589
+ .poll(() => Number.parseFloat(getComputedStyle(main).paddingBottom))
590
+ .toBe(navigation.getBoundingClientRect().height);
591
+ const iconBox = home.querySelector('.bk-navigation-icon')?.getBoundingClientRect();
592
+ const labelBox = home.querySelector('.bk-navigation-label')?.getBoundingClientRect();
593
+ if (iconBox === undefined || labelBox === undefined)
594
+ throw new Error('Icon or label is missing');
595
+ expect(labelBox.top).toBeGreaterThanOrEqual(iconBox.bottom);
596
+ expect(navigation.getBoundingClientRect().height).toBeGreaterThan(64);
597
+ } else {
598
+ await act(async () => {
599
+ await page.getByRole('button', { name: 'Collapse navigation' }).click();
600
+ });
601
+ await expect.element(page.getByText('B', { exact: true })).toBeVisible();
602
+ expect(page.getByRole('status', { name: 'Workout status' }).element().textContent).toBe('●');
603
+ }
604
+ const account = page.getByRole('button', { name: 'Account' });
605
+ await act(async () => {
606
+ await account.click();
607
+ });
608
+ const danger = page.getByRole('menuitem', { name: 'Delete account' }).element();
609
+ expect(getComputedStyle(danger).fontSize).toBe(`${String(16 * scale)}px`);
610
+ const expectedColor = exampleTokens.color.status.danger[theme === 'dark' ? 'dark' : 'light'];
611
+ const probe = document.createElement('span');
612
+ probe.style.color = expectedColor;
613
+ host.append(probe);
614
+ expect(getComputedStyle(danger).color).toBe(getComputedStyle(probe).color);
615
+ probe.remove();
616
+ expect((await axe.run(host)).violations).toEqual([]);
617
+ await act(async () => {
618
+ await userEvent.keyboard('{End}');
619
+ });
620
+ await expect.element(page.getByRole('menuitem', { name: 'Sign out' })).toHaveFocus();
621
+ await act(async () => {
622
+ await page.getByRole('button', { name: 'Menü schließen' }).click();
623
+ });
624
+ await expect.element(account).toHaveFocus();
625
+ await expect.element(page.getByRole('menu')).not.toBeInTheDocument();
626
+ expect(document.documentElement.scrollWidth).toBeLessThanOrEqual(width);
627
+ },
628
+ );
629
+
630
+ it.each([320, 1024])('wraps long slot and menu text at $0 px and font scale 2', async (width) => {
631
+ await page.viewport(width, 900);
632
+ document.documentElement.lang = 'de';
633
+ styles = document.createElement('style');
634
+ styles.textContent = `${toCssVariables(exampleTokens)} ${stylesheet} html{font-size:32px} body{margin:0}`;
635
+ document.head.append(styles);
636
+ host = document.createElement('div');
637
+ document.body.append(host);
638
+ root = createRoot(host);
639
+ const dangerLabel = 'Kontozugriffdauerhaftbeenden';
640
+ const closeLabel = 'MenüschließenundzurÜbersichtzurückkehren';
641
+ await act(() => {
642
+ root?.render(
643
+ <SlotFixture
644
+ brandLabel="BaukitTrainingsverwaltung"
645
+ accessoryLabel="Kraftausdauertrainingläuft"
646
+ dangerLabel={dangerLabel}
647
+ closeLabel={closeLabel}
648
+ />,
649
+ );
650
+ return Promise.resolve();
651
+ });
652
+ const navigation = page.getByTestId('primary-navigation').element();
653
+ const slots = navigation.querySelector('.bk-navigation-slots');
654
+ if (slots === null) throw new Error('Slots are missing');
655
+ for (const slot of slots.children) {
656
+ const bounds = slot.getBoundingClientRect();
657
+ expect(bounds.left).toBeGreaterThanOrEqual(navigation.getBoundingClientRect().left);
658
+ expect(bounds.right).toBeLessThanOrEqual(navigation.getBoundingClientRect().right);
659
+ expect(slot.scrollWidth).toBeLessThanOrEqual(slot.clientWidth);
660
+ const text = document.createRange();
661
+ text.selectNodeContents(slot);
662
+ expect(text.getClientRects().length).toBeGreaterThan(1);
663
+ for (const line of text.getClientRects()) {
664
+ expect(line.left).toBeGreaterThanOrEqual(bounds.left);
665
+ expect(line.right).toBeLessThanOrEqual(bounds.right);
666
+ }
667
+ }
668
+ if (width === 320) {
669
+ const main = host.querySelector('main');
670
+ if (main === null) throw new Error('Content is missing');
671
+ await expect
672
+ .poll(() => Number.parseFloat(getComputedStyle(main).paddingBottom))
673
+ .toBe(navigation.getBoundingClientRect().height);
674
+ expect(
675
+ page.getByRole('link', { name: 'Home' }).element().getBoundingClientRect().top,
676
+ ).toBeGreaterThanOrEqual(slots.getBoundingClientRect().bottom);
677
+ }
678
+ await act(async () => {
679
+ await page.getByRole('button', { name: 'Account' }).click();
680
+ });
681
+ const danger = page.getByRole('menuitem', { name: dangerLabel }).element();
682
+ const close = page.getByRole('button', { name: closeLabel }).element();
683
+ for (const control of [danger, close]) {
684
+ expect(control.scrollWidth).toBeLessThanOrEqual(control.clientWidth);
685
+ const text = document.createRange();
686
+ text.selectNodeContents(control);
687
+ expect(text.getClientRects().length).toBeGreaterThan(1);
688
+ const bounds = control.getBoundingClientRect();
689
+ for (const line of text.getClientRects()) {
690
+ expect(line.left).toBeGreaterThanOrEqual(bounds.left);
691
+ expect(line.right).toBeLessThanOrEqual(bounds.right);
692
+ }
693
+ }
694
+ expect(document.documentElement.scrollWidth).toBeLessThanOrEqual(width);
695
+ });
package/src/web.css CHANGED
@@ -13,6 +13,8 @@
13
13
  --bk-navigation-rail-width: 280px;
14
14
  --bk-navigation-collapsed-width: 76px;
15
15
  --bk-navigation-bar-height: 64px;
16
+ --bk-navigation-bar-padding: 5px;
17
+ --bk-navigation-bar-border: 1px;
16
18
  position: fixed;
17
19
  z-index: 5;
18
20
  display: flex;
@@ -30,9 +32,11 @@
30
32
  grid-auto-columns: minmax(44px, 1fr);
31
33
  inset: auto 0 0;
32
34
  min-height: calc(var(--bk-navigation-bar-height) + env(safe-area-inset-bottom));
33
- padding: 5px calc(5px + env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom))
34
- calc(5px + env(safe-area-inset-left));
35
- border-top: 1px solid var(--bk-color-border-primary);
35
+ padding: var(--bk-navigation-bar-padding)
36
+ calc(var(--bk-navigation-bar-padding) + env(safe-area-inset-right))
37
+ calc(var(--bk-navigation-bar-padding) + env(safe-area-inset-bottom))
38
+ calc(var(--bk-navigation-bar-padding) + env(safe-area-inset-left));
39
+ border-top: var(--bk-navigation-bar-border) solid var(--bk-color-border-primary);
36
40
  }
37
41
  .bk-navigation-items {
38
42
  min-height: 0;
@@ -48,7 +52,8 @@
48
52
  }
49
53
  .bk-navigation-item,
50
54
  .bk-navigation-toggle,
51
- .bk-navigation-picker-trigger {
55
+ .bk-navigation-picker-trigger,
56
+ .bk-navigation-menu-close {
52
57
  display: flex;
53
58
  align-items: center;
54
59
  gap: calc(var(--bk-space-small) * 1px);
@@ -77,7 +82,8 @@
77
82
  }
78
83
  .bk-navigation-item:focus-visible,
79
84
  .bk-navigation-toggle:focus-visible,
80
- .bk-navigation-picker-trigger:focus-visible {
85
+ .bk-navigation-picker-trigger:focus-visible,
86
+ .bk-navigation-menu-close:focus-visible {
81
87
  outline: 3px solid var(--bk-color-focus-ring);
82
88
  outline-offset: 2px;
83
89
  }
@@ -176,7 +182,10 @@
176
182
  right: 0;
177
183
  width: min(280px, calc(100vw - 16px));
178
184
  max-height: calc(100dvh - 100px);
179
- overflow-y: auto;
185
+ display: flex;
186
+ flex-direction: column;
187
+ overflow-wrap: anywhere;
188
+ overflow: hidden;
180
189
  padding: 8px;
181
190
  color: var(--bk-color-text-primary);
182
191
  background: var(--bk-color-background-primary);
@@ -189,7 +198,8 @@
189
198
  right: auto;
190
199
  left: calc(100% + 8px);
191
200
  }
192
- .bk-navigation-menu .bk-navigation-item {
201
+ .bk-navigation-menu .bk-navigation-item,
202
+ .bk-navigation[data-layout='bar'] .bk-navigation-menu .bk-navigation-item {
193
203
  height: auto;
194
204
  flex-direction: row;
195
205
  justify-content: flex-start;
@@ -248,6 +258,7 @@
248
258
  font-weight: normal;
249
259
  }
250
260
  .bk-navigation-menu-profile {
261
+ flex-shrink: 0;
251
262
  padding: 8px;
252
263
  border-bottom: 1px solid var(--bk-color-border-primary);
253
264
  }
@@ -255,3 +266,56 @@
255
266
  .bk-navigation[data-collapsed='true'] .bk-navigation-profile-copy {
256
267
  display: none;
257
268
  }
269
+
270
+ .bk-navigation-menu .bk-navigation-item[data-tone='danger'] {
271
+ color: var(--bk-color-status-danger);
272
+ background: var(--bk-color-background-primary);
273
+ }
274
+ .bk-navigation-menu-items {
275
+ min-height: 0;
276
+ overflow-y: auto;
277
+ padding: 5px;
278
+ }
279
+ .bk-navigation-menu-content {
280
+ display: flex;
281
+ flex-direction: column;
282
+ min-height: 0;
283
+ }
284
+ .bk-navigation-menu-close {
285
+ flex-shrink: 0;
286
+ width: 100%;
287
+ justify-content: center;
288
+ border-top: 1px solid var(--bk-color-border-primary);
289
+ }
290
+ .bk-navigation-slots {
291
+ flex: none;
292
+ display: grid;
293
+ gap: calc(var(--bk-space-small) * 1px);
294
+ padding: calc(var(--bk-space-small) * 1px);
295
+ min-width: 0;
296
+ }
297
+ .bk-navigation-brand,
298
+ .bk-navigation-accessory {
299
+ min-width: 0;
300
+ max-width: 100%;
301
+ overflow-wrap: anywhere;
302
+ }
303
+ .bk-navigation[data-layout='bar'] .bk-navigation-slots {
304
+ grid-column: 1 / -1;
305
+ grid-row: 1;
306
+ display: flex;
307
+ flex-wrap: wrap;
308
+ align-items: center;
309
+ justify-content: space-between;
310
+ }
311
+ .bk-navigation[data-layout='bar'] .bk-navigation-brand {
312
+ flex-shrink: 0;
313
+ }
314
+ .bk-navigation[data-layout='bar']:has(.bk-navigation-slots) .bk-navigation-section,
315
+ .bk-navigation[data-layout='bar']:has(.bk-navigation-slots) .bk-navigation-profile {
316
+ grid-row: 2;
317
+ min-height: calc(
318
+ var(--bk-navigation-bar-height) - 2 * var(--bk-navigation-bar-padding) -
319
+ var(--bk-navigation-bar-border)
320
+ );
321
+ }
package/src/web.test.tsx CHANGED
@@ -259,7 +259,9 @@ it('handles profile menu focus, disabled items, actions, Escape and outside clic
259
259
  });
260
260
  it('lets a picker select a section page directly', () => {
261
261
  const navigate = vi.fn();
262
- render(<SectionPicker item={section} pathname="/progress" onNavigate={navigate} />);
262
+ render(
263
+ <SectionPicker closeLabel="Close" item={section} pathname="/progress" onNavigate={navigate} />,
264
+ );
263
265
  fireEvent.click(screen.getByRole('button', { name: 'Progress, Overview' }));
264
266
  fireEvent.click(screen.getByRole('menuitem', { name: 'History' }));
265
267
  expect(navigate).toHaveBeenCalledWith('/progress/history', expect.anything());
@@ -353,6 +355,7 @@ it('uses product labels for the navigation and collapse controls', () => {
353
355
  items={items}
354
356
  pathname="/"
355
357
  width={1024}
358
+ closeLabel="Schließen"
356
359
  label="Hauptnavigation"
357
360
  collapseLabel="Einklappen"
358
361
  expandLabel="Ausklappen"
@@ -481,3 +484,105 @@ it.each([600, 1024])('enters the visible parent of a hidden active child at widt
481
484
  expect(screen.getByRole('link', { name: 'Home' }).tabIndex).toBe(-1);
482
485
  expect(screen.queryByRole('link', { name: 'Charts' })).toBeNull();
483
486
  });
487
+
488
+ it('closes both menus with a visible localized control and restores focus', () => {
489
+ const action = vi.fn();
490
+ render(
491
+ <>
492
+ <AppNavigation
493
+ {...labels}
494
+ closeLabel="Menü schließen"
495
+ items={items}
496
+ pathname="/"
497
+ profile={{
498
+ label: 'Account',
499
+ initials: 'AB',
500
+ menu: [{ id: 'signout', label: 'Sign out', onSelect: action }],
501
+ }}
502
+ />
503
+ <SectionPicker item={section} pathname="/progress" closeLabel="Auswahl schließen" />
504
+ </>,
505
+ );
506
+ for (const [triggerName, closeName] of [
507
+ ['Account', 'Menü schließen'],
508
+ ['Progress, Overview', 'Auswahl schließen'],
509
+ ] as const) {
510
+ const trigger = screen.getByRole('button', { name: triggerName });
511
+ fireEvent.click(trigger);
512
+ const close = screen.getByRole('button', { name: closeName });
513
+ expect(close.textContent).toBe(closeName);
514
+ expect(screen.getByRole('menu').contains(close)).toBe(false);
515
+ fireEvent.click(close);
516
+ expect(screen.queryByRole('menu')).toBeNull();
517
+ expect(document.activeElement).toBe(trigger);
518
+ }
519
+ expect(action).not.toHaveBeenCalled();
520
+ });
521
+ it('marks danger actions and links without changing menu keyboard order', () => {
522
+ render(
523
+ <AppNavigation
524
+ {...labels}
525
+ items={items}
526
+ pathname="/delete"
527
+ profile={{
528
+ label: 'Account',
529
+ initials: 'AB',
530
+ menu: [
531
+ { id: 'settings', label: 'Settings', href: '/settings' },
532
+ { id: 'delete', label: 'Delete account', href: '/delete', tone: 'danger' },
533
+ { id: 'signout', label: 'Sign out', onSelect: vi.fn(), tone: 'danger' },
534
+ ],
535
+ }}
536
+ />,
537
+ );
538
+ fireEvent.click(screen.getByRole('button', { name: 'Account' }));
539
+ const settings = screen.getByRole('menuitem', { name: 'Settings' });
540
+ expect(settings.hasAttribute('data-tone')).toBe(false);
541
+ fireEvent.keyDown(settings, { key: 'End' });
542
+ const signout = screen.getByRole('menuitem', { name: 'Sign out' });
543
+ expect(document.activeElement).toBe(signout);
544
+ expect(signout.getAttribute('data-tone')).toBe('danger');
545
+ expect(screen.getByRole('menuitem', { name: 'Delete account' }).getAttribute('data-tone')).toBe(
546
+ 'danger',
547
+ );
548
+ expect(
549
+ screen.getByRole('menuitem', { name: 'Delete account' }).getAttribute('aria-current'),
550
+ ).toBe('page');
551
+ });
552
+ it.each([
553
+ { width: 320, collapsed: false },
554
+ { width: 1024, collapsed: false },
555
+ { width: 1024, collapsed: true },
556
+ ])('renders web slots at $width, collapsed=$collapsed', ({ width, collapsed }) => {
557
+ const brand = vi.fn(({ collapsed: small }: { collapsed: boolean }) => (
558
+ <span>{small ? 'B' : 'Baukit'}</span>
559
+ ));
560
+ const accessory = vi.fn(() => <span role="status">Workout active</span>);
561
+ render(
562
+ <AppNavigation
563
+ {...labels}
564
+ items={items}
565
+ pathname="/"
566
+ width={width}
567
+ collapsed={collapsed}
568
+ renderBrand={brand}
569
+ renderAccessory={accessory}
570
+ />,
571
+ );
572
+ expect(brand).toHaveBeenCalledWith({ layout: width === 320 ? 'bar' : 'rail', collapsed });
573
+ expect(accessory).toHaveBeenCalledWith({ layout: width === 320 ? 'bar' : 'rail', collapsed });
574
+ expect(
575
+ screen.getByText(collapsed ? 'B' : 'Baukit').closest('.bk-navigation-brand'),
576
+ ).not.toBeNull();
577
+ expect(within(screen.getByRole('navigation')).getByRole('status').textContent).toBe(
578
+ 'Workout active',
579
+ );
580
+ });
581
+
582
+ it('omits web slots when their conditional content disappears', () => {
583
+ const props = { ...labels, items, pathname: '/', width: 320 };
584
+ const { rerender } = render(<AppNavigation {...props} renderBrand={() => <span>Baukit</span>} />);
585
+ expect(screen.getByText('Baukit')).toBeTruthy();
586
+ rerender(<AppNavigation {...props} renderBrand={() => null} renderAccessory={() => false} />);
587
+ expect(screen.getByRole('navigation').querySelector('.bk-navigation-slots')).toBeNull();
588
+ });