@aleph-alpha/ui-library 6.3.4 → 6.5.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.
Files changed (78) hide show
  1. package/config.js +2 -1
  2. package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
  3. package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
  4. package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
  5. package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
  6. package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
  7. package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
  8. package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +10 -1
  9. package/dist/system/components/UiFileItem/index.d.ts +1 -1
  10. package/dist/system/components/UiFileItem/types.d.ts +81 -5
  11. package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
  12. package/dist/system/components/UiPopover/UiPopoverContent.vue.d.ts +1 -0
  13. package/dist/system/components/UiPopover/types.d.ts +6 -0
  14. package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
  15. package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
  16. package/dist/system/components/UiToggle/types.d.ts +10 -2
  17. package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
  18. package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
  19. package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
  20. package/dist/system/components/core/popover/PopoverContent.vue.d.ts +1 -0
  21. package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
  22. package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
  23. package/dist/system/components/core/toggle/index.d.ts +47 -2
  24. package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
  25. package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
  26. package/dist/system/components/core/toggle-group/context.d.ts +1 -0
  27. package/dist/system/components/core/toggle-group/index.d.ts +10 -2
  28. package/dist/system/lib.js +10646 -10369
  29. package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
  30. package/dist/system/patterns/UiLayout/layout-shell.d.ts +171 -12
  31. package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
  32. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +9 -4
  33. package/package.json +2 -2
  34. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
  35. package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
  36. package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
  37. package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
  38. package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
  39. package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
  40. package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
  41. package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
  42. package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
  43. package/src/components/UiDropdownMenu/types.ts +3 -0
  44. package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
  45. package/src/components/UiFileItem/UiFileItem.vue +111 -6
  46. package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +52 -0
  47. package/src/components/UiFileItem/index.ts +1 -0
  48. package/src/components/UiFileItem/types.ts +82 -5
  49. package/src/components/UiPopover/UiPopover.stories.ts +141 -0
  50. package/src/components/UiPopover/UiPopoverContent.vue +2 -0
  51. package/src/components/UiPopover/__tests__/UiPopover.test.ts +48 -0
  52. package/src/components/UiPopover/types.ts +7 -0
  53. package/src/components/UiSnackbar/UiSnackbar.stories.ts +104 -32
  54. package/src/components/UiToggle/UiToggle.stories.ts +386 -261
  55. package/src/components/UiToggle/UiToggle.vue +2 -0
  56. package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
  57. package/src/components/UiToggle/types.ts +10 -2
  58. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
  59. package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
  60. package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
  61. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
  62. package/src/components/UiToggleGroup/types.ts +12 -2
  63. package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
  64. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  65. package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
  66. package/src/components/core/popover/PopoverContent.vue +9 -3
  67. package/src/components/core/toggle/Toggle.vue +12 -5
  68. package/src/components/core/toggle/index.ts +47 -19
  69. package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
  70. package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
  71. package/src/components/core/toggle-group/context.ts +1 -0
  72. package/src/components/core/toggle-group/index.ts +10 -24
  73. package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
  74. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  75. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +808 -22
  76. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +188 -6
  77. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
  78. package/src/patterns/UiTopBar/accessory-dropdown.ts +5 -3
@@ -1,6 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
3
- import { computed, ref, watch } from 'vue';
3
+ import { computed, reactive, ref, watch } from 'vue';
4
4
  import {
5
5
  UiDropdownMenu,
6
6
  UiDropdownMenuTrigger,
@@ -19,6 +19,7 @@ import {
19
19
  } from './index';
20
20
  import UiButton from '../UiButton/UiButton.vue';
21
21
  import UiToggle from '../UiToggle/UiToggle.vue';
22
+ import UiSwitch from '../UiSwitch/UiSwitch.vue';
22
23
  import { UiIcon } from '../UiIcon';
23
24
  import { UiAvatar, UiAvatarFallback, UiAvatarImage } from '../UiAvatar';
24
25
 
@@ -45,6 +46,22 @@ const meta: Meta<typeof UiDropdownMenu> = {
45
46
  open: false,
46
47
  modal: true,
47
48
  },
49
+ parameters: {
50
+ a11y: {
51
+ options: {
52
+ rules: {
53
+ // A menu that scrolls is reached with the arrow keys: the menu owns
54
+ // focus and keeps every row at `tabindex="-1"` (WAI-ARIA menu
55
+ // pattern), scrolling the focused row into view. axe only looks for
56
+ // a tab stop inside the scroll box, so it reports the five-row
57
+ // mobile list, and any desktop menu taller than the space beside
58
+ // its trigger, as unreachable. Keyboard reach is covered by the
59
+ // `keyboard:` plays instead.
60
+ 'scrollable-region-focusable': { enabled: false },
61
+ },
62
+ },
63
+ },
64
+ },
48
65
  };
49
66
 
50
67
  export default meta;
