@aleph-alpha/ui-library 5.8.0 → 5.10.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.
- package/README.md +8 -7
- package/config.js +157 -4
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
- package/dist/system/components/UiFileType/types.d.ts +2 -1
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
- package/dist/system/components/UiSwitch/types.d.ts +12 -0
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
- package/dist/system/components/core/switch/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/scrollbar.d.ts +37 -0
- package/dist/system/lib/useAnchorFloat.d.ts +0 -2
- package/dist/system/lib/useIsTruncated.d.ts +15 -0
- package/dist/system/lib.js +22660 -21292
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -2
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +7 -1
- package/docs/public-docs/foundations.md +17 -15
- package/package.json +4 -3
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiFileItem/UiFileItem.vue +17 -4
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
- package/src/components/UiFileType/UiFileType.stories.ts +13 -2
- package/src/components/UiFileType/UiFileType.vue +8 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
- package/src/components/UiFileType/types.ts +3 -1
- package/src/components/UiListbox/UiListbox.stories.ts +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
- package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
- package/src/components/UiSwitch/UiSwitch.vue +1 -0
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
- package/src/components/UiSwitch/types.ts +13 -0
- package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/switch/Switch.vue +23 -17
- package/src/components/core/switch/index.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/lib/scrollbar.ts +295 -0
- package/src/lib/useAnchorFloat.ts +0 -2
- package/src/lib/useIsTruncated.test.ts +174 -0
- package/src/lib/useIsTruncated.ts +75 -0
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -6
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -12
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -2
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1079 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
- package/src/theme/Background.stories.ts +27 -1
- package/src/theme/BorderRadius.stories.ts +5 -0
- package/src/theme/Overlay.stories.ts +12 -1
- package/src/theme/Scrollbar.stories.ts +260 -0
- package/tokens.json +224 -2
- package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
|
@@ -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 { computed, ref, watch } from 'vue';
|
|
3
4
|
import {
|
|
4
5
|
UiDropdownMenu,
|
|
@@ -1029,6 +1030,219 @@ export const WithSoftToggleTriggerAndText: Story = {
|
|
|
1029
1030
|
},
|
|
1030
1031
|
};
|
|
1031
1032
|
|
|
1033
|
+
const itemTypesTemplateSource = `<script setup lang="ts">
|
|
1034
|
+
import { ref } from 'vue'
|
|
1035
|
+
import {
|
|
1036
|
+
UiDropdownMenu,
|
|
1037
|
+
UiDropdownMenuTrigger,
|
|
1038
|
+
UiDropdownMenuContent,
|
|
1039
|
+
UiDropdownMenuItem,
|
|
1040
|
+
UiDropdownMenuLabel,
|
|
1041
|
+
UiDropdownMenuSeparator,
|
|
1042
|
+
UiDropdownMenuShortcut,
|
|
1043
|
+
UiDropdownMenuCheckboxItem,
|
|
1044
|
+
UiDropdownMenuRadioGroup,
|
|
1045
|
+
UiDropdownMenuRadioItem,
|
|
1046
|
+
UiDropdownMenuSub,
|
|
1047
|
+
UiDropdownMenuSubTrigger,
|
|
1048
|
+
UiDropdownMenuSubContent,
|
|
1049
|
+
UiButton,
|
|
1050
|
+
UiIcon,
|
|
1051
|
+
} from '@aleph-alpha/ui-library'
|
|
1052
|
+
|
|
1053
|
+
const open = ref(false)
|
|
1054
|
+
const checked = ref(true)
|
|
1055
|
+
const position = ref('default')
|
|
1056
|
+
</script>
|
|
1057
|
+
|
|
1058
|
+
<template>
|
|
1059
|
+
<UiDropdownMenu v-model:open="open">
|
|
1060
|
+
<UiDropdownMenuTrigger as-child>
|
|
1061
|
+
<UiButton variant="outline">Menu Items</UiButton>
|
|
1062
|
+
</UiDropdownMenuTrigger>
|
|
1063
|
+
<UiDropdownMenuContent class="w-64" align="start">
|
|
1064
|
+
<UiDropdownMenuLabel>Default</UiDropdownMenuLabel>
|
|
1065
|
+
<UiDropdownMenuItem>
|
|
1066
|
+
Menu item text
|
|
1067
|
+
<UiDropdownMenuShortcut>⌘P</UiDropdownMenuShortcut>
|
|
1068
|
+
</UiDropdownMenuItem>
|
|
1069
|
+
<UiDropdownMenuItem disabled>
|
|
1070
|
+
Menu item text
|
|
1071
|
+
<UiDropdownMenuShortcut>⌘P</UiDropdownMenuShortcut>
|
|
1072
|
+
</UiDropdownMenuItem>
|
|
1073
|
+
<UiDropdownMenuSeparator />
|
|
1074
|
+
|
|
1075
|
+
<UiDropdownMenuLabel>Checkbox</UiDropdownMenuLabel>
|
|
1076
|
+
<UiDropdownMenuCheckboxItem v-model:checked="checked">
|
|
1077
|
+
Checkbox
|
|
1078
|
+
</UiDropdownMenuCheckboxItem>
|
|
1079
|
+
<UiDropdownMenuCheckboxItem :checked="false" disabled>
|
|
1080
|
+
Checkbox
|
|
1081
|
+
</UiDropdownMenuCheckboxItem>
|
|
1082
|
+
<UiDropdownMenuSeparator />
|
|
1083
|
+
|
|
1084
|
+
<UiDropdownMenuLabel>Radio</UiDropdownMenuLabel>
|
|
1085
|
+
<UiDropdownMenuRadioGroup v-model="position">
|
|
1086
|
+
<UiDropdownMenuRadioItem value="default">Radio Button</UiDropdownMenuRadioItem>
|
|
1087
|
+
<UiDropdownMenuRadioItem value="disabled" disabled>Radio Button</UiDropdownMenuRadioItem>
|
|
1088
|
+
</UiDropdownMenuRadioGroup>
|
|
1089
|
+
<UiDropdownMenuSeparator />
|
|
1090
|
+
|
|
1091
|
+
<UiDropdownMenuLabel>Icon</UiDropdownMenuLabel>
|
|
1092
|
+
<UiDropdownMenuItem>
|
|
1093
|
+
<UiIcon name="check" :size="16" />
|
|
1094
|
+
Menu item text
|
|
1095
|
+
<UiIcon name="info" :size="16" class="ml-auto" />
|
|
1096
|
+
</UiDropdownMenuItem>
|
|
1097
|
+
<UiDropdownMenuItem disabled>
|
|
1098
|
+
<UiIcon name="check" :size="16" />
|
|
1099
|
+
Menu item text
|
|
1100
|
+
<UiIcon name="info" :size="16" class="ml-auto" />
|
|
1101
|
+
</UiDropdownMenuItem>
|
|
1102
|
+
<UiDropdownMenuSeparator />
|
|
1103
|
+
|
|
1104
|
+
<UiDropdownMenuLabel>SubTrigger</UiDropdownMenuLabel>
|
|
1105
|
+
<UiDropdownMenuSub>
|
|
1106
|
+
<UiDropdownMenuSubTrigger>
|
|
1107
|
+
<UiIcon name="info" :size="16" class="mr-2" />
|
|
1108
|
+
Menu item text
|
|
1109
|
+
</UiDropdownMenuSubTrigger>
|
|
1110
|
+
<UiDropdownMenuSubContent>
|
|
1111
|
+
<UiDropdownMenuItem>Submenu item</UiDropdownMenuItem>
|
|
1112
|
+
</UiDropdownMenuSubContent>
|
|
1113
|
+
</UiDropdownMenuSub>
|
|
1114
|
+
<UiDropdownMenuSub>
|
|
1115
|
+
<UiDropdownMenuSubTrigger disabled>
|
|
1116
|
+
<UiIcon name="info" :size="16" class="mr-2" />
|
|
1117
|
+
Menu item text
|
|
1118
|
+
</UiDropdownMenuSubTrigger>
|
|
1119
|
+
<UiDropdownMenuSubContent>
|
|
1120
|
+
<UiDropdownMenuItem>Submenu item</UiDropdownMenuItem>
|
|
1121
|
+
</UiDropdownMenuSubContent>
|
|
1122
|
+
</UiDropdownMenuSub>
|
|
1123
|
+
</UiDropdownMenuContent>
|
|
1124
|
+
</UiDropdownMenu>
|
|
1125
|
+
</template>`;
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* Every menu item type — plain item with shortcut, checkbox, radio, item with
|
|
1129
|
+
* leading and trailing icons, and submenu trigger — each shown in its default
|
|
1130
|
+
* and disabled state.
|
|
1131
|
+
*/
|
|
1132
|
+
export const ItemTypes: Story = {
|
|
1133
|
+
render: (args) => ({
|
|
1134
|
+
components: {
|
|
1135
|
+
UiDropdownMenu,
|
|
1136
|
+
UiDropdownMenuTrigger,
|
|
1137
|
+
UiDropdownMenuContent,
|
|
1138
|
+
UiDropdownMenuItem,
|
|
1139
|
+
UiDropdownMenuLabel,
|
|
1140
|
+
UiDropdownMenuSeparator,
|
|
1141
|
+
UiDropdownMenuShortcut,
|
|
1142
|
+
UiDropdownMenuCheckboxItem,
|
|
1143
|
+
UiDropdownMenuRadioGroup,
|
|
1144
|
+
UiDropdownMenuRadioItem,
|
|
1145
|
+
UiDropdownMenuSub,
|
|
1146
|
+
UiDropdownMenuSubTrigger,
|
|
1147
|
+
UiDropdownMenuSubContent,
|
|
1148
|
+
UiButton,
|
|
1149
|
+
UiIcon,
|
|
1150
|
+
},
|
|
1151
|
+
setup() {
|
|
1152
|
+
const open = ref(args.open);
|
|
1153
|
+
const modal = ref(args.modal);
|
|
1154
|
+
const checked = ref(true);
|
|
1155
|
+
const position = ref('default');
|
|
1156
|
+
watch(
|
|
1157
|
+
() => args.open,
|
|
1158
|
+
(v) => {
|
|
1159
|
+
open.value = v;
|
|
1160
|
+
},
|
|
1161
|
+
);
|
|
1162
|
+
watch(
|
|
1163
|
+
() => args.modal,
|
|
1164
|
+
(v) => {
|
|
1165
|
+
modal.value = v;
|
|
1166
|
+
},
|
|
1167
|
+
);
|
|
1168
|
+
return { open, modal, checked, position };
|
|
1169
|
+
},
|
|
1170
|
+
template: `<UiDropdownMenu v-model:open="open" :modal="modal">
|
|
1171
|
+
<UiDropdownMenuTrigger as-child>
|
|
1172
|
+
<UiButton variant="outline">Menu Items</UiButton>
|
|
1173
|
+
</UiDropdownMenuTrigger>
|
|
1174
|
+
<UiDropdownMenuContent class="w-64" align="start">
|
|
1175
|
+
<UiDropdownMenuLabel>Default</UiDropdownMenuLabel>
|
|
1176
|
+
<UiDropdownMenuItem>
|
|
1177
|
+
Menu item text
|
|
1178
|
+
<UiDropdownMenuShortcut>⌘P</UiDropdownMenuShortcut>
|
|
1179
|
+
</UiDropdownMenuItem>
|
|
1180
|
+
<UiDropdownMenuItem disabled>
|
|
1181
|
+
Menu item text
|
|
1182
|
+
<UiDropdownMenuShortcut>⌘P</UiDropdownMenuShortcut>
|
|
1183
|
+
</UiDropdownMenuItem>
|
|
1184
|
+
<UiDropdownMenuSeparator />
|
|
1185
|
+
|
|
1186
|
+
<UiDropdownMenuLabel>Checkbox</UiDropdownMenuLabel>
|
|
1187
|
+
<UiDropdownMenuCheckboxItem v-model:checked="checked">
|
|
1188
|
+
Checkbox
|
|
1189
|
+
</UiDropdownMenuCheckboxItem>
|
|
1190
|
+
<UiDropdownMenuCheckboxItem :checked="false" disabled>
|
|
1191
|
+
Checkbox
|
|
1192
|
+
</UiDropdownMenuCheckboxItem>
|
|
1193
|
+
<UiDropdownMenuSeparator />
|
|
1194
|
+
|
|
1195
|
+
<UiDropdownMenuLabel>Radio</UiDropdownMenuLabel>
|
|
1196
|
+
<UiDropdownMenuRadioGroup v-model="position">
|
|
1197
|
+
<UiDropdownMenuRadioItem value="default">Radio Button</UiDropdownMenuRadioItem>
|
|
1198
|
+
<UiDropdownMenuRadioItem value="disabled" disabled>Radio Button</UiDropdownMenuRadioItem>
|
|
1199
|
+
</UiDropdownMenuRadioGroup>
|
|
1200
|
+
<UiDropdownMenuSeparator />
|
|
1201
|
+
|
|
1202
|
+
<UiDropdownMenuLabel>Icon</UiDropdownMenuLabel>
|
|
1203
|
+
<UiDropdownMenuItem>
|
|
1204
|
+
<UiIcon name="check" :size="16" />
|
|
1205
|
+
Menu item text
|
|
1206
|
+
<UiIcon name="info" :size="16" class="ml-auto" />
|
|
1207
|
+
</UiDropdownMenuItem>
|
|
1208
|
+
<UiDropdownMenuItem disabled>
|
|
1209
|
+
<UiIcon name="check" :size="16" />
|
|
1210
|
+
Menu item text
|
|
1211
|
+
<UiIcon name="info" :size="16" class="ml-auto" />
|
|
1212
|
+
</UiDropdownMenuItem>
|
|
1213
|
+
<UiDropdownMenuSeparator />
|
|
1214
|
+
|
|
1215
|
+
<UiDropdownMenuLabel>SubTrigger</UiDropdownMenuLabel>
|
|
1216
|
+
<UiDropdownMenuSub>
|
|
1217
|
+
<UiDropdownMenuSubTrigger>
|
|
1218
|
+
<UiIcon name="info" :size="16" class="mr-2" />
|
|
1219
|
+
Menu item text
|
|
1220
|
+
</UiDropdownMenuSubTrigger>
|
|
1221
|
+
<UiDropdownMenuSubContent>
|
|
1222
|
+
<UiDropdownMenuItem>Submenu item</UiDropdownMenuItem>
|
|
1223
|
+
</UiDropdownMenuSubContent>
|
|
1224
|
+
</UiDropdownMenuSub>
|
|
1225
|
+
<UiDropdownMenuSub>
|
|
1226
|
+
<UiDropdownMenuSubTrigger disabled>
|
|
1227
|
+
<UiIcon name="info" :size="16" class="mr-2" />
|
|
1228
|
+
Menu item text
|
|
1229
|
+
</UiDropdownMenuSubTrigger>
|
|
1230
|
+
<UiDropdownMenuSubContent>
|
|
1231
|
+
<UiDropdownMenuItem>Submenu item</UiDropdownMenuItem>
|
|
1232
|
+
</UiDropdownMenuSubContent>
|
|
1233
|
+
</UiDropdownMenuSub>
|
|
1234
|
+
</UiDropdownMenuContent>
|
|
1235
|
+
</UiDropdownMenu>`,
|
|
1236
|
+
}),
|
|
1237
|
+
parameters: {
|
|
1238
|
+
docs: {
|
|
1239
|
+
source: {
|
|
1240
|
+
code: itemTypesTemplateSource,
|
|
1241
|
+
},
|
|
1242
|
+
},
|
|
1243
|
+
},
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1032
1246
|
const avatarTriggerTemplateSource = `<script setup lang="ts">
|
|
1033
1247
|
import { ref } from 'vue'
|
|
1034
1248
|
import {
|
|
@@ -1137,3 +1351,549 @@ export const WithAvatarTrigger: Story = {
|
|
|
1137
1351
|
},
|
|
1138
1352
|
},
|
|
1139
1353
|
};
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Bound to the outside-interaction events of the menus in the accessibility
|
|
1357
|
+
* story, which sit open side by side. A menu taking focus reads as an outside
|
|
1358
|
+
* interaction to the other one, which would otherwise dismiss itself.
|
|
1359
|
+
*/
|
|
1360
|
+
const stayOpen = {
|
|
1361
|
+
onFocusOutside: (event: Event) => event.preventDefault(),
|
|
1362
|
+
onPointerDownOutside: (event: Event) => event.preventDefault(),
|
|
1363
|
+
onInteractOutside: (event: Event) => event.preventDefault(),
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* An open menu for the accessibility story. The theme class goes on the content
|
|
1368
|
+
* itself, since the menu is portalled out of any wrapper further up the page.
|
|
1369
|
+
* @param themeClass Extra classes for the menu surface.
|
|
1370
|
+
*/
|
|
1371
|
+
const themedMenu = (themeClass = '') => `
|
|
1372
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
1373
|
+
<UiDropdownMenuTrigger as-child>
|
|
1374
|
+
<UiButton variant="outline">Open Menu</UiButton>
|
|
1375
|
+
</UiDropdownMenuTrigger>
|
|
1376
|
+
<UiDropdownMenuContent
|
|
1377
|
+
v-bind="stayOpen"
|
|
1378
|
+
class="w-56 ${themeClass}"
|
|
1379
|
+
align="start"
|
|
1380
|
+
:avoid-collisions="false"
|
|
1381
|
+
>
|
|
1382
|
+
<UiDropdownMenuLabel>My account</UiDropdownMenuLabel>
|
|
1383
|
+
<UiDropdownMenuItem>Profile</UiDropdownMenuItem>
|
|
1384
|
+
<UiDropdownMenuItem disabled>Billing</UiDropdownMenuItem>
|
|
1385
|
+
<UiDropdownMenuSeparator />
|
|
1386
|
+
<UiDropdownMenuCheckboxItem :checked="true">
|
|
1387
|
+
Notifications
|
|
1388
|
+
</UiDropdownMenuCheckboxItem>
|
|
1389
|
+
<UiDropdownMenuSeparator />
|
|
1390
|
+
<UiDropdownMenuSub>
|
|
1391
|
+
<UiDropdownMenuSubTrigger>Invite users</UiDropdownMenuSubTrigger>
|
|
1392
|
+
<UiDropdownMenuSubContent>
|
|
1393
|
+
<UiDropdownMenuItem>Email</UiDropdownMenuItem>
|
|
1394
|
+
</UiDropdownMenuSubContent>
|
|
1395
|
+
</UiDropdownMenuSub>
|
|
1396
|
+
</UiDropdownMenuContent>
|
|
1397
|
+
</UiDropdownMenu>
|
|
1398
|
+
`;
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* How the menu behaves for keyboard and screen-reader users.
|
|
1402
|
+
*/
|
|
1403
|
+
export const Accessibility: Story = {
|
|
1404
|
+
tags: ['!autodocs'],
|
|
1405
|
+
parameters: {
|
|
1406
|
+
chromatic: { disableSnapshot: true },
|
|
1407
|
+
docs: { canvas: { sourceState: 'none' } },
|
|
1408
|
+
},
|
|
1409
|
+
render: () => ({
|
|
1410
|
+
components: {
|
|
1411
|
+
UiDropdownMenu,
|
|
1412
|
+
UiDropdownMenuTrigger,
|
|
1413
|
+
UiDropdownMenuContent,
|
|
1414
|
+
UiDropdownMenuItem,
|
|
1415
|
+
UiDropdownMenuLabel,
|
|
1416
|
+
UiDropdownMenuSeparator,
|
|
1417
|
+
UiDropdownMenuCheckboxItem,
|
|
1418
|
+
UiDropdownMenuSub,
|
|
1419
|
+
UiDropdownMenuSubTrigger,
|
|
1420
|
+
UiDropdownMenuSubContent,
|
|
1421
|
+
UiButton,
|
|
1422
|
+
},
|
|
1423
|
+
setup() {
|
|
1424
|
+
const open = ref(true);
|
|
1425
|
+
return { open, stayOpen };
|
|
1426
|
+
},
|
|
1427
|
+
template: `
|
|
1428
|
+
<section class="flex flex-col gap-6 p-4">
|
|
1429
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
1430
|
+
Accessibility
|
|
1431
|
+
</h2>
|
|
1432
|
+
|
|
1433
|
+
<div class="flex flex-col gap-2">
|
|
1434
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1435
|
+
Requirements
|
|
1436
|
+
</h3>
|
|
1437
|
+
<ul class="body-16-regular list-disc pl-5 text-content-on-surface-primary">
|
|
1438
|
+
<li>The trigger needs a name of its own: give an icon-only trigger an <code class="label-14-regular">aria-label</code>, since the icon is not read out.</li>
|
|
1439
|
+
<li>The trigger tells assistive technology that it opens a menu, and whether that menu is currently open.</li>
|
|
1440
|
+
<li>Every row is announced as a menu item, named by the text you can see; icons in an item are decoration and add nothing to that name.</li>
|
|
1441
|
+
<li>A label groups the items below it and is not a choice — it cannot be focused or activated.</li>
|
|
1442
|
+
<li>A disabled item says it is disabled and is skipped by the arrow keys, so it is never a dead end.</li>
|
|
1443
|
+
<li>Checkbox and radio items report checked and selected, so the state is spoken and not carried by the tick alone.</li>
|
|
1444
|
+
<li>An item that leads to a second level says so, and opens with the right arrow key as well as on hover.</li>
|
|
1445
|
+
<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>
|
|
1446
|
+
<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>
|
|
1447
|
+
<li>Triggers need a touch target of at least 24px.</li>
|
|
1448
|
+
</ul>
|
|
1449
|
+
</div>
|
|
1450
|
+
|
|
1451
|
+
<div class="flex flex-col gap-2">
|
|
1452
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1453
|
+
Enable accessibility theme
|
|
1454
|
+
</h3>
|
|
1455
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
1456
|
+
When accessibility is required, enable our accessibility theme. This
|
|
1457
|
+
increases contrast and ensures there are no color contrast issues.
|
|
1458
|
+
</p>
|
|
1459
|
+
</div>
|
|
1460
|
+
|
|
1461
|
+
<div class="flex flex-wrap gap-12">
|
|
1462
|
+
<div class="flex w-64 flex-col gap-3">
|
|
1463
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
1464
|
+
Default
|
|
1465
|
+
</h3>
|
|
1466
|
+
<div class="min-h-72">${themedMenu()}</div>
|
|
1467
|
+
</div>
|
|
1468
|
+
|
|
1469
|
+
<div class="flex w-64 flex-col gap-3">
|
|
1470
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
1471
|
+
Accessible
|
|
1472
|
+
</h3>
|
|
1473
|
+
<div class="min-h-72">${themedMenu('accessible-theme')}</div>
|
|
1474
|
+
</div>
|
|
1475
|
+
</div>
|
|
1476
|
+
</section>
|
|
1477
|
+
`,
|
|
1478
|
+
}),
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
/*
|
|
1482
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
1483
|
+
* Interaction & accessibility tests (play functions)
|
|
1484
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
1485
|
+
* Each story below is hidden from the sidebar and the docs page but still run
|
|
1486
|
+
* by the Storybook test-runner on every PR, alongside the axe audit. The
|
|
1487
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
1488
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
1489
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
1490
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2)
|
|
1491
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
1492
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
1493
|
+
*/
|
|
1494
|
+
|
|
1495
|
+
const onSelect = fn();
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* Waits for the menu to be open and painted. The content fades and zooms in, so
|
|
1499
|
+
* it is in the DOM a frame before it is visible.
|
|
1500
|
+
* @param body Queries bound to the document body, where the menu is portalled.
|
|
1501
|
+
*/
|
|
1502
|
+
async function expectOpenMenu(body: ReturnType<typeof within>) {
|
|
1503
|
+
const menu = await body.findByRole('menu');
|
|
1504
|
+
await waitFor(async () => {
|
|
1505
|
+
await expect(menu).toBeVisible();
|
|
1506
|
+
});
|
|
1507
|
+
return menu;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* The menu the test stories drive: a plain item, a disabled one, a checkbox, a
|
|
1512
|
+
* radio group and a submenu, so one menu exercises every item type. Closed on
|
|
1513
|
+
* load, so a play function can open it the way a user would.
|
|
1514
|
+
*/
|
|
1515
|
+
function renderTestMenu() {
|
|
1516
|
+
return {
|
|
1517
|
+
components: {
|
|
1518
|
+
UiDropdownMenu,
|
|
1519
|
+
UiDropdownMenuTrigger,
|
|
1520
|
+
UiDropdownMenuContent,
|
|
1521
|
+
UiDropdownMenuItem,
|
|
1522
|
+
UiDropdownMenuLabel,
|
|
1523
|
+
UiDropdownMenuSeparator,
|
|
1524
|
+
UiDropdownMenuCheckboxItem,
|
|
1525
|
+
UiDropdownMenuRadioGroup,
|
|
1526
|
+
UiDropdownMenuRadioItem,
|
|
1527
|
+
UiDropdownMenuSub,
|
|
1528
|
+
UiDropdownMenuSubTrigger,
|
|
1529
|
+
UiDropdownMenuSubContent,
|
|
1530
|
+
UiButton,
|
|
1531
|
+
},
|
|
1532
|
+
setup() {
|
|
1533
|
+
const open = ref(false);
|
|
1534
|
+
const notifications = ref(true);
|
|
1535
|
+
const position = ref('top');
|
|
1536
|
+
return { open, notifications, position, onSelect };
|
|
1537
|
+
},
|
|
1538
|
+
// Non-modal: a modal menu marks the rest of the page `aria-hidden` while
|
|
1539
|
+
// the trigger inside it stays focusable, and the axe audit that runs after
|
|
1540
|
+
// the play would report that background instead of auditing the open menu.
|
|
1541
|
+
template: `<div class="flex min-h-100 items-start p-6">
|
|
1542
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
1543
|
+
<UiDropdownMenuTrigger as-child>
|
|
1544
|
+
<UiButton variant="outline">Open Menu</UiButton>
|
|
1545
|
+
</UiDropdownMenuTrigger>
|
|
1546
|
+
<UiDropdownMenuContent class="w-56" align="start">
|
|
1547
|
+
<UiDropdownMenuLabel>My account</UiDropdownMenuLabel>
|
|
1548
|
+
<UiDropdownMenuItem @select="onSelect">Profile</UiDropdownMenuItem>
|
|
1549
|
+
<UiDropdownMenuItem>Settings</UiDropdownMenuItem>
|
|
1550
|
+
<UiDropdownMenuItem disabled>Billing</UiDropdownMenuItem>
|
|
1551
|
+
<UiDropdownMenuSeparator />
|
|
1552
|
+
<UiDropdownMenuCheckboxItem v-model:checked="notifications">
|
|
1553
|
+
Notifications
|
|
1554
|
+
</UiDropdownMenuCheckboxItem>
|
|
1555
|
+
<UiDropdownMenuSeparator />
|
|
1556
|
+
<UiDropdownMenuRadioGroup v-model="position">
|
|
1557
|
+
<UiDropdownMenuRadioItem value="top">Top</UiDropdownMenuRadioItem>
|
|
1558
|
+
<UiDropdownMenuRadioItem value="bottom">Bottom</UiDropdownMenuRadioItem>
|
|
1559
|
+
</UiDropdownMenuRadioGroup>
|
|
1560
|
+
<UiDropdownMenuSeparator />
|
|
1561
|
+
<UiDropdownMenuSub>
|
|
1562
|
+
<UiDropdownMenuSubTrigger>Invite users</UiDropdownMenuSubTrigger>
|
|
1563
|
+
<UiDropdownMenuSubContent>
|
|
1564
|
+
<UiDropdownMenuItem>Email</UiDropdownMenuItem>
|
|
1565
|
+
<UiDropdownMenuItem>Message</UiDropdownMenuItem>
|
|
1566
|
+
</UiDropdownMenuSubContent>
|
|
1567
|
+
</UiDropdownMenuSub>
|
|
1568
|
+
</UiDropdownMenuContent>
|
|
1569
|
+
</UiDropdownMenu>
|
|
1570
|
+
</div>`,
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* Opening the menu from its trigger, choosing an item, and the guard on a
|
|
1576
|
+
* disabled one. Hidden test-only story.
|
|
1577
|
+
*/
|
|
1578
|
+
export const PointerInteraction: Story = {
|
|
1579
|
+
name: 'test - Pointer interaction',
|
|
1580
|
+
tags: ['!dev', '!autodocs'],
|
|
1581
|
+
parameters: {
|
|
1582
|
+
chromatic: { disableSnapshot: true },
|
|
1583
|
+
docs: {
|
|
1584
|
+
description: {
|
|
1585
|
+
story: 'Click the trigger to open the menu, then choose an item.',
|
|
1586
|
+
},
|
|
1587
|
+
},
|
|
1588
|
+
},
|
|
1589
|
+
render: renderTestMenu,
|
|
1590
|
+
play: async ({ canvasElement, step }) => {
|
|
1591
|
+
// Scenario (UiDropdownMenu): a pointer user opens the menu, sees that the
|
|
1592
|
+
// disabled item cannot be used, picks "Profile", and the menu closes behind
|
|
1593
|
+
// the choice.
|
|
1594
|
+
onSelect.mockClear();
|
|
1595
|
+
const canvas = within(canvasElement);
|
|
1596
|
+
const body = within(document.body);
|
|
1597
|
+
const trigger = canvas.getByRole('button', { name: 'Open Menu' });
|
|
1598
|
+
|
|
1599
|
+
await step('interaction: the trigger opens the menu', async () => {
|
|
1600
|
+
await userEvent.click(trigger);
|
|
1601
|
+
await expectOpenMenu(body);
|
|
1602
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
await step('interaction: a disabled item stays inert', async () => {
|
|
1606
|
+
const billing = body.getByRole('menuitem', { name: 'Billing' });
|
|
1607
|
+
await expect(billing).toHaveAttribute('aria-disabled', 'true');
|
|
1608
|
+
await expect(getComputedStyle(billing).pointerEvents).toBe('none');
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1611
|
+
await step('interaction: choosing an item closes the menu', async () => {
|
|
1612
|
+
await userEvent.click(body.getByRole('menuitem', { name: 'Profile' }));
|
|
1613
|
+
await expect(onSelect).toHaveBeenCalledTimes(1);
|
|
1614
|
+
await waitFor(async () => {
|
|
1615
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
1616
|
+
});
|
|
1617
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
1618
|
+
});
|
|
1619
|
+
},
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* Reaching the menu, its items, and its submenu without a pointer. Hidden
|
|
1624
|
+
* test-only story.
|
|
1625
|
+
*/
|
|
1626
|
+
export const KeyboardNavigation: Story = {
|
|
1627
|
+
name: 'test - Keyboard navigation',
|
|
1628
|
+
tags: ['!dev', '!autodocs'],
|
|
1629
|
+
parameters: {
|
|
1630
|
+
chromatic: { disableSnapshot: true },
|
|
1631
|
+
docs: {
|
|
1632
|
+
description: {
|
|
1633
|
+
story:
|
|
1634
|
+
'Press `Tab` to focus the trigger, `Enter` to open, arrow keys to move, and `Escape` to dismiss.',
|
|
1635
|
+
},
|
|
1636
|
+
},
|
|
1637
|
+
},
|
|
1638
|
+
render: renderTestMenu,
|
|
1639
|
+
play: async ({ canvasElement, step }) => {
|
|
1640
|
+
// Scenario (UiDropdownMenu): a keyboard user tabs to the trigger, opens the
|
|
1641
|
+
// menu with Enter, walks the items past the disabled one, opens the submenu
|
|
1642
|
+
// with ArrowRight, dismisses everything with Escape, and finally activates
|
|
1643
|
+
// an item with Enter.
|
|
1644
|
+
onSelect.mockClear();
|
|
1645
|
+
const canvas = within(canvasElement);
|
|
1646
|
+
const body = within(document.body);
|
|
1647
|
+
const trigger = canvas.getByRole('button', { name: 'Open Menu' });
|
|
1648
|
+
|
|
1649
|
+
await step(
|
|
1650
|
+
'keyboard: the trigger is reachable via Tab (WCAG 2.1.1)',
|
|
1651
|
+
async () => {
|
|
1652
|
+
await userEvent.tab();
|
|
1653
|
+
await expect(trigger).toHaveFocus();
|
|
1654
|
+
},
|
|
1655
|
+
);
|
|
1656
|
+
|
|
1657
|
+
await step('keyboard: Enter opens the menu', async () => {
|
|
1658
|
+
await userEvent.keyboard('{Enter}');
|
|
1659
|
+
await expectOpenMenu(body);
|
|
1660
|
+
});
|
|
1661
|
+
|
|
1662
|
+
await step(
|
|
1663
|
+
'keyboard: arrow keys move through the items, and End jumps to the last one (WCAG 2.4.3)',
|
|
1664
|
+
async () => {
|
|
1665
|
+
await waitFor(async () => {
|
|
1666
|
+
await expect(
|
|
1667
|
+
body.getByRole('menuitem', { name: 'Profile' }),
|
|
1668
|
+
).toHaveFocus();
|
|
1669
|
+
});
|
|
1670
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
1671
|
+
await expect(
|
|
1672
|
+
body.getByRole('menuitem', { name: 'Settings' }),
|
|
1673
|
+
).toHaveFocus();
|
|
1674
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
1675
|
+
await expect(
|
|
1676
|
+
body.getByRole('menuitemcheckbox', { name: 'Notifications' }),
|
|
1677
|
+
).toHaveFocus();
|
|
1678
|
+
},
|
|
1679
|
+
);
|
|
1680
|
+
|
|
1681
|
+
await step('keyboard: ArrowRight opens the submenu', async () => {
|
|
1682
|
+
await userEvent.keyboard('{End}');
|
|
1683
|
+
const invite = body.getByRole('menuitem', { name: 'Invite users' });
|
|
1684
|
+
await expect(invite).toHaveFocus();
|
|
1685
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1686
|
+
await waitFor(async () => {
|
|
1687
|
+
await expect(
|
|
1688
|
+
body.getByRole('menuitem', { name: 'Email' }),
|
|
1689
|
+
).toBeVisible();
|
|
1690
|
+
});
|
|
1691
|
+
});
|
|
1692
|
+
|
|
1693
|
+
await step(
|
|
1694
|
+
'keyboard: Escape closes the menu and restores focus to the trigger (WCAG 2.1.2)',
|
|
1695
|
+
async () => {
|
|
1696
|
+
await userEvent.keyboard('{Escape}');
|
|
1697
|
+
await userEvent.keyboard('{Escape}');
|
|
1698
|
+
await waitFor(async () => {
|
|
1699
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
1700
|
+
});
|
|
1701
|
+
// Reka hands focus back on the next tick, after the closing animation
|
|
1702
|
+
// has been kicked off.
|
|
1703
|
+
await waitFor(async () => {
|
|
1704
|
+
await expect(trigger).toHaveFocus();
|
|
1705
|
+
});
|
|
1706
|
+
},
|
|
1707
|
+
);
|
|
1708
|
+
|
|
1709
|
+
await step('interaction: Enter runs the focused item', async () => {
|
|
1710
|
+
await userEvent.keyboard('{Enter}');
|
|
1711
|
+
await expectOpenMenu(body);
|
|
1712
|
+
await waitFor(async () => {
|
|
1713
|
+
await expect(
|
|
1714
|
+
body.getByRole('menuitem', { name: 'Profile' }),
|
|
1715
|
+
).toHaveFocus();
|
|
1716
|
+
});
|
|
1717
|
+
await userEvent.keyboard('{Enter}');
|
|
1718
|
+
await expect(onSelect).toHaveBeenCalledTimes(1);
|
|
1719
|
+
});
|
|
1720
|
+
},
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* What assistive technology reports for the trigger and each item type. Hidden
|
|
1725
|
+
* test-only story.
|
|
1726
|
+
*/
|
|
1727
|
+
export const ScreenReader: Story = {
|
|
1728
|
+
name: 'test - Screen reader',
|
|
1729
|
+
tags: ['!dev', '!autodocs'],
|
|
1730
|
+
parameters: {
|
|
1731
|
+
chromatic: { disableSnapshot: true },
|
|
1732
|
+
docs: {
|
|
1733
|
+
description: {
|
|
1734
|
+
story:
|
|
1735
|
+
'Every item type carries its role, name, and state for assistive technology.',
|
|
1736
|
+
},
|
|
1737
|
+
},
|
|
1738
|
+
},
|
|
1739
|
+
render: renderTestMenu,
|
|
1740
|
+
play: async ({ canvasElement, step }) => {
|
|
1741
|
+
// Scenario (UiDropdownMenu): a screen-reader user hears what the trigger
|
|
1742
|
+
// opens, then hears each item as its own kind of control, with the checked
|
|
1743
|
+
// and selected states spoken rather than shown.
|
|
1744
|
+
const canvas = within(canvasElement);
|
|
1745
|
+
const body = within(document.body);
|
|
1746
|
+
const trigger = canvas.getByRole('button', { name: 'Open Menu' });
|
|
1747
|
+
|
|
1748
|
+
await step(
|
|
1749
|
+
'screen-reader: the trigger announces that it opens a menu (WCAG 4.1.2)',
|
|
1750
|
+
async () => {
|
|
1751
|
+
await expect(trigger).toHaveAttribute('aria-haspopup', 'menu');
|
|
1752
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
1753
|
+
await userEvent.click(trigger);
|
|
1754
|
+
const menu = await expectOpenMenu(body);
|
|
1755
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
1756
|
+
await expect(menu).toHaveAttribute('aria-labelledby', trigger.id);
|
|
1757
|
+
},
|
|
1758
|
+
);
|
|
1759
|
+
|
|
1760
|
+
await step(
|
|
1761
|
+
'screen-reader: items carry their visible label, and the disabled one says so',
|
|
1762
|
+
async () => {
|
|
1763
|
+
await expect(
|
|
1764
|
+
body.getByRole('menuitem', { name: 'Settings' }),
|
|
1765
|
+
).toBeVisible();
|
|
1766
|
+
await expect(
|
|
1767
|
+
body.getByRole('menuitem', { name: 'Billing' }),
|
|
1768
|
+
).toHaveAttribute('aria-disabled', 'true');
|
|
1769
|
+
},
|
|
1770
|
+
);
|
|
1771
|
+
|
|
1772
|
+
await step(
|
|
1773
|
+
'screen-reader: the checkbox and radio items report their state (WCAG 4.1.2)',
|
|
1774
|
+
async () => {
|
|
1775
|
+
await expect(
|
|
1776
|
+
body.getByRole('menuitemcheckbox', { name: 'Notifications' }),
|
|
1777
|
+
).toHaveAttribute('aria-checked', 'true');
|
|
1778
|
+
await expect(
|
|
1779
|
+
body.getByRole('menuitemradio', { name: 'Top' }),
|
|
1780
|
+
).toHaveAttribute('aria-checked', 'true');
|
|
1781
|
+
await expect(
|
|
1782
|
+
body.getByRole('menuitemradio', { name: 'Bottom' }),
|
|
1783
|
+
).toHaveAttribute('aria-checked', 'false');
|
|
1784
|
+
},
|
|
1785
|
+
);
|
|
1786
|
+
|
|
1787
|
+
await step(
|
|
1788
|
+
'screen-reader: the submenu trigger announces a collapsed second level',
|
|
1789
|
+
async () => {
|
|
1790
|
+
const invite = body.getByRole('menuitem', { name: 'Invite users' });
|
|
1791
|
+
await expect(invite).toHaveAttribute('aria-haspopup', 'menu');
|
|
1792
|
+
await expect(invite).toHaveAttribute('aria-expanded', 'false');
|
|
1793
|
+
},
|
|
1794
|
+
);
|
|
1795
|
+
},
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1800
|
+
* try 400% reflow (WCAG 1.4.10); the menu must stay readable and operable.
|
|
1801
|
+
* Hidden test-only story.
|
|
1802
|
+
*/
|
|
1803
|
+
export const ZoomMagnification: Story = {
|
|
1804
|
+
name: 'test - Zoom magnification',
|
|
1805
|
+
tags: ['!dev', '!autodocs'],
|
|
1806
|
+
globals: { zoom: '200' },
|
|
1807
|
+
parameters: {
|
|
1808
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
1809
|
+
// already covers magnified snapshots, so skip this one.
|
|
1810
|
+
chromatic: { disableSnapshot: true },
|
|
1811
|
+
docs: {
|
|
1812
|
+
description: {
|
|
1813
|
+
story:
|
|
1814
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1815
|
+
},
|
|
1816
|
+
},
|
|
1817
|
+
},
|
|
1818
|
+
render: renderTestMenu,
|
|
1819
|
+
play: async ({ canvasElement, step }) => {
|
|
1820
|
+
// Scenario (UiDropdownMenu): at 200% page zoom the trigger keeps its name
|
|
1821
|
+
// and the menu still opens with readable items.
|
|
1822
|
+
const canvas = within(canvasElement);
|
|
1823
|
+
const body = within(document.body);
|
|
1824
|
+
const trigger = canvas.getByRole('button', { name: 'Open Menu' });
|
|
1825
|
+
|
|
1826
|
+
await step(
|
|
1827
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1828
|
+
async () => {
|
|
1829
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1830
|
+
},
|
|
1831
|
+
);
|
|
1832
|
+
|
|
1833
|
+
await step('zoom: the trigger keeps its accessible name', async () => {
|
|
1834
|
+
await expect(trigger).toBeVisible();
|
|
1835
|
+
await expect(trigger).toHaveAccessibleName('Open Menu');
|
|
1836
|
+
});
|
|
1837
|
+
|
|
1838
|
+
await step('zoom: the menu opens and stays readable', async () => {
|
|
1839
|
+
await userEvent.click(trigger);
|
|
1840
|
+
await expectOpenMenu(body);
|
|
1841
|
+
await expect(
|
|
1842
|
+
body.getByRole('menuitem', { name: 'Settings' }),
|
|
1843
|
+
).toBeVisible();
|
|
1844
|
+
});
|
|
1845
|
+
},
|
|
1846
|
+
};
|
|
1847
|
+
|
|
1848
|
+
/**
|
|
1849
|
+
* Rendered at the 320px mobile reflow breakpoint. The trigger meets the minimum
|
|
1850
|
+
* touch-target size and the menu stays operable. Hidden test-only story.
|
|
1851
|
+
*/
|
|
1852
|
+
export const MobileBreakpoint: Story = {
|
|
1853
|
+
name: 'test - Mobile breakpoint',
|
|
1854
|
+
tags: ['!dev', '!autodocs'],
|
|
1855
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1856
|
+
parameters: {
|
|
1857
|
+
// Reflow snapshots are already covered by the accessible-reflow Chromatic
|
|
1858
|
+
// mode, and the play opens the menu, so skip this snapshot.
|
|
1859
|
+
chromatic: { disableSnapshot: true },
|
|
1860
|
+
docs: {
|
|
1861
|
+
description: {
|
|
1862
|
+
story:
|
|
1863
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1864
|
+
},
|
|
1865
|
+
},
|
|
1866
|
+
},
|
|
1867
|
+
render: renderTestMenu,
|
|
1868
|
+
play: async ({ canvasElement, step }) => {
|
|
1869
|
+
// Scenario (UiDropdownMenu): at the 320px mobile breakpoint the trigger is
|
|
1870
|
+
// a large enough touch target and the menu opens within the viewport.
|
|
1871
|
+
const canvas = within(canvasElement);
|
|
1872
|
+
const body = within(document.body);
|
|
1873
|
+
const trigger = canvas.getByRole('button', { name: 'Open Menu' });
|
|
1874
|
+
|
|
1875
|
+
await step(
|
|
1876
|
+
'mobile: the trigger meets the minimum touch-target size (WCAG 2.5.8)',
|
|
1877
|
+
async () => {
|
|
1878
|
+
// The phone frame draws the story through `transform: scale()`, which
|
|
1879
|
+
// shrinks the measured rect but not the CSS size the finger actually
|
|
1880
|
+
// gets, so read the computed box instead.
|
|
1881
|
+
const { width, height } = getComputedStyle(trigger);
|
|
1882
|
+
await expect(Number.parseFloat(width)).toBeGreaterThanOrEqual(24);
|
|
1883
|
+
await expect(Number.parseFloat(height)).toBeGreaterThanOrEqual(24);
|
|
1884
|
+
},
|
|
1885
|
+
);
|
|
1886
|
+
|
|
1887
|
+
await step(
|
|
1888
|
+
'mobile: the menu opens and its items stay operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
|
|
1889
|
+
async () => {
|
|
1890
|
+
await userEvent.click(trigger);
|
|
1891
|
+
await expectOpenMenu(body);
|
|
1892
|
+
await userEvent.click(body.getByRole('menuitem', { name: 'Settings' }));
|
|
1893
|
+
await waitFor(async () => {
|
|
1894
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
1895
|
+
});
|
|
1896
|
+
},
|
|
1897
|
+
);
|
|
1898
|
+
},
|
|
1899
|
+
};
|