@aleph-alpha/ui-library 6.3.3 → 6.3.4

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 (50) hide show
  1. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  2. package/dist/system/components/UiStepper/context.d.ts +8 -0
  3. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  4. package/dist/system/icons/story-sidebar-icons.json +7 -0
  5. package/dist/system/lib.js +14776 -14598
  6. package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
  7. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
  8. package/dist/system/story-sidebar-icons.json +7 -0
  9. package/package.json +1 -1
  10. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  11. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  12. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  13. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  14. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  15. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  16. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  17. package/src/components/UiFileUploadBox/types.ts +8 -5
  18. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  19. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  20. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  21. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  22. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
  23. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  24. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  25. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  26. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  27. package/src/components/UiStepper/UiStepper.vue +14 -1
  28. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  29. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  30. package/src/components/UiStepper/context.ts +10 -0
  31. package/src/components/core/calendar/Calendar.vue +234 -2
  32. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  33. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  34. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  35. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  36. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  37. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  38. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  39. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  40. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  41. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  42. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  43. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  44. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  45. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  46. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  47. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  48. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  49. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  50. package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
2
3
  import { ref, watch } from 'vue';
3
4
  import {
4
5
  UiNavigationMenu,
@@ -11,6 +12,11 @@ import {
11
12
  navigationMenuTriggerStyle,
12
13
  } from './index';
13
14
 
15
+ // Module-level spies shared by the hidden test stories; each play function
16
+ // clears them first so runs stay independent.
17
+ const onUpdate = fn();
18
+ const onSelect = fn();
19
+
14
20
  function useStoryModel(args: { modelValue?: string }) {
15
21
  const value = ref(args.modelValue);
16
22
  watch(
@@ -1212,3 +1218,720 @@ export const WithActivePage: Story = {
1212
1218
  },
1213
1219
  },
1214
1220
  };
1221
+
1222
+ /**
1223
+ * Shared fixture for the hidden test stories: a named top-level navigation
1224
+ * with a plain link, an openable "Products" panel, a disabled "Admin"
1225
+ * trigger, a second "Resources" panel, and an active "Pricing" link marked
1226
+ * as the current page. Hover-opening is disabled so pointer interactions in
1227
+ * tests are deterministic (click/keyboard only).
1228
+ */
1229
+ function renderTestMenu() {
1230
+ return {
1231
+ components: {
1232
+ UiNavigationMenu,
1233
+ UiNavigationMenuList,
1234
+ UiNavigationMenuItem,
1235
+ UiNavigationMenuTrigger,
1236
+ UiNavigationMenuContent,
1237
+ UiNavigationMenuLink,
1238
+ },
1239
+ setup() {
1240
+ return { onUpdate, onSelect, navigationMenuTriggerStyle };
1241
+ },
1242
+ template: `<UiNavigationMenu
1243
+ aria-label="Main navigation"
1244
+ :disable-hover-trigger="true"
1245
+ @update:model-value="onUpdate"
1246
+ >
1247
+ <UiNavigationMenuList>
1248
+ <UiNavigationMenuItem>
1249
+ <UiNavigationMenuLink href="#home" :class="navigationMenuTriggerStyle()">Home</UiNavigationMenuLink>
1250
+ </UiNavigationMenuItem>
1251
+
1252
+ <UiNavigationMenuItem value="products">
1253
+ <UiNavigationMenuTrigger>Products</UiNavigationMenuTrigger>
1254
+ <UiNavigationMenuContent>
1255
+ <ul class="grid w-[300px]">
1256
+ <li>
1257
+ <UiNavigationMenuLink href="#analytics" @select="onSelect">
1258
+ <div class="body-14-medium">Analytics</div>
1259
+ <p class="body-14-regular text-content-on-surface-muted">Track your metrics</p>
1260
+ </UiNavigationMenuLink>
1261
+ </li>
1262
+ <li>
1263
+ <UiNavigationMenuLink href="#automation">
1264
+ <div class="body-14-medium">Automation</div>
1265
+ <p class="body-14-regular text-content-on-surface-muted">Streamline workflows</p>
1266
+ </UiNavigationMenuLink>
1267
+ </li>
1268
+ </ul>
1269
+ </UiNavigationMenuContent>
1270
+ </UiNavigationMenuItem>
1271
+
1272
+ <UiNavigationMenuItem value="admin">
1273
+ <UiNavigationMenuTrigger disabled>Admin</UiNavigationMenuTrigger>
1274
+ <UiNavigationMenuContent>
1275
+ <ul class="grid w-[300px]">
1276
+ <li>
1277
+ <UiNavigationMenuLink href="#users">Users</UiNavigationMenuLink>
1278
+ </li>
1279
+ </ul>
1280
+ </UiNavigationMenuContent>
1281
+ </UiNavigationMenuItem>
1282
+
1283
+ <UiNavigationMenuItem value="resources">
1284
+ <UiNavigationMenuTrigger>Resources</UiNavigationMenuTrigger>
1285
+ <UiNavigationMenuContent>
1286
+ <ul class="grid w-[300px]">
1287
+ <li>
1288
+ <UiNavigationMenuLink href="#docs">Documentation</UiNavigationMenuLink>
1289
+ </li>
1290
+ </ul>
1291
+ </UiNavigationMenuContent>
1292
+ </UiNavigationMenuItem>
1293
+
1294
+ <UiNavigationMenuItem>
1295
+ <UiNavigationMenuLink href="#pricing" :active="true" :class="navigationMenuTriggerStyle()">Pricing</UiNavigationMenuLink>
1296
+ </UiNavigationMenuItem>
1297
+ </UiNavigationMenuList>
1298
+ </UiNavigationMenu>`,
1299
+ };
1300
+ }
1301
+
1302
+ /**
1303
+ * Selection behaviour: opening a menu reveals its items and emits
1304
+ * `update:modelValue`, selecting a link activates it and dismisses the panel,
1305
+ * and a disabled trigger refuses to open.
1306
+ */
1307
+ export const SelectionBehavior: Story = {
1308
+ name: 'test - Selection Behavior',
1309
+ tags: ['!dev', '!autodocs'],
1310
+ parameters: {
1311
+ chromatic: { disableSnapshot: true },
1312
+ docs: {
1313
+ description: {
1314
+ story:
1315
+ 'Open and close panels with the pointer and confirm the disabled guard holds.',
1316
+ },
1317
+ },
1318
+ },
1319
+ render: renderTestMenu,
1320
+ play: async ({ canvasElement, step }) => {
1321
+ // Scenario (UiNavigationMenu): a pointer user opens the Products panel,
1322
+ // follows a link inside it, toggles the panel closed, and bounces off the
1323
+ // disabled Admin trigger.
1324
+ onUpdate.mockClear();
1325
+ onSelect.mockClear();
1326
+ const canvas = within(canvasElement);
1327
+ const products = canvas.getByRole('button', { name: 'Products' });
1328
+ const admin = canvas.getByRole('button', { name: 'Admin' });
1329
+
1330
+ await step(
1331
+ 'interaction: opening a menu reveals its items and emits update:modelValue',
1332
+ async () => {
1333
+ await userEvent.click(products);
1334
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1335
+ const analytics = await canvas.findByRole('link', {
1336
+ name: /Analytics/,
1337
+ });
1338
+ await expect(analytics).toBeVisible();
1339
+ await expect(onUpdate).toHaveBeenLastCalledWith('products');
1340
+ },
1341
+ );
1342
+
1343
+ await step(
1344
+ 'interaction: selecting a link emits select and dismisses the panel',
1345
+ async () => {
1346
+ await userEvent.click(canvas.getByRole('link', { name: /Analytics/ }));
1347
+ await expect(onSelect).toHaveBeenCalledTimes(1);
1348
+ await waitFor(async () => {
1349
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1350
+ });
1351
+ },
1352
+ );
1353
+
1354
+ await step(
1355
+ 'interaction: clicking an open trigger closes its panel again',
1356
+ async () => {
1357
+ await userEvent.click(products);
1358
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1359
+ await userEvent.click(products);
1360
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1361
+ await expect(onUpdate).toHaveBeenLastCalledWith('');
1362
+ },
1363
+ );
1364
+
1365
+ await step(
1366
+ 'interaction: a disabled trigger does not activate (WCAG 4.1.2)',
1367
+ async () => {
1368
+ await expect(admin).toBeDisabled();
1369
+ await userEvent.click(admin, { pointerEventsCheck: 0 });
1370
+ await expect(admin).toHaveAttribute('aria-expanded', 'false');
1371
+ await expect(
1372
+ canvas.queryByRole('link', { name: 'Users' }),
1373
+ ).not.toBeInTheDocument();
1374
+ },
1375
+ );
1376
+
1377
+ await step(
1378
+ 'interaction: the current page link is marked with aria-current',
1379
+ async () => {
1380
+ await expect(
1381
+ canvas.getByRole('link', { name: 'Pricing' }),
1382
+ ).toHaveAttribute('aria-current', 'page');
1383
+ },
1384
+ );
1385
+ },
1386
+ };
1387
+
1388
+ /**
1389
+ * `UiNavigationMenu` is fully keyboard operable: `Tab` reaches the items,
1390
+ * arrow keys move between them while skipping the disabled trigger,
1391
+ * `Enter`/`Space` open a panel, `ArrowDown` enters it, and `Escape` closes
1392
+ * it and returns focus to the trigger.
1393
+ */
1394
+ export const KeyboardNavigationTest: Story = {
1395
+ name: 'test - Keyboard Navigation',
1396
+ tags: ['!dev', '!autodocs'],
1397
+ parameters: {
1398
+ chromatic: { disableSnapshot: true },
1399
+ docs: {
1400
+ description: {
1401
+ story:
1402
+ 'Press `Tab` to reach the navigation, arrow keys to move, Enter/Space to open, and Escape to close.',
1403
+ },
1404
+ },
1405
+ },
1406
+ render: renderTestMenu,
1407
+ play: async ({ canvasElement, step }) => {
1408
+ // Scenario (UiNavigationMenu): a keyboard user tabs to the navigation,
1409
+ // arrows across the top level, opens Products with Enter, walks into the
1410
+ // panel, escapes back out, reopens with Space, and jumps across the row
1411
+ // with Home/End — all without touching the pointer.
1412
+ onUpdate.mockClear();
1413
+ const canvas = within(canvasElement);
1414
+ const home = canvas.getByRole('link', { name: 'Home' });
1415
+ const pricing = canvas.getByRole('link', { name: 'Pricing' });
1416
+ const products = canvas.getByRole('button', { name: 'Products' });
1417
+ const resources = canvas.getByRole('button', { name: 'Resources' });
1418
+
1419
+ await step(
1420
+ 'keyboard: Tab reaches the navigation without needing hover (WCAG 2.1.1 Keyboard)',
1421
+ async () => {
1422
+ await userEvent.tab();
1423
+ await expect(home).toHaveFocus();
1424
+ },
1425
+ );
1426
+
1427
+ await step(
1428
+ 'keyboard: the focused item shows a visible focus indicator (WCAG 2.4.7)',
1429
+ async () => {
1430
+ const { boxShadow, outlineStyle } = getComputedStyle(home);
1431
+ await expect(outlineStyle).toBe('none');
1432
+ await expect(boxShadow).not.toBe('none');
1433
+ },
1434
+ );
1435
+
1436
+ await step('keyboard: arrow keys move between menu items', async () => {
1437
+ await userEvent.keyboard('{ArrowRight}');
1438
+ await expect(products).toHaveFocus();
1439
+ await userEvent.keyboard('{ArrowLeft}');
1440
+ await expect(home).toHaveFocus();
1441
+ await userEvent.keyboard('{ArrowRight}');
1442
+ await expect(products).toHaveFocus();
1443
+ });
1444
+
1445
+ await step(
1446
+ 'keyboard: Enter opens the focused trigger and ArrowDown moves into the panel',
1447
+ async () => {
1448
+ await userEvent.keyboard('{Enter}');
1449
+ await waitFor(async () => {
1450
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1451
+ });
1452
+ await expect(onUpdate).toHaveBeenLastCalledWith('products');
1453
+ await userEvent.keyboard('{ArrowDown}');
1454
+ await expect(
1455
+ canvas.getByRole('link', { name: /Analytics/ }),
1456
+ ).toHaveFocus();
1457
+ await userEvent.keyboard('{ArrowDown}');
1458
+ await expect(
1459
+ canvas.getByRole('link', { name: /Automation/ }),
1460
+ ).toHaveFocus();
1461
+ },
1462
+ );
1463
+
1464
+ await step(
1465
+ 'keyboard: Escape closes the panel and returns focus to the trigger (WCAG 2.1.2)',
1466
+ async () => {
1467
+ await userEvent.keyboard('{Escape}');
1468
+ await waitFor(async () => {
1469
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1470
+ });
1471
+ await expect(products).toHaveFocus();
1472
+ },
1473
+ );
1474
+
1475
+ await step('keyboard: Space also opens the focused trigger', async () => {
1476
+ // The vendor's Space handler reads the legacy `keyCode` field, which
1477
+ // real browsers always set but user-event's synthesized events leave
1478
+ // at 0 — so deliver the keydown the way a browser would.
1479
+ products.dispatchEvent(
1480
+ new KeyboardEvent('keydown', {
1481
+ key: ' ',
1482
+ code: 'Space',
1483
+ keyCode: 32,
1484
+ bubbles: true,
1485
+ cancelable: true,
1486
+ } as KeyboardEventInit),
1487
+ );
1488
+ await waitFor(async () => {
1489
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1490
+ });
1491
+ await userEvent.keyboard('{Escape}');
1492
+ await waitFor(async () => {
1493
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1494
+ });
1495
+ });
1496
+
1497
+ await step(
1498
+ 'keyboard: arrow navigation skips the disabled trigger (WCAG 2.1.1)',
1499
+ async () => {
1500
+ await userEvent.keyboard('{ArrowRight}');
1501
+ await expect(resources).toHaveFocus();
1502
+ },
1503
+ );
1504
+
1505
+ await step(
1506
+ 'keyboard: Home and End jump to the first and last item, and the current page is indicated (WCAG 2.4.3)',
1507
+ async () => {
1508
+ await userEvent.keyboard('{End}');
1509
+ await expect(pricing).toHaveFocus();
1510
+ await expect(pricing).toHaveAttribute('aria-current', 'page');
1511
+ await userEvent.keyboard('{Home}');
1512
+ await expect(home).toHaveFocus();
1513
+ },
1514
+ );
1515
+ },
1516
+ };
1517
+
1518
+ /**
1519
+ * Screen-reader semantics: the menu is a named navigation landmark, triggers
1520
+ * are buttons announcing their expanded state and panel linkage, links expose
1521
+ * their names, the current page announces `aria-current`, and the disabled
1522
+ * trigger announces its state.
1523
+ */
1524
+ export const ScreenReader: Story = {
1525
+ name: 'test - Screen Reader',
1526
+ tags: ['!dev', '!autodocs'],
1527
+ parameters: {
1528
+ chromatic: { disableSnapshot: true },
1529
+ docs: {
1530
+ description: {
1531
+ story:
1532
+ 'Verifies the roles, names, and states that assistive technology announces.',
1533
+ },
1534
+ },
1535
+ },
1536
+ render: renderTestMenu,
1537
+ play: async ({ canvasElement, step }) => {
1538
+ // Scenario (UiNavigationMenu): assistive tech lands on a named navigation
1539
+ // landmark, hears each trigger as a collapsible button, is told which
1540
+ // link is the current page, and which trigger is unavailable.
1541
+ const canvas = within(canvasElement);
1542
+ const products = canvas.getByRole('button', { name: 'Products' });
1543
+
1544
+ await step(
1545
+ 'screen-reader: the menu is a navigation landmark with an accessible name (WCAG 1.3.1)',
1546
+ async () => {
1547
+ await expect(
1548
+ canvas.getByRole('navigation', { name: 'Main navigation' }),
1549
+ ).toBeVisible();
1550
+ },
1551
+ );
1552
+
1553
+ await step(
1554
+ 'screen-reader: triggers are buttons that announce their collapsed state (WCAG 4.1.2)',
1555
+ async () => {
1556
+ await expect(products).toHaveAccessibleName('Products');
1557
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1558
+ },
1559
+ );
1560
+
1561
+ await step(
1562
+ 'screen-reader: an open panel announces expanded and is labelled by its trigger (WCAG 1.3.1 / 4.1.2)',
1563
+ async () => {
1564
+ await userEvent.click(products);
1565
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1566
+ const contentId = products.getAttribute('aria-controls');
1567
+ await expect(contentId).toBeTruthy();
1568
+ const content = canvasElement.ownerDocument.getElementById(
1569
+ contentId as string,
1570
+ );
1571
+ if (!content) throw new Error('Expected the open panel to be mounted');
1572
+ await expect(content).toHaveAttribute('aria-labelledby', products.id);
1573
+ await userEvent.keyboard('{Escape}');
1574
+ await waitFor(async () => {
1575
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1576
+ });
1577
+ },
1578
+ );
1579
+
1580
+ await step(
1581
+ 'screen-reader: links expose the link role named by their label (WCAG 4.1.2)',
1582
+ async () => {
1583
+ await expect(
1584
+ canvas.getByRole('link', { name: 'Home' }),
1585
+ ).toHaveAccessibleName('Home');
1586
+ await expect(
1587
+ canvas.getByRole('link', { name: 'Pricing' }),
1588
+ ).toHaveAccessibleName('Pricing');
1589
+ },
1590
+ );
1591
+
1592
+ await step(
1593
+ 'screen-reader: the current page announces aria-current="page" (WCAG 4.1.2)',
1594
+ async () => {
1595
+ await expect(
1596
+ canvas.getByRole('link', { name: 'Pricing' }),
1597
+ ).toHaveAttribute('aria-current', 'page');
1598
+ await expect(
1599
+ canvas.getByRole('link', { name: 'Home' }),
1600
+ ).not.toHaveAttribute('aria-current');
1601
+ },
1602
+ );
1603
+
1604
+ await step(
1605
+ 'screen-reader: the disabled trigger announces its disabled state (WCAG 4.1.2)',
1606
+ async () => {
1607
+ await expect(
1608
+ canvas.getByRole('button', { name: 'Admin' }),
1609
+ ).toBeDisabled();
1610
+ },
1611
+ );
1612
+
1613
+ await step(
1614
+ 'screen-reader: the trigger chevron is decorative and hidden (WCAG 1.1.1)',
1615
+ async () => {
1616
+ const chevron = products.querySelector('svg');
1617
+ if (!chevron) throw new Error('Expected a chevron icon in the trigger');
1618
+ await expect(chevron).toHaveAttribute('aria-hidden', 'true');
1619
+ },
1620
+ );
1621
+ },
1622
+ };
1623
+
1624
+ /**
1625
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1626
+ * try 400% reflow (WCAG 1.4.10); every item must stay visible, readable, and
1627
+ * operable.
1628
+ */
1629
+ export const ZoomMagnification: Story = {
1630
+ name: 'test - Zoom Magnification',
1631
+ tags: ['!dev', '!autodocs'],
1632
+ globals: { zoom: '200' },
1633
+ parameters: {
1634
+ chromatic: { disableSnapshot: true },
1635
+ docs: {
1636
+ description: {
1637
+ story:
1638
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1639
+ },
1640
+ },
1641
+ },
1642
+ render: renderTestMenu,
1643
+ play: async ({ canvasElement, step }) => {
1644
+ // Scenario (UiNavigationMenu): at 200% page zoom every top-level item
1645
+ // stays on screen with its label, and a panel still opens with its
1646
+ // destinations readable.
1647
+ const canvas = within(canvasElement);
1648
+ const products = canvas.getByRole('button', { name: 'Products' });
1649
+
1650
+ await step(
1651
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1652
+ async () => {
1653
+ await expect(document.documentElement.style.zoom).toBe('200%');
1654
+ },
1655
+ );
1656
+
1657
+ await step(
1658
+ 'zoom: every menu item stays visible with a readable label when magnified',
1659
+ async () => {
1660
+ for (const name of ['Home', 'Pricing']) {
1661
+ await expect(canvas.getByRole('link', { name })).toBeVisible();
1662
+ }
1663
+ for (const name of ['Products', 'Resources']) {
1664
+ await expect(canvas.getByRole('button', { name })).toBeVisible();
1665
+ }
1666
+ },
1667
+ );
1668
+
1669
+ await step('zoom: the menu remains operable when magnified', async () => {
1670
+ await userEvent.click(products);
1671
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1672
+ await expect(
1673
+ await canvas.findByRole('link', { name: /Analytics/ }),
1674
+ ).toBeVisible();
1675
+ await userEvent.keyboard('{Escape}');
1676
+ await waitFor(async () => {
1677
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1678
+ });
1679
+ });
1680
+ },
1681
+ };
1682
+
1683
+ /**
1684
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1685
+ * toolbar. Every item stays operable and meets the minimum touch-target size
1686
+ * (WCAG 2.5.8).
1687
+ */
1688
+ export const MobileBreakpoint: Story = {
1689
+ name: 'test - Mobile Breakpoint',
1690
+ tags: ['!dev', '!autodocs'],
1691
+ globals: { mediaBreakpoint: 'reflow' },
1692
+ parameters: {
1693
+ chromatic: { disableSnapshot: true },
1694
+ docs: {
1695
+ description: {
1696
+ story:
1697
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1698
+ },
1699
+ },
1700
+ },
1701
+ render: renderTestMenu,
1702
+ play: async ({ canvasElement, step }) => {
1703
+ // Scenario (UiNavigationMenu): at the 320px mobile breakpoint the
1704
+ // navigation stays reachable by keyboard, every item is big enough to
1705
+ // tap, and a tap still opens its panel.
1706
+ onUpdate.mockClear();
1707
+ const canvas = within(canvasElement);
1708
+ const products = canvas.getByRole('button', { name: 'Products' });
1709
+
1710
+ await step(
1711
+ 'mobile: the menu fits without horizontal scrolling at the 320px breakpoint (WCAG 1.4.10 Reflow)',
1712
+ async () => {
1713
+ await expect(document.documentElement.clientWidth).toBe(320);
1714
+ for (const name of ['Home', 'Pricing']) {
1715
+ await expect(canvas.getByRole('link', { name })).toBeVisible();
1716
+ }
1717
+ for (const name of ['Products', 'Resources']) {
1718
+ await expect(canvas.getByRole('button', { name })).toBeVisible();
1719
+ }
1720
+ const { scrollWidth, clientWidth } = document.documentElement;
1721
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
1722
+ },
1723
+ );
1724
+
1725
+ await step(
1726
+ 'mobile: items meet the minimum touch-target size (WCAG 2.5.8)',
1727
+ async () => {
1728
+ const targets = [
1729
+ canvas.getByRole('link', { name: 'Home' }),
1730
+ products,
1731
+ canvas.getByRole('button', { name: 'Resources' }),
1732
+ canvas.getByRole('link', { name: 'Pricing' }),
1733
+ ];
1734
+ for (const target of targets) {
1735
+ const { width, height } = target.getBoundingClientRect();
1736
+ await expect(width).toBeGreaterThanOrEqual(24);
1737
+ await expect(height).toBeGreaterThanOrEqual(24);
1738
+ }
1739
+ },
1740
+ );
1741
+
1742
+ await step(
1743
+ 'mobile: stays keyboard operable — Tab reaches the first item (WCAG 2.1.1)',
1744
+ async () => {
1745
+ await userEvent.tab();
1746
+ await expect(canvas.getByRole('link', { name: 'Home' })).toHaveFocus();
1747
+ },
1748
+ );
1749
+
1750
+ await step(
1751
+ 'mobile: tapping a trigger opens its panel at the 320px breakpoint',
1752
+ async () => {
1753
+ await userEvent.click(products);
1754
+ await expect(products).toHaveAttribute('aria-expanded', 'true');
1755
+ await expect(
1756
+ await canvas.findByRole('link', { name: /Analytics/ }),
1757
+ ).toBeVisible();
1758
+ // Close again so the automated axe audit runs on the resting state:
1759
+ // while a panel is open the vendor keeps an intentional aria-hidden
1760
+ // focus proxy in the DOM, which axe's aria-hidden-focus rule flags.
1761
+ await userEvent.keyboard('{Escape}');
1762
+ await waitFor(async () => {
1763
+ await expect(products).toHaveAttribute('aria-expanded', 'false');
1764
+ });
1765
+ },
1766
+ );
1767
+ },
1768
+ };
1769
+
1770
+ /**
1771
+ * Accessibility guidance for top-level navigation: the current section marked
1772
+ * without relying on colour, distinct hover and focus states, panels that
1773
+ * open fully on screen, comfortable targets, and hover-free reachability —
1774
+ * shown side by side in the default and accessible themes.
1775
+ */
1776
+ export const Accessibility: Story = {
1777
+ tags: ['!autodocs'],
1778
+ parameters: {
1779
+ a11y: { test: 'off' },
1780
+ chromatic: { disableSnapshot: true },
1781
+ docs: {
1782
+ canvas: {
1783
+ sourceState: 'none',
1784
+ },
1785
+ },
1786
+ },
1787
+ render: () => ({
1788
+ components: {
1789
+ UiNavigationMenu,
1790
+ UiNavigationMenuList,
1791
+ UiNavigationMenuItem,
1792
+ UiNavigationMenuTrigger,
1793
+ UiNavigationMenuContent,
1794
+ UiNavigationMenuLink,
1795
+ },
1796
+ setup() {
1797
+ return { navigationMenuTriggerStyle };
1798
+ },
1799
+ template: `
1800
+ <section class="flex w-full flex-col gap-6 p-4">
1801
+ <div>
1802
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1803
+ Accessibility
1804
+ </h2>
1805
+ </div>
1806
+
1807
+ <div class="flex flex-col gap-6">
1808
+ <div class="flex flex-col gap-2">
1809
+ <h3 class="body-16-medium text-content-on-surface-primary">
1810
+ Requirements
1811
+ </h3>
1812
+ <ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
1813
+ <li>
1814
+ The current section is marked by weight or a rule, not by
1815
+ colour alone
1816
+ </li>
1817
+ <li>
1818
+ Triggers and links keep visible hover and focus states,
1819
+ distinct from each other
1820
+ </li>
1821
+ <li>
1822
+ Panels open fully on screen, so no destination is cut off
1823
+ </li>
1824
+ <li>
1825
+ Link descriptions hold contrast against the panel's own surface
1826
+ </li>
1827
+ <li>
1828
+ Triggers and links are comfortable targets, with space between
1829
+ adjacent items
1830
+ </li>
1831
+ <li>
1832
+ Give every navigation landmark a unique accessible name with
1833
+ <code>aria-label</code> or <code>aria-labelledby</code>
1834
+ </li>
1835
+ <li>
1836
+ Preserve keyboard operation: Tab enters the navigation, arrow
1837
+ keys move between items, Enter or Space opens a panel, and
1838
+ Escape closes it
1839
+ </li>
1840
+ <li>
1841
+ Navigation is reachable without hover, since pointing is not
1842
+ available to every user
1843
+ </li>
1844
+ </ul>
1845
+ </div>
1846
+
1847
+ <div class="flex flex-col gap-2">
1848
+ <h3 class="body-16-medium text-content-on-surface-primary">
1849
+ Enable accessibility theme
1850
+ </h3>
1851
+ <p class="body-16-regular text-content-on-surface-primary">
1852
+ When accessibility is required, enable our accessibility theme.
1853
+ This increases contrast and ensures there are no color contrast
1854
+ issues.
1855
+ </p>
1856
+ </div>
1857
+ </div>
1858
+
1859
+ <div class="grid gap-4 md:grid-cols-2">
1860
+ <div class="flex flex-col gap-3">
1861
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1862
+ Default
1863
+ </h3>
1864
+ <div class="flex min-h-20 items-center justify-start overflow-visible border border-border-surface-default p-6">
1865
+ <UiNavigationMenu aria-label="Main navigation">
1866
+ <UiNavigationMenuList>
1867
+ <UiNavigationMenuItem>
1868
+ <UiNavigationMenuTrigger>Menu Item</UiNavigationMenuTrigger>
1869
+ <UiNavigationMenuContent>
1870
+ <ul class="grid w-[200px]">
1871
+ <li><UiNavigationMenuLink href="#">Menu Item</UiNavigationMenuLink></li>
1872
+ </ul>
1873
+ </UiNavigationMenuContent>
1874
+ </UiNavigationMenuItem>
1875
+ <UiNavigationMenuItem>
1876
+ <UiNavigationMenuTrigger>Menu Item</UiNavigationMenuTrigger>
1877
+ <UiNavigationMenuContent>
1878
+ <ul class="grid w-[200px]">
1879
+ <li><UiNavigationMenuLink href="#">Menu Item</UiNavigationMenuLink></li>
1880
+ </ul>
1881
+ </UiNavigationMenuContent>
1882
+ </UiNavigationMenuItem>
1883
+ <UiNavigationMenuItem>
1884
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1885
+ </UiNavigationMenuItem>
1886
+ <UiNavigationMenuItem>
1887
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1888
+ </UiNavigationMenuItem>
1889
+ <UiNavigationMenuItem>
1890
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1891
+ </UiNavigationMenuItem>
1892
+ </UiNavigationMenuList>
1893
+ </UiNavigationMenu>
1894
+ </div>
1895
+ </div>
1896
+
1897
+ <div class="accessible-theme flex flex-col gap-3">
1898
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1899
+ Accessible
1900
+ </h3>
1901
+ <div class="flex min-h-20 items-center justify-start overflow-visible border border-border-surface-default p-6">
1902
+ <UiNavigationMenu aria-label="Main navigation">
1903
+ <UiNavigationMenuList>
1904
+ <UiNavigationMenuItem>
1905
+ <UiNavigationMenuTrigger>Menu Item</UiNavigationMenuTrigger>
1906
+ <UiNavigationMenuContent>
1907
+ <ul class="grid w-[200px]">
1908
+ <li><UiNavigationMenuLink href="#">Menu Item</UiNavigationMenuLink></li>
1909
+ </ul>
1910
+ </UiNavigationMenuContent>
1911
+ </UiNavigationMenuItem>
1912
+ <UiNavigationMenuItem>
1913
+ <UiNavigationMenuTrigger>Menu Item</UiNavigationMenuTrigger>
1914
+ <UiNavigationMenuContent>
1915
+ <ul class="grid w-[200px]">
1916
+ <li><UiNavigationMenuLink href="#">Menu Item</UiNavigationMenuLink></li>
1917
+ </ul>
1918
+ </UiNavigationMenuContent>
1919
+ </UiNavigationMenuItem>
1920
+ <UiNavigationMenuItem>
1921
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1922
+ </UiNavigationMenuItem>
1923
+ <UiNavigationMenuItem>
1924
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1925
+ </UiNavigationMenuItem>
1926
+ <UiNavigationMenuItem>
1927
+ <UiNavigationMenuLink href="#" :class="navigationMenuTriggerStyle()">Menu Item</UiNavigationMenuLink>
1928
+ </UiNavigationMenuItem>
1929
+ </UiNavigationMenuList>
1930
+ </UiNavigationMenu>
1931
+ </div>
1932
+ </div>
1933
+ </div>
1934
+ </section>
1935
+ `,
1936
+ }),
1937
+ };