@@ -781,11 +798,7 @@ import {
781
798
  const open = ref(false)
782
799
  const activeFilter = ref('')
783
800
  const hasFilter = computed(() => !!activeFilter.value)
784
- const toggleVariant = computed(() => {
785
- if (open.value) return 'soft'
786
- if (hasFilter.value) return 'outline'
787
- return 'default'
788
- })
801
+ const toggleVariant = computed(() => (hasFilter.value ? 'outline' : 'default'))
789
802
  const toggleActive = computed({
790
803
  get: () => open.value,
791
804
  set: () => {},
@@ -795,7 +808,7 @@ const toggleActive = computed({
795
808
  <template>
796
809
  <UiDropdownMenu v-model:open="open">
797
810
  <UiDropdownMenuTrigger as-child>
798
- <UiToggle v-model="toggleActive" :variant="toggleVariant" aria-label="Filter options">
811
+ <UiToggle v-model="toggleActive" :variant="toggleVariant" soft aria-label="Filter options">
799
812
  <UiIcon name="filter" />
800
813
  </UiToggle>
801
814
  </UiDropdownMenuTrigger>
@@ -829,11 +842,9 @@ export const WithSoftToggleTrigger: Story = {
829
842
  const modal = ref(args.modal);
830
843
  const activeFilter = ref('');
831
844
  const hasFilter = computed(() => !!activeFilter.value);
832
- const toggleVariant = computed(() => {
833
- if (open.value) return 'soft';
834
- if (hasFilter.value) return 'outline';
835
- return 'default';
836
- });
845
+ const toggleVariant = computed(() =>
846
+ hasFilter.value ? 'outline' : 'default',
847
+ );
837
848
  const toggleActive = computed({
838
849
  get: () => open.value,
839
850
  set: (value: boolean) => {
@@ -863,7 +874,7 @@ export const WithSoftToggleTrigger: Story = {
863
874
  },
864
875
  template: `<UiDropdownMenu v-model:open="open" :modal="modal">
865
876
  <UiDropdownMenuTrigger as-child>
866
- <UiToggle v-model="toggleActive" :variant="toggleVariant" aria-label="Filter options">
877
+ <UiToggle v-model="toggleActive" :variant="toggleVariant" soft aria-label="Filter options">
867
878
  <UiIcon name="filter" />
868
879
  </UiToggle>
869
880
  </UiDropdownMenuTrigger>
@@ -877,12 +888,112 @@ export const WithSoftToggleTrigger: Story = {
877
888
  </UiDropdownMenu>`,
878
889
  }),
879
890
  parameters: {
891
+ // The play opens the menu, picks a filter and moves focus; skip the
892
+ // visual snapshot.
893
+ chromatic: { disableSnapshot: true },
880
894
  docs: {
881
895
  source: {
882
896
  code: softToggleTriggerTemplateSource,
883
897
  },
884
898
  },
885
899
  },
900
+ play: async ({ canvasElement, step }) => {
901
+ // Scenario (UiDropdownMenu): a `UiToggle` trigger owns two states at once —
902
+ // pressed, because it is a toggle, and expanded, because it opens a menu.
903
+ // They are bound to the same `open` ref, so they must never disagree, and
904
+ // the variant must follow whether a filter is applied.
905
+ const canvas = within(canvasElement);
906
+ const body = within(document.body);
907
+ const trigger = canvas.getByRole('button', { name: 'Filter options' });
908
+
909
+ await step(
910
+ 'interaction: the closed trigger reports neither pressed nor expanded (WCAG 4.1.2)',
911
+ async () => {
912
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
913
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
914
+ // No filter yet, so the trigger is still the borderless default.
915
+ await expect(trigger).toHaveClass('border-transparent');
916
+ },
917
+ );
918
+
919
+ await step(
920
+ 'interaction: opening the menu sets pressed and expanded together',
921
+ async () => {
922
+ await userEvent.click(trigger);
923
+ const menu = await body.findByRole('menu');
924
+ await waitFor(async () => {
925
+ await expect(menu).toBeVisible();
926
+ });
927
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
928
+ await expect(trigger).toHaveAttribute('aria-pressed', 'true');
929
+ // `as-child` merges the menu's own `data-state` onto the toggle, so an
930
+ // open trigger reads `open` rather than the toggle's `on`. That is what
931
+ // lights the hover overlay while the menu is up.
932
+ await expect(trigger).toHaveAttribute('data-state', 'open');
933
+ },
934
+ );
935
+
936
+ await step(
937
+ 'interaction: selecting a filter closes the menu and clears both states',
938
+ async () => {
939
+ await userEvent.click(body.getByRole('menuitem', { name: 'By Name' }));
940
+ await waitFor(async () => {
941
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
942
+ });
943
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
944
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
945
+ },
946
+ );
947
+
948
+ await step(
949
+ 'interaction: an applied filter switches the trigger to the outline variant',
950
+ async () => {
951
+ // The border is what keeps the trigger discoverable once it is
952
+ // carrying state the user cannot otherwise see.
953
+ await expect(trigger).toHaveClass('border-input');
954
+ await expect(trigger).not.toHaveClass('border-transparent');
955
+ },
956
+ );
957
+
958
+ await step(
959
+ 'interaction: clearing the filter returns the trigger to the default variant',
960
+ async () => {
961
+ await userEvent.click(trigger);
962
+ await waitFor(async () => {
963
+ await expect(await body.findByRole('menu')).toBeVisible();
964
+ });
965
+ await userEvent.click(
966
+ body.getByRole('menuitem', { name: 'Clear Filters' }),
967
+ );
968
+ await waitFor(async () => {
969
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
970
+ });
971
+ await expect(trigger).toHaveClass('border-transparent');
972
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
973
+ },
974
+ );
975
+
976
+ await step(
977
+ 'keyboard: Escape closes the menu and returns focus to the trigger (WCAG 2.1.2)',
978
+ async () => {
979
+ await userEvent.click(trigger);
980
+ await waitFor(async () => {
981
+ await expect(await body.findByRole('menu')).toBeVisible();
982
+ });
983
+ await userEvent.keyboard('{Escape}');
984
+ await waitFor(async () => {
985
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
986
+ });
987
+ // Reka hands focus back on the next tick, after the closing animation
988
+ // has been kicked off.
989
+ await waitFor(async () => {
990
+ await expect(trigger).toHaveFocus();
991
+ });
992
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
993
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
994
+ },
995
+ );
996
+ },
886
997
  };
887
998
 
888
999
  const softToggleTriggerWithTextTemplateSource = `<script setup lang="ts">
@@ -903,11 +1014,7 @@ const showPreview = ref(false)
903
1014
  const showMetadata = ref(false)
904
1015
  const showTimestamps = ref(false)
905
1016
  const hasSelection = computed(() => showPreview.value || showMetadata.value || showTimestamps.value)
906
- const toggleVariant = computed(() => {
907
- if (open.value) return 'soft'
908
- if (hasSelection.value) return 'outline'
909
- return 'default'
910
- })
1017
+ const toggleVariant = computed(() => (hasSelection.value ? 'outline' : 'default'))
911
1018
  const toggleActive = computed({
912
1019
  get: () => open.value,
913
1020
  set: () => {},
@@ -917,7 +1024,7 @@ const toggleActive = computed({
917
1024
  <template>
918
1025
  <UiDropdownMenu v-model:open="open">
919
1026
  <UiDropdownMenuTrigger as-child>
920
- <UiToggle v-model="toggleActive" :variant="toggleVariant" aria-label="View settings">
1027
+ <UiToggle v-model="toggleActive" :variant="toggleVariant" soft aria-label="View settings">
921
1028
  <UiIcon name="settings" />
922
1029
  View
923
1030
  <UiIcon name="chevron-down" class="size-3" />
@@ -964,11 +1071,9 @@ export const WithSoftToggleTriggerAndText: Story = {
964
1071
  const hasSelection = computed(
965
1072
  () => showPreview.value || showMetadata.value || showTimestamps.value,
966
1073
  );
967
- const toggleVariant = computed(() => {
968
- if (open.value) return 'soft';
969
- if (hasSelection.value) return 'outline';
970
- return 'default';
971
- });
1074
+ const toggleVariant = computed(() =>
1075
+ hasSelection.value ? 'outline' : 'default',
1076
+ );
972
1077
  const toggleActive = computed({
973
1078
  get: () => open.value,
974
1079
  set: (value: boolean) => {
@@ -1000,7 +1105,7 @@ export const WithSoftToggleTriggerAndText: Story = {
1000
1105
  },
1001
1106
  template: `<UiDropdownMenu v-model:open="open" :modal="modal">
1002
1107
  <UiDropdownMenuTrigger as-child>
1003
- <UiToggle v-model="toggleActive" :variant="toggleVariant" aria-label="View settings">
1108
+ <UiToggle v-model="toggleActive" :variant="toggleVariant" soft aria-label="View settings">
1004
1109
  <UiIcon name="settings" />
1005
1110
  View
1006
1111
  <UiIcon name="chevron-down" class="size-3" />
@@ -1022,12 +1127,124 @@ export const WithSoftToggleTriggerAndText: Story = {
1022
1127
  </UiDropdownMenu>`,
1023
1128
  }),
1024
1129
  parameters: {
1130
+ // The play opens the menu and ticks checkboxes; skip the visual snapshot.
1131
+ chromatic: { disableSnapshot: true },
1025
1132
  docs: {
1026
1133
  source: {
1027
1134
  code: softToggleTriggerWithTextTemplateSource,
1028
1135
  },
1029
1136
  },
1030
1137
  },
1138
+ play: async ({ canvasElement, step }) => {
1139
+ // Scenario (UiDropdownMenu): the same trigger contract as the icon-only
1140
+ // one, but driven by checkbox items that stay open while they are ticked —
1141
+ // so the trigger has to hold its expanded and pressed states across several
1142
+ // selections before the variant settles.
1143
+ const canvas = within(canvasElement);
1144
+ const body = within(document.body);
1145
+ const trigger = canvas.getByRole('button', { name: 'View settings' });
1146
+
1147
+ await step(
1148
+ 'interaction: the trigger is named by its label, not by the visible word alone',
1149
+ async () => {
1150
+ // The visible "View" is shorter than the name, which is allowed because
1151
+ // the name contains it (WCAG 2.5.3 Label in Name).
1152
+ await expect(trigger).toHaveAccessibleName('View settings');
1153
+ await expect(canvas.getByText('View')).toBeVisible();
1154
+ },
1155
+ );
1156
+
1157
+ await step(
1158
+ 'interaction: the closed trigger reports neither pressed nor expanded (WCAG 4.1.2)',
1159
+ async () => {
1160
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
1161
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
1162
+ await expect(trigger).toHaveClass('border-transparent');
1163
+ },
1164
+ );
1165
+
1166
+ await step(
1167
+ 'interaction: opening the menu sets pressed and expanded together',
1168
+ async () => {
1169
+ await userEvent.click(trigger);
1170
+ const menu = await body.findByRole('menu');
1171
+ await waitFor(async () => {
1172
+ await expect(menu).toBeVisible();
1173
+ });
1174
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1175
+ await expect(trigger).toHaveAttribute('aria-pressed', 'true');
1176
+ },
1177
+ );
1178
+
1179
+ await step(
1180
+ 'interaction: ticking an option closes the menu and clears both states',
1181
+ async () => {
1182
+ const preview = body.getByRole('menuitemcheckbox', {
1183
+ name: 'Show Preview',
1184
+ });
1185
+ await expect(preview).toHaveAttribute('aria-checked', 'false');
1186
+ // A checkbox item dismisses the menu on select, so the trigger has to
1187
+ // come back down with it rather than being left stuck as expanded.
1188
+ await userEvent.click(preview);
1189
+ await waitFor(async () => {
1190
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1191
+ });
1192
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
1193
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
1194
+ },
1195
+ );
1196
+
1197
+ await step(
1198
+ 'interaction: a ticked option switches the trigger to the outline variant',
1199
+ async () => {
1200
+ await expect(trigger).toHaveClass('border-input');
1201
+ await expect(trigger).not.toHaveClass('border-transparent');
1202
+ },
1203
+ );
1204
+
1205
+ await step(
1206
+ 'interaction: unticking the last option returns the trigger to default',
1207
+ async () => {
1208
+ await userEvent.click(trigger);
1209
+ await waitFor(async () => {
1210
+ await expect(await body.findByRole('menu')).toBeVisible();
1211
+ });
1212
+ // Reopening shows the choice was kept, not reset by the dismissal.
1213
+ const preview = body.getByRole('menuitemcheckbox', {
1214
+ name: 'Show Preview',
1215
+ });
1216
+ await expect(preview).toHaveAttribute('aria-checked', 'true');
1217
+
1218
+ await userEvent.click(preview);
1219
+ await waitFor(async () => {
1220
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1221
+ });
1222
+ await expect(trigger).toHaveClass('border-transparent');
1223
+ await expect(trigger).toHaveAttribute('aria-pressed', 'false');
1224
+ },
1225
+ );
1226
+
1227
+ await step(
1228
+ 'keyboard: the trigger opens the menu from the keyboard (WCAG 2.1.1)',
1229
+ async () => {
1230
+ trigger.focus();
1231
+ await userEvent.keyboard('{Enter}');
1232
+ await waitFor(async () => {
1233
+ await expect(await body.findByRole('menu')).toBeVisible();
1234
+ });
1235
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1236
+ await userEvent.keyboard('{Escape}');
1237
+ await waitFor(async () => {
1238
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1239
+ });
1240
+ // Reka hands focus back on the next tick, after the closing animation
1241
+ // has been kicked off.
1242
+ await waitFor(async () => {
1243
+ await expect(trigger).toHaveFocus();
1244
+ });
1245
+ },
1246
+ );
1247
+ },
1031
1248
  };
1032
1249
 
1033
1250
  const itemTypesTemplateSource = `<script setup lang="ts">
@@ -1243,6 +1460,312 @@ export const ItemTypes: Story = {
1243
1460
  },
1244
1461
  };
1245
1462
 
1463
+ const mobileModeTemplateSource = `<script setup lang="ts">
1464
+ import { reactive, ref } from 'vue'
1465
+ import {
1466
+ UiDropdownMenu,
1467
+ UiDropdownMenuTrigger,
1468
+ UiDropdownMenuContent,
1469
+ UiDropdownMenuItem,
1470
+ UiDropdownMenuSub,
1471
+ UiDropdownMenuSubTrigger,
1472
+ UiDropdownMenuSubContent,
1473
+ UiButton,
1474
+ UiIcon,
1475
+ UiSwitch,
1476
+ } from '@aleph-alpha/ui-library'
1477
+
1478
+ const open = ref(false)
1479
+
1480
+ const connectors = reactive([
1481
+ { id: 'web-search', label: 'Web search', icon: 'globe', enabled: true },
1482
+ { id: 'salesforce', label: 'Salesforce', icon: 'cloud', enabled: false },
1483
+ { id: 'google-drive', label: 'Google Drive', icon: 'folder', enabled: false },
1484
+ { id: 'github', label: 'GitHub', icon: 'github', enabled: false },
1485
+ { id: 'figma', label: 'Figma', icon: 'figma', enabled: false },
1486
+ { id: 'slack', label: 'Slack', icon: 'message-square', enabled: false },
1487
+ { id: 'notion', label: 'Notion', icon: 'file-text', enabled: false },
1488
+ ])
1489
+
1490
+ const agents = ['Research', 'Summarize', 'Translate', 'Code review', 'Draft email', 'Plan']
1491
+ </script>
1492
+
1493
+ <template>
1494
+ <UiDropdownMenu v-model:open="open">
1495
+ <UiDropdownMenuTrigger as-child>
1496
+ <UiButton variant="outline" aria-label="Open menu">
1497
+ <UiIcon name="plus" :size="16" />
1498
+ </UiButton>
1499
+ </UiDropdownMenuTrigger>
1500
+ <UiDropdownMenuContent class="w-72" align="start" side="top">
1501
+ <UiDropdownMenuSub>
1502
+ <UiDropdownMenuSubTrigger>
1503
+ <UiIcon name="plug" :size="16" class="mr-2" />
1504
+ Connectors
1505
+ </UiDropdownMenuSubTrigger>
1506
+ <UiDropdownMenuSubContent>
1507
+ <!-- The row is the toggle: it carries the checked state for
1508
+ assistive technology, and the switch is only its picture. -->
1509
+ <UiDropdownMenuItem
1510
+ v-for="connector in connectors"
1511
+ :key="connector.id"
1512
+ role="menuitemcheckbox"
1513
+ :aria-checked="connector.enabled"
1514
+ :text-value="connector.label"
1515
+ @select.prevent="connector.enabled = !connector.enabled"
1516
+ >
1517
+ <UiIcon :name="connector.icon" :size="16" />
1518
+ {{ connector.label }}
1519
+ <UiSwitch
1520
+ :model-value="connector.enabled"
1521
+ :name="connector.id"
1522
+ size="sm"
1523
+ class="pointer-events-none ml-auto"
1524
+ inert
1525
+ />
1526
+ </UiDropdownMenuItem>
1527
+ </UiDropdownMenuSubContent>
1528
+ </UiDropdownMenuSub>
1529
+ <UiDropdownMenuSub>
1530
+ <UiDropdownMenuSubTrigger>
1531
+ <UiIcon name="scroll-text" :size="16" class="mr-2" />
1532
+ Agents &amp; Skills
1533
+ </UiDropdownMenuSubTrigger>
1534
+ <UiDropdownMenuSubContent>
1535
+ <UiDropdownMenuItem v-for="agent in agents" :key="agent">
1536
+ {{ agent }}
1537
+ </UiDropdownMenuItem>
1538
+ </UiDropdownMenuSubContent>
1539
+ </UiDropdownMenuSub>
1540
+ <UiDropdownMenuItem v-for="item in 6" :key="item">
1541
+ Menu item text {{ item }}
1542
+ </UiDropdownMenuItem>
1543
+ </UiDropdownMenuContent>
1544
+ </UiDropdownMenu>
1545
+ </template>`;
1546
+
1547
+ /**
1548
+ * The menu below the `sm` breakpoint. Five rows stay in view, with the first
1549
+ * and last fading into the panel while there are more rows past them; the
1550
+ * fade lifts off the first row at the top of the list and off the last row at
1551
+ * the bottom. A submenu opens 8px above or below the row that opened it, at
1552
+ * the parent's width, and may cover the rest of the parent, which takes an
1553
+ * overlay while the submenu is open.
1554
+ */
1555
+ export const MobileMode: Story = {
1556
+ args: { modal: false },
1557
+ globals: { mediaBreakpoint: 'reflow' },
1558
+ render: (args) => ({
1559
+ components: {
1560
+ UiDropdownMenu,
1561
+ UiDropdownMenuTrigger,
1562
+ UiDropdownMenuContent,
1563
+ UiDropdownMenuItem,
1564
+ UiDropdownMenuSub,
1565
+ UiDropdownMenuSubTrigger,
1566
+ UiDropdownMenuSubContent,
1567
+ UiButton,
1568
+ UiIcon,
1569
+ UiSwitch,
1570
+ },
1571
+ setup() {
1572
+ const open = ref(args.open);
1573
+ const modal = ref(args.modal);
1574
+ const connectors = reactive([
1575
+ { id: 'web-search', label: 'Web search', icon: 'globe', enabled: true },
1576
+ {
1577
+ id: 'salesforce',
1578
+ label: 'Salesforce',
1579
+ icon: 'cloud',
1580
+ enabled: false,
1581
+ },
1582
+ {
1583
+ id: 'google-drive',
1584
+ label: 'Google Drive',
1585
+ icon: 'folder',
1586
+ enabled: false,
1587
+ },
1588
+ { id: 'github', label: 'GitHub', icon: 'github', enabled: false },
1589
+ { id: 'figma', label: 'Figma', icon: 'figma', enabled: false },
1590
+ {
1591
+ id: 'slack',
1592
+ label: 'Slack',
1593
+ icon: 'message-square',
1594
+ enabled: false,
1595
+ },
1596
+ { id: 'notion', label: 'Notion', icon: 'file-text', enabled: false },
1597
+ ]);
1598
+ const agents = [
1599
+ 'Research',
1600
+ 'Summarize',
1601
+ 'Translate',
1602
+ 'Code review',
1603
+ 'Draft email',
1604
+ 'Plan',
1605
+ ];
1606
+ watch(
1607
+ () => args.open,
1608
+ (v) => {
1609
+ open.value = v;
1610
+ },
1611
+ );
1612
+ watch(
1613
+ () => args.modal,
1614
+ (v) => {
1615
+ modal.value = v;
1616
+ },
1617
+ );
1618
+ return { open, modal, connectors, agents };
1619
+ },
1620
+ template: `<div class="flex min-h-[32rem] items-end p-1">
1621
+ <UiDropdownMenu v-model:open="open" :modal="modal">
1622
+ <UiDropdownMenuTrigger as-child>
1623
+ <UiButton variant="outline" aria-label="Open menu" class="w-full">
1624
+ <UiIcon name="plus" :size="16" />
1625
+ </UiButton>
1626
+ </UiDropdownMenuTrigger>
1627
+ <UiDropdownMenuContent class="w-72" align="start" side="top">
1628
+ <UiDropdownMenuSub>
1629
+ <UiDropdownMenuSubTrigger>
1630
+ <UiIcon name="plug" :size="16" class="mr-2" />
1631
+ Connectors
1632
+ </UiDropdownMenuSubTrigger>
1633
+ <UiDropdownMenuSubContent>
1634
+ <UiDropdownMenuItem
1635
+ v-for="connector in connectors"
1636
+ :key="connector.id"
1637
+ role="menuitemcheckbox"
1638
+ :aria-checked="connector.enabled"
1639
+ :text-value="connector.label"
1640
+ @select.prevent="connector.enabled = !connector.enabled"
1641
+ >
1642
+ <UiIcon :name="connector.icon" :size="16" />
1643
+ {{ connector.label }}
1644
+ <UiSwitch
1645
+ :model-value="connector.enabled"
1646
+ :name="connector.id"
1647
+ size="sm"
1648
+ class="pointer-events-none ml-auto"
1649
+ inert
1650
+ />
1651
+ </UiDropdownMenuItem>
1652
+ </UiDropdownMenuSubContent>
1653
+ </UiDropdownMenuSub>
1654
+ <UiDropdownMenuSub>
1655
+ <UiDropdownMenuSubTrigger>
1656
+ <UiIcon name="scroll-text" :size="16" class="mr-2" />
1657
+ Agents &amp; Skills
1658
+ </UiDropdownMenuSubTrigger>
1659
+ <UiDropdownMenuSubContent>
1660
+ <UiDropdownMenuItem v-for="agent in agents" :key="agent">
1661
+ {{ agent }}
1662
+ </UiDropdownMenuItem>
1663
+ </UiDropdownMenuSubContent>
1664
+ </UiDropdownMenuSub>
1665
+ <UiDropdownMenuItem v-for="item in 6" :key="item">
1666
+ Menu item text {{ item }}
1667
+ </UiDropdownMenuItem>
1668
+ </UiDropdownMenuContent>
1669
+ </UiDropdownMenu>
1670
+ </div>`,
1671
+ }),
1672
+ parameters: {
1673
+ // The play opens the menu and a submenu, which moves focus; the reflow
1674
+ // Chromatic mode already snapshots the closed state.
1675
+ chromatic: { disableSnapshot: true },
1676
+ docs: {
1677
+ source: {
1678
+ code: mobileModeTemplateSource,
1679
+ },
1680
+ },
1681
+ },
1682
+ play: async ({ canvasElement, step }) => {
1683
+ // Scenario (UiDropdownMenu): on a phone the user opens the menu, sees five
1684
+ // rows with the rest fading out under the last one, scrolls to the end so
1685
+ // the fade swaps to the first row, opens "Connectors" and gets its list
1686
+ // stacked right next to that row over the dimmed parent, then flips a
1687
+ // connector without the submenu going away.
1688
+ const canvas = within(canvasElement);
1689
+ const body = within(document.body);
1690
+ const trigger = canvas.getByRole('button', { name: 'Open menu' });
1691
+
1692
+ await step(
1693
+ 'interaction: the menu opens with five rows in view and a fade under the last one',
1694
+ async () => {
1695
+ await userEvent.click(trigger);
1696
+ const menu = await expectOpenMenu(body);
1697
+ const { viewport, scroll } = getMobileViewport(menu);
1698
+ const row = body.getByRole('menuitem', { name: 'Connectors' });
1699
+ await expect(scroll.clientHeight).toBe(row.offsetHeight * 5);
1700
+ await expect(scroll.scrollHeight).toBeGreaterThan(scroll.clientHeight);
1701
+ await expect(viewport).toHaveAttribute('data-fade', 'bottom');
1702
+ },
1703
+ );
1704
+
1705
+ await step(
1706
+ 'interaction: scrolling moves the fade to the rows that still have more behind them',
1707
+ async () => {
1708
+ const menu = body.getAllByRole('menu')[0];
1709
+ const { viewport, scroll } = getMobileViewport(menu);
1710
+ scroll.scrollTop = scroll.scrollHeight;
1711
+ await waitFor(async () => {
1712
+ await expect(viewport).toHaveAttribute('data-fade', 'top');
1713
+ });
1714
+ scroll.scrollTop = scroll.offsetHeight / 5;
1715
+ await waitFor(async () => {
1716
+ await expect(viewport).toHaveAttribute('data-fade', 'both');
1717
+ });
1718
+ scroll.scrollTop = 0;
1719
+ await waitFor(async () => {
1720
+ await expect(viewport).toHaveAttribute('data-fade', 'bottom');
1721
+ });
1722
+ },
1723
+ );
1724
+
1725
+ await step(
1726
+ 'interaction: a submenu stacks next to its row at the parent width, over the dimmed parent',
1727
+ async () => {
1728
+ const menu = body.getAllByRole('menu')[0];
1729
+ const row = body.getByRole('menuitem', { name: 'Connectors' });
1730
+ await userEvent.click(row);
1731
+ await expectStackedSubmenu(menu, row);
1732
+ await expect(
1733
+ menu.matches(
1734
+ ':has([data-slot="dropdown-menu-sub-trigger"][data-state="open"])',
1735
+ ),
1736
+ ).toBe(true);
1737
+ },
1738
+ );
1739
+
1740
+ await step(
1741
+ 'interaction: moving the pointer from the row into the submenu keeps it open',
1742
+ async () => {
1743
+ const row = body.getByRole('menuitem', { name: 'Connectors' });
1744
+ const webSearch = body.getByRole('menuitemcheckbox', {
1745
+ name: 'Web search',
1746
+ });
1747
+ await userEvent.hover(row);
1748
+ await userEvent.hover(webSearch);
1749
+ await expect(webSearch).toBeVisible();
1750
+ await expect(row).toHaveAttribute('aria-expanded', 'true');
1751
+ },
1752
+ );
1753
+
1754
+ await step(
1755
+ 'interaction: choosing a connector flips it and leaves the submenu open',
1756
+ async () => {
1757
+ const webSearch = body.getByRole('menuitemcheckbox', {
1758
+ name: 'Web search',
1759
+ });
1760
+ await expect(webSearch).toHaveAttribute('aria-checked', 'true');
1761
+ await userEvent.click(webSearch);
1762
+ await expect(webSearch).toHaveAttribute('aria-checked', 'false');
1763
+ await expect(webSearch).toBeVisible();
1764
+ },
1765
+ );
1766
+ },
1767
+ };
1768
+
1246
1769
  const avatarTriggerTemplateSource = `<script setup lang="ts">
1247
1770
  import { ref } from 'vue'
1248
1771
  import {
@@ -1366,6 +1889,9 @@ const stayOpen = {
1366
1889
  /**
1367
1890
  * An open menu for the accessibility story. The theme class goes on the content
1368
1891
  * itself, since the menu is portalled out of any wrapper further up the page.
1892
+ * Pinned open with `:avoid-collisions="false"`, it ignores the viewport, so it
1893
+ * also drops the height limit reka-ui derives from the space beside the
1894
+ * trigger, which low on the page would make it scroll.
1369
1895
  * @param themeClass Extra classes for the menu surface.
1370
1896
  */
1371
1897
  const themedMenu = (themeClass = '') => `
@@ -1375,7 +1901,7 @@ const themedMenu = (themeClass = '') => `
1375
1901
  </UiDropdownMenuTrigger>
1376
1902
  <UiDropdownMenuContent
1377
1903
  v-bind="stayOpen"
1378
- class="w-56 ${themeClass}"
1904
+ class="w-56 max-h-none ${themeClass}"
1379
1905
  align="start"
1380
1906
  :avoid-collisions="false"
1381
1907
  >
@@ -1445,7 +1971,10 @@ export const Accessibility: Story = {
1445
1971
  <li>An item that leads to a second level says so, and opens with the right arrow key as well as on hover.</li>
1446
1972
  <li>Enter or Space opens the menu, the arrow keys walk it, Home and End jump to its ends, and Escape closes it and puts focus back on the trigger.</li>
1447
1973
  <li>A modal menu hides the rest of the page from assistive technology. Pass <code class="label-14-regular">:modal="false"</code> when what is behind the menu should stay available.</li>
1448
- <li>Triggers need a touch target of at least 24px.</li>
1974
+ <li>Triggers need a touch target of at least 24px; every row is 36px tall, so it meets that on its own.</li>
1975
+ <li>On a phone only five rows are in view and the rest scroll under a fade. The fade is decoration: the rows behind it are still in the tree, the arrow keys still reach them, and the list scrolls to keep the focused row visible.</li>
1976
+ <li>On a phone a second level opens stacked 8px above or below its row, as wide as the menu, and dims the rest of the menu. It is still a menu named by its row: the row says it is expanded, the right arrow key opens it and moves focus into it, and the left arrow key closes it and puts focus back on the row.</li>
1977
+ <li>Put the checked state on the row, not on a control inside it: a switch or checkbox inside a menu item is nested interactive content. Give the row <code class="label-14-regular">role="menuitemcheckbox"</code> and <code class="label-14-regular">aria-checked</code>, and mark the visual control <code class="label-14-regular">inert</code>.</li>
1449
1978
  </ul>
1450
1979
  </div>
1451
1980
 
@@ -1508,6 +2037,65 @@ async function expectOpenMenu(body: ReturnType<typeof within>) {
1508
2037
  return menu;
1509
2038
  }
1510
2039
 
2040
+ /**
2041
+ * The fade wrapper and the scroll box of an open menu below the `sm`
2042
+ * breakpoint.
2043
+ * @param menu The `role="menu"` element.
2044
+ */
2045
+ function getMobileViewport(menu: HTMLElement) {
2046
+ const viewport = menu.querySelector<HTMLElement>(
2047
+ '[data-slot="dropdown-menu-viewport"]',
2048
+ );
2049
+ const scroll = menu.querySelector<HTMLElement>(
2050
+ '[data-slot="dropdown-menu-scroll"]',
2051
+ );
2052
+ if (!viewport || !scroll) {
2053
+ throw new Error('The menu has no mobile viewport.');
2054
+ }
2055
+ return { viewport, scroll };
2056
+ }
2057
+
2058
+ /**
2059
+ * Waits for the submenu opened from `row` to be placed the mobile way: visible,
2060
+ * labelled by its row, stacked 8px above or below that row, as wide as the
2061
+ * parent, flush with its left edge, and inside the viewport. Resolves with the
2062
+ * submenu element.
2063
+ * @param parent The parent `role="menu"` element.
2064
+ * @param row The submenu trigger row inside `parent`.
2065
+ */
2066
+ async function expectStackedSubmenu(parent: HTMLElement, row: HTMLElement) {
2067
+ const submenu = await waitFor(() => {
2068
+ const found = Array.from(
2069
+ document.querySelectorAll<HTMLElement>('[role="menu"]'),
2070
+ ).find((menu) => menu.getAttribute('aria-labelledby') === row.id);
2071
+ if (!found) throw new Error('The submenu is not open.');
2072
+ return found;
2073
+ });
2074
+ await waitFor(async () => {
2075
+ const side = submenu.dataset.mobileSide;
2076
+ await expect(['top', 'bottom']).toContain(side);
2077
+ await expect(row).toHaveAttribute('data-mobile-submenu-side', side);
2078
+ await expect(submenu).toBeVisible();
2079
+ // The open animation scales the panel for a few frames, so keep measuring
2080
+ // until the rects settle. A scaled phone frame shrinks every rect by the
2081
+ // same factor, so compare against the parent's rect, not CSS pixels.
2082
+ const parentRect = parent.getBoundingClientRect();
2083
+ const rowRect = row.getBoundingClientRect();
2084
+ const subRect = submenu.getBoundingClientRect();
2085
+ const scale = parentRect.width / parent.offsetWidth;
2086
+ const gap =
2087
+ side === 'top'
2088
+ ? rowRect.top - subRect.bottom
2089
+ : subRect.top - rowRect.bottom;
2090
+ await expect(Math.abs(subRect.width - parentRect.width)).toBeLessThan(1);
2091
+ await expect(Math.abs(subRect.left - parentRect.left)).toBeLessThan(1);
2092
+ await expect(Math.abs(gap - 8 * scale)).toBeLessThan(1);
2093
+ await expect(subRect.top).toBeGreaterThanOrEqual(0);
2094
+ await expect(subRect.bottom).toBeLessThanOrEqual(window.innerHeight);
2095
+ });
2096
+ return submenu;
2097
+ }
2098
+
1511
2099
  /**
1512
2100
  * The menu the test stories drive: a plain item, a disabled one, a checkbox, a
1513
2101
  * radio group and a submenu, so one menu exercises every item type. Closed on
@@ -1843,6 +2431,20 @@ export const ZoomMagnification: Story = {
1843
2431
  body.getByRole('menuitem', { name: 'Settings' }),
1844
2432
  ).toBeVisible();
1845
2433
  });
2434
+
2435
+ await step(
2436
+ 'zoom: the submenu opens and its items stay readable',
2437
+ async () => {
2438
+ await userEvent.click(
2439
+ body.getByRole('menuitem', { name: 'Invite users' }),
2440
+ );
2441
+ await waitFor(async () => {
2442
+ await expect(
2443
+ body.getByRole('menuitem', { name: 'Email' }),
2444
+ ).toBeVisible();
2445
+ });
2446
+ },
2447
+ );
1846
2448
  },
1847
2449
  };
1848
2450
 
@@ -1868,7 +2470,9 @@ export const MobileBreakpoint: Story = {
1868
2470
  render: renderTestMenu,
1869
2471
  play: async ({ canvasElement, step }) => {
1870
2472
  // Scenario (UiDropdownMenu): at the 320px mobile breakpoint the trigger is
1871
- // a large enough touch target and the menu opens within the viewport.
2473
+ // a large enough touch target, the menu opens within the viewport with
2474
+ // five rows in view and the rest reachable by scrolling, and a row can
2475
+ // still be chosen.
1872
2476
  const canvas = within(canvasElement);
1873
2477
  const body = within(document.body);
1874
2478
  const trigger = canvas.getByRole('button', { name: 'Open Menu' });
@@ -1886,14 +2490,198 @@ export const MobileBreakpoint: Story = {
1886
2490
  );
1887
2491
 
1888
2492
  await step(
1889
- 'mobile: the menu opens and its items stay operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
2493
+ 'mobile: the menu opens within the viewport with five rows in view (WCAG 1.4.10 Reflow)',
1890
2494
  async () => {
1891
2495
  await userEvent.click(trigger);
1892
- await expectOpenMenu(body);
1893
- await userEvent.click(body.getByRole('menuitem', { name: 'Settings' }));
2496
+ const menu = await expectOpenMenu(body);
2497
+ const { viewport, scroll } = getMobileViewport(menu);
2498
+ const row = body.getByRole('menuitem', { name: 'Settings' });
2499
+ await expect(scroll.clientHeight).toBe(row.offsetHeight * 5);
2500
+ await expect(scroll.scrollHeight).toBeGreaterThan(scroll.clientHeight);
2501
+ await expect(viewport).toHaveAttribute('data-fade', 'bottom');
2502
+ const rect = menu.getBoundingClientRect();
2503
+ await expect(rect.left).toBeGreaterThanOrEqual(0);
2504
+ await expect(rect.right).toBeLessThanOrEqual(window.innerWidth);
2505
+ await expect(rect.top).toBeGreaterThanOrEqual(0);
2506
+ await expect(rect.bottom).toBeLessThanOrEqual(window.innerHeight);
2507
+ },
2508
+ );
2509
+
2510
+ await step(
2511
+ 'mobile: every row meets the minimum touch-target size (WCAG 2.5.8)',
2512
+ async () => {
2513
+ for (const row of body.getAllByRole('menuitem')) {
2514
+ const { height } = getComputedStyle(row);
2515
+ await expect(Number.parseFloat(height)).toBeGreaterThanOrEqual(24);
2516
+ }
2517
+ },
2518
+ );
2519
+
2520
+ await step(
2521
+ 'mobile: the rows past the fade are reachable by scrolling, and the fade follows',
2522
+ async () => {
2523
+ const menu = body.getAllByRole('menu')[0];
2524
+ const { viewport, scroll } = getMobileViewport(menu);
2525
+ scroll.scrollTop = scroll.scrollHeight;
2526
+ await waitFor(async () => {
2527
+ await expect(viewport).toHaveAttribute('data-fade', 'top');
2528
+ });
2529
+ await expect(
2530
+ body.getByRole('menuitem', { name: 'Invite users' }),
2531
+ ).toBeVisible();
2532
+ },
2533
+ );
2534
+
2535
+ await step('mobile: choosing a row closes the menu', async () => {
2536
+ await userEvent.click(body.getByRole('menuitem', { name: 'Settings' }));
2537
+ await waitFor(async () => {
2538
+ await expect(body.queryByRole('menu')).toBeNull();
2539
+ });
2540
+ });
2541
+ },
2542
+ };
2543
+
2544
+ /**
2545
+ * The submenu below the `sm` breakpoint: stacked 8px above or below its row at
2546
+ * the parent's width, reachable with the keyboard, and announced the same way
2547
+ * as on desktop. Hidden test-only story.
2548
+ */
2549
+ export const MobileSubmenu: Story = {
2550
+ name: 'test - Mobile submenu',
2551
+ tags: ['!dev', '!autodocs'],
2552
+ globals: { mediaBreakpoint: 'reflow' },
2553
+ parameters: {
2554
+ // The play moves focus into the submenu, and the reflow Chromatic mode
2555
+ // already snapshots the mobile layout.
2556
+ chromatic: { disableSnapshot: true },
2557
+ docs: {
2558
+ description: {
2559
+ story:
2560
+ 'Switch the Media breakpoint toolbar to Mobile and open "Invite users" to see the stacked submenu.',
2561
+ },
2562
+ },
2563
+ },
2564
+ render: renderTestMenu,
2565
+ play: async ({ canvasElement, step }) => {
2566
+ // Scenario (UiDropdownMenu): on a phone a keyboard user opens the menu,
2567
+ // walks down to the last row (which the list scrolls into view), opens the
2568
+ // submenu with ArrowRight and gets it stacked next to that row, hears it
2569
+ // announced as a menu named by its row, closes it with ArrowLeft and lands
2570
+ // back on the row, and finally dismisses everything with Escape.
2571
+ const canvas = within(canvasElement);
2572
+ const body = within(document.body);
2573
+ const trigger = canvas.getByRole('button', { name: 'Open Menu' });
2574
+
2575
+ await step(
2576
+ 'keyboard: Enter opens the menu and End scrolls the last row into view (WCAG 2.4.3)',
2577
+ async () => {
2578
+ await userEvent.tab();
2579
+ await expect(trigger).toHaveFocus();
2580
+ await userEvent.keyboard('{Enter}');
2581
+ const menu = await expectOpenMenu(body);
2582
+ const { viewport, scroll } = getMobileViewport(menu);
2583
+ await expect(viewport).toHaveAttribute('data-fade', 'bottom');
2584
+ await userEvent.keyboard('{End}');
2585
+ const invite = body.getByRole('menuitem', { name: 'Invite users' });
2586
+ await expect(invite).toHaveFocus();
2587
+ await waitFor(async () => {
2588
+ await expect(scroll.scrollTop).toBeGreaterThan(0);
2589
+ await expect(viewport).toHaveAttribute('data-fade', 'top');
2590
+ });
2591
+ },
2592
+ );
2593
+
2594
+ await step(
2595
+ 'keyboard: ArrowRight opens the stacked submenu and moves focus into it',
2596
+ async () => {
2597
+ const menu = body.getAllByRole('menu')[0];
2598
+ const invite = body.getByRole('menuitem', { name: 'Invite users' });
2599
+ await userEvent.keyboard('{ArrowRight}');
2600
+ await expectStackedSubmenu(menu, invite);
2601
+ await waitFor(async () => {
2602
+ await expect(
2603
+ body.getByRole('menuitem', { name: 'Email' }),
2604
+ ).toHaveFocus();
2605
+ });
2606
+ },
2607
+ );
2608
+
2609
+ await step(
2610
+ 'screen-reader: the stacked submenu is a menu named by its row, which reports it as expanded (WCAG 4.1.2)',
2611
+ async () => {
2612
+ const invite = body.getByRole('menuitem', { name: 'Invite users' });
2613
+ const submenu = body
2614
+ .getAllByRole('menu')
2615
+ .find((menu) => menu.getAttribute('aria-labelledby') === invite.id);
2616
+ await expect(submenu).toBeDefined();
2617
+ await expect(submenu).toHaveAccessibleName('Invite users');
2618
+ await expect(invite).toHaveAttribute('aria-haspopup', 'menu');
2619
+ await expect(invite).toHaveAttribute('aria-expanded', 'true');
2620
+ await expect(invite).toHaveAttribute('aria-controls', submenu?.id);
2621
+ },
2622
+ );
2623
+
2624
+ await step(
2625
+ 'screen-reader: the fade bands are decoration and hidden from assistive technology',
2626
+ async () => {
2627
+ for (const menu of body.getAllByRole('menu')) {
2628
+ const { viewport } = getMobileViewport(menu);
2629
+ for (const band of viewport.querySelectorAll('.ui-fade-mask__band')) {
2630
+ await expect(band).toHaveAttribute('aria-hidden', 'true');
2631
+ }
2632
+ }
2633
+ },
2634
+ );
2635
+
2636
+ await step(
2637
+ 'mobile: the submenu rows meet the minimum touch-target size (WCAG 2.5.8)',
2638
+ async () => {
2639
+ const email = body.getByRole('menuitem', { name: 'Email' });
2640
+ const { height } = getComputedStyle(email);
2641
+ await expect(Number.parseFloat(height)).toBeGreaterThanOrEqual(24);
2642
+ },
2643
+ );
2644
+
2645
+ await step(
2646
+ 'mobile: the parent takes an overlay while the submenu covers it',
2647
+ async () => {
2648
+ const menu = body.getAllByRole('menu')[0];
2649
+ await expect(
2650
+ menu.matches(
2651
+ ':has([data-slot="dropdown-menu-sub-trigger"][data-state="open"])',
2652
+ ),
2653
+ ).toBe(true);
2654
+ },
2655
+ );
2656
+
2657
+ await step(
2658
+ 'keyboard: ArrowLeft closes the submenu and puts focus back on its row',
2659
+ async () => {
2660
+ const invite = body.getByRole('menuitem', { name: 'Invite users' });
2661
+ await userEvent.keyboard('{ArrowLeft}');
2662
+ await waitFor(async () => {
2663
+ await expect(
2664
+ body.queryByRole('menuitem', { name: 'Email' }),
2665
+ ).toBeNull();
2666
+ });
2667
+ await waitFor(async () => {
2668
+ await expect(invite).toHaveFocus();
2669
+ });
2670
+ await expect(invite).toHaveAttribute('aria-expanded', 'false');
2671
+ await expect(invite).not.toHaveAttribute('data-mobile-submenu-side');
2672
+ },
2673
+ );
2674
+
2675
+ await step(
2676
+ 'keyboard: Escape closes the menu and restores focus to the trigger (WCAG 2.1.2)',
2677
+ async () => {
2678
+ await userEvent.keyboard('{Escape}');
1894
2679
  await waitFor(async () => {
1895
2680
  await expect(body.queryByRole('menu')).toBeNull();
1896
2681
  });
2682
+ await waitFor(async () => {
2683
+ await expect(trigger).toHaveFocus();
2684
+ });
1897
2685
  },
1898
2686
  );
1899
2687
  },