@aleph-alpha/ui-library 5.7.0 → 5.9.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 +12 -7
- package/config.d.ts +5 -1
- package/config.js +18 -1
- 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/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
- package/dist/system/components/UiBreadcrumb/types.d.ts +22 -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/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/UiToggleGroup/types.d.ts +0 -5
- package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
- package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
- package/dist/system/components/core/listbox/context.d.ts +21 -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/index.d.ts +2 -0
- package/dist/system/lib.js +22570 -21061
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
- 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 +10 -1
- package/package.json +3 -2
- 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/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
- package/src/components/UiBreadcrumb/index.ts +8 -0
- package/src/components/UiBreadcrumb/types.ts +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -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/UiListbox/UiListbox.stories.ts +1404 -30
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
- 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/UiSwitch/UiSwitch.stories.ts +706 -9
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
- package/src/components/UiToggle/UiToggle.stories.ts +961 -130
- package/src/components/UiToggle/UiToggle.vue +8 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
- package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
- package/src/components/UiToggleGroup/types.ts +0 -5
- package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
- package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
- package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
- package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
- package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/src/components/core/breadcrumb/index.ts +7 -0
- 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/listbox/Listbox.vue +14 -2
- package/src/components/core/listbox/ListboxContent.vue +61 -3
- package/src/components/core/listbox/ListboxItem.vue +6 -1
- package/src/components/core/listbox/context.ts +34 -0
- package/src/components/core/toggle/Toggle.vue +15 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
- package/src/components/core/toggle-group/index.ts +5 -2
- package/src/components/index.ts +2 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -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
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
3
|
+
import { ref, watch } from 'vue';
|
|
4
|
+
import {
|
|
5
|
+
UiDropdownMenu,
|
|
6
|
+
UiDropdownMenuTrigger,
|
|
7
|
+
UiDropdownMenuContent,
|
|
8
|
+
UiDropdownMenuItem,
|
|
9
|
+
UiDropdownMenuLabel,
|
|
10
|
+
UiDropdownMenuSeparator,
|
|
11
|
+
UiDropdownMenuRadioGroup,
|
|
12
|
+
UiDropdownMenuRadioItem,
|
|
13
|
+
UiDropdownMenuSub,
|
|
14
|
+
UiDropdownMenuSubTrigger,
|
|
15
|
+
UiDropdownMenuSubContent,
|
|
16
|
+
} from '../../components/UiDropdownMenu';
|
|
17
|
+
import { UiAvatar, UiAvatarFallback } from '../../components/UiAvatar';
|
|
18
|
+
import { UiIcon } from '../../components/UiIcon';
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* The profile card ships no component of its own — it is a composition of
|
|
22
|
+
* `UiDropdownMenu` parts, so every card below is assembled in story land
|
|
23
|
+
* exactly as a product would assemble it.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Every part the cards are built from. */
|
|
27
|
+
const PROFILE_CARD_COMPONENTS = {
|
|
28
|
+
UiDropdownMenu,
|
|
29
|
+
UiDropdownMenuTrigger,
|
|
30
|
+
UiDropdownMenuContent,
|
|
31
|
+
UiDropdownMenuItem,
|
|
32
|
+
UiDropdownMenuLabel,
|
|
33
|
+
UiDropdownMenuSeparator,
|
|
34
|
+
UiDropdownMenuRadioGroup,
|
|
35
|
+
UiDropdownMenuRadioItem,
|
|
36
|
+
UiDropdownMenuSub,
|
|
37
|
+
UiDropdownMenuSubTrigger,
|
|
38
|
+
UiDropdownMenuSubContent,
|
|
39
|
+
UiAvatar,
|
|
40
|
+
UiAvatarFallback,
|
|
41
|
+
UiIcon,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Stacks menu items 4px apart. Flex gap and margin add up, so the 4px the
|
|
46
|
+
* separator already carries lands each divider at 8px of clear space.
|
|
47
|
+
*/
|
|
48
|
+
const STACK = 'flex flex-col gap-1';
|
|
49
|
+
|
|
50
|
+
/** The card surface: 320px wide, a 12px radius and 8px of padding. */
|
|
51
|
+
const CARD = `w-80 ${STACK} rounded-xl p-2`;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The avatar the card hangs from. A real button, so it is focusable and named
|
|
55
|
+
* for assistive technology — the same control `UiTopBar` puts in its `profile`
|
|
56
|
+
* slot. `WithAvatarTrigger` is the story that shows it.
|
|
57
|
+
*/
|
|
58
|
+
const AVATAR_TRIGGER = `
|
|
59
|
+
<UiDropdownMenuTrigger as-child>
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
aria-label="Open profile menu"
|
|
63
|
+
class="ui-focus-ring shrink-0 cursor-pointer rounded-full"
|
|
64
|
+
>
|
|
65
|
+
<UiAvatar :size="10">
|
|
66
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
67
|
+
</UiAvatar>
|
|
68
|
+
</button>
|
|
69
|
+
</UiDropdownMenuTrigger>
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The trigger for the stories that document the card itself. A menu is
|
|
74
|
+
* positioned against its trigger, so one has to exist; `sr-only` shrinks it out
|
|
75
|
+
* of the picture while keeping the card reachable by keyboard.
|
|
76
|
+
*/
|
|
77
|
+
const HIDDEN_TRIGGER = `
|
|
78
|
+
<UiDropdownMenuTrigger as-child>
|
|
79
|
+
<button type="button" class="sr-only">Open profile menu</button>
|
|
80
|
+
</UiDropdownMenuTrigger>
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The identity block at the top of every card: a label rather than an item, so
|
|
85
|
+
* it is announced as a group name and cannot be activated.
|
|
86
|
+
*/
|
|
87
|
+
const HEADER = `
|
|
88
|
+
<UiDropdownMenuLabel class="flex items-center gap-3 py-2">
|
|
89
|
+
<UiAvatar :size="10">
|
|
90
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
91
|
+
</UiAvatar>
|
|
92
|
+
<span class="flex min-w-0 flex-col">
|
|
93
|
+
<span class="truncate label-14-medium text-content-on-surface-primary">Christina Neumann</span>
|
|
94
|
+
<span class="truncate label-12-regular text-content-on-surface-muted">christina.neumann@example.com</span>
|
|
95
|
+
</span>
|
|
96
|
+
</UiDropdownMenuLabel>
|
|
97
|
+
<UiDropdownMenuSeparator />
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
/** The closing action, split off by a separator on every card. */
|
|
101
|
+
const SIGN_OUT = `
|
|
102
|
+
<UiDropdownMenuSeparator />
|
|
103
|
+
<UiDropdownMenuItem>
|
|
104
|
+
<UiIcon name="log-out" size="s" />
|
|
105
|
+
Sign out
|
|
106
|
+
</UiDropdownMenuItem>
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
/** The three navigational items, with the leading icons of the icon variants. */
|
|
110
|
+
const ICON_LINKS = `
|
|
111
|
+
<UiDropdownMenuItem>
|
|
112
|
+
<UiIcon name="settings" size="s" />
|
|
113
|
+
Your account settings
|
|
114
|
+
</UiDropdownMenuItem>
|
|
115
|
+
<UiDropdownMenuItem>
|
|
116
|
+
<UiIcon name="eye" size="s" />
|
|
117
|
+
Privacy policy
|
|
118
|
+
</UiDropdownMenuItem>
|
|
119
|
+
<UiDropdownMenuItem>
|
|
120
|
+
<UiIcon name="file-text" size="s" />
|
|
121
|
+
Terms and conditions
|
|
122
|
+
</UiDropdownMenuItem>
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The organization link, which leaves the app — hence the trailing
|
|
127
|
+
* `external-link` icon next to its label.
|
|
128
|
+
*/
|
|
129
|
+
const ORGANIZATION_LINK = `
|
|
130
|
+
<UiDropdownMenuItem>
|
|
131
|
+
<UiIcon name="lock" size="s" />
|
|
132
|
+
Your organization settings
|
|
133
|
+
<UiIcon name="external-link" size="s" class="ml-auto" />
|
|
134
|
+
</UiDropdownMenuItem>
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The `Languages` submenu, closed until it is hovered or arrowed into. The
|
|
139
|
+
* options are radio items — one language at a time — with the indicator moved
|
|
140
|
+
* to the trailing edge as a check mark.
|
|
141
|
+
*/
|
|
142
|
+
function languagesSubmenu() {
|
|
143
|
+
return `
|
|
144
|
+
<UiDropdownMenuSub>
|
|
145
|
+
<UiDropdownMenuSubTrigger>
|
|
146
|
+
<UiIcon name="languages" size="s" class="mr-2" />
|
|
147
|
+
Languages
|
|
148
|
+
</UiDropdownMenuSubTrigger>
|
|
149
|
+
<UiDropdownMenuSubContent class="w-40 ${STACK}">
|
|
150
|
+
<UiDropdownMenuRadioGroup v-model="language" class="${STACK}">
|
|
151
|
+
<UiDropdownMenuRadioItem value="en" class="pl-2">
|
|
152
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
153
|
+
English
|
|
154
|
+
<UiIcon v-if="language === 'en'" name="check" size="s" class="ml-auto" />
|
|
155
|
+
</UiDropdownMenuRadioItem>
|
|
156
|
+
<UiDropdownMenuRadioItem value="de" class="pl-2">
|
|
157
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
158
|
+
German
|
|
159
|
+
<UiIcon v-if="language === 'de'" name="check" size="s" class="ml-auto" />
|
|
160
|
+
</UiDropdownMenuRadioItem>
|
|
161
|
+
</UiDropdownMenuRadioGroup>
|
|
162
|
+
</UiDropdownMenuSubContent>
|
|
163
|
+
</UiDropdownMenuSub>
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Wraps a card so the story reserves the height the open menu needs. The menu
|
|
169
|
+
* itself is portalled to the body, so without this the docs block would
|
|
170
|
+
* collapse to the height of the avatar. The trigger sits at the start of the
|
|
171
|
+
* stage to leave room for submenus, which otherwise flip to the other side.
|
|
172
|
+
* @param card Markup for the card, trigger included.
|
|
173
|
+
*/
|
|
174
|
+
const stage = (card: string) =>
|
|
175
|
+
`<div class="flex min-h-100 items-start p-6">${card}</div>`;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Bound to the outside-interaction events of the cards that stay open. The docs
|
|
179
|
+
* page mounts every story at once, and a menu taking focus reads as an outside
|
|
180
|
+
* interaction to the menus already open, which then dismiss themselves — so
|
|
181
|
+
* without this only the last card would survive.
|
|
182
|
+
*/
|
|
183
|
+
const stayOpen = {
|
|
184
|
+
onFocusOutside: (event: Event) => event.preventDefault(),
|
|
185
|
+
onPointerDownOutside: (event: Event) => event.preventDefault(),
|
|
186
|
+
onInteractOutside: (event: Event) => event.preventDefault(),
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Keeps the open state in sync with the `open` control while still letting the
|
|
191
|
+
* avatar toggle the card.
|
|
192
|
+
* @param args Story args.
|
|
193
|
+
* @param args.open Current value of the `open` control.
|
|
194
|
+
*/
|
|
195
|
+
function useOpenState(args: { open: boolean }) {
|
|
196
|
+
const open = ref(args.open);
|
|
197
|
+
watch(
|
|
198
|
+
() => args.open,
|
|
199
|
+
(value) => {
|
|
200
|
+
open.value = value;
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
return { open, stayOpen };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Displays a profile menu when user clicks on their avatar.
|
|
208
|
+
*/
|
|
209
|
+
const meta = {
|
|
210
|
+
title: 'Patterns/UiProfileCard',
|
|
211
|
+
tags: ['autodocs', 'experimental'],
|
|
212
|
+
argTypes: {
|
|
213
|
+
open: {
|
|
214
|
+
control: 'boolean',
|
|
215
|
+
description: 'Whether the card is open',
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
args: {
|
|
219
|
+
open: true,
|
|
220
|
+
},
|
|
221
|
+
} satisfies Meta<{ open: boolean }>;
|
|
222
|
+
|
|
223
|
+
export default meta;
|
|
224
|
+
type Story = StoryObj<typeof meta>;
|
|
225
|
+
|
|
226
|
+
const defaultTemplateSource = `<!-- the trigger this card hangs off is in WithAvatarTrigger -->
|
|
227
|
+
<UiDropdownMenuContent class="${CARD}" align="start">
|
|
228
|
+
<UiDropdownMenuLabel class="flex items-center gap-3 py-2">
|
|
229
|
+
<UiAvatar :size="10">
|
|
230
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
231
|
+
</UiAvatar>
|
|
232
|
+
<span class="flex min-w-0 flex-col">
|
|
233
|
+
<span class="truncate label-14-medium">Christina Neumann</span>
|
|
234
|
+
<span class="truncate label-12-regular text-content-on-surface-muted">christina.neumann@example.com</span>
|
|
235
|
+
</span>
|
|
236
|
+
</UiDropdownMenuLabel>
|
|
237
|
+
<UiDropdownMenuSeparator />
|
|
238
|
+
|
|
239
|
+
<UiDropdownMenuItem>Account settings</UiDropdownMenuItem>
|
|
240
|
+
<UiDropdownMenuItem>Privacy policy</UiDropdownMenuItem>
|
|
241
|
+
<UiDropdownMenuItem>Terms and conditions</UiDropdownMenuItem>
|
|
242
|
+
|
|
243
|
+
<UiDropdownMenuSeparator />
|
|
244
|
+
<UiDropdownMenuItem>
|
|
245
|
+
<UiIcon name="log-out" size="s" />
|
|
246
|
+
Sign out
|
|
247
|
+
</UiDropdownMenuItem>
|
|
248
|
+
</UiDropdownMenuContent>`;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The card with plain text links.
|
|
252
|
+
*/
|
|
253
|
+
export const Default: Story = {
|
|
254
|
+
render: (args) => ({
|
|
255
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
256
|
+
setup() {
|
|
257
|
+
return useOpenState(args);
|
|
258
|
+
},
|
|
259
|
+
template: stage(`
|
|
260
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
261
|
+
${HIDDEN_TRIGGER}
|
|
262
|
+
<UiDropdownMenuContent
|
|
263
|
+
v-bind="stayOpen"
|
|
264
|
+
class="${CARD}"
|
|
265
|
+
align="start"
|
|
266
|
+
:avoid-collisions="false"
|
|
267
|
+
>
|
|
268
|
+
${HEADER}
|
|
269
|
+
<UiDropdownMenuItem>Account settings</UiDropdownMenuItem>
|
|
270
|
+
<UiDropdownMenuItem>Privacy policy</UiDropdownMenuItem>
|
|
271
|
+
<UiDropdownMenuItem>Terms and conditions</UiDropdownMenuItem>
|
|
272
|
+
${SIGN_OUT}
|
|
273
|
+
</UiDropdownMenuContent>
|
|
274
|
+
</UiDropdownMenu>
|
|
275
|
+
`),
|
|
276
|
+
}),
|
|
277
|
+
parameters: {
|
|
278
|
+
docs: { source: { code: defaultTemplateSource } },
|
|
279
|
+
},
|
|
280
|
+
play: async ({ step }) => {
|
|
281
|
+
// Scenario (UiProfileCard): a screen-reader user opens the profile card and
|
|
282
|
+
// finds a menu whose items carry their visible labels, with the identity
|
|
283
|
+
// block announced as a name rather than as another choice. Non-mutating
|
|
284
|
+
// assertions only, so the Chromatic snapshot for this story stays valid.
|
|
285
|
+
const body = within(document.body);
|
|
286
|
+
|
|
287
|
+
await step(
|
|
288
|
+
'screen-reader: the card is exposed as a menu (WCAG 4.1.2)',
|
|
289
|
+
async () => {
|
|
290
|
+
await expect(await body.findByRole('menu')).toBeVisible();
|
|
291
|
+
},
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
await step(
|
|
295
|
+
'screen-reader: every link is a named menu item (WCAG 4.1.2)',
|
|
296
|
+
async () => {
|
|
297
|
+
await expect(
|
|
298
|
+
body.getByRole('menuitem', { name: 'Account settings' }),
|
|
299
|
+
).toBeVisible();
|
|
300
|
+
await expect(
|
|
301
|
+
body.getByRole('menuitem', { name: 'Privacy policy' }),
|
|
302
|
+
).toBeVisible();
|
|
303
|
+
await expect(
|
|
304
|
+
body.getByRole('menuitem', { name: 'Terms and conditions' }),
|
|
305
|
+
).toBeVisible();
|
|
306
|
+
await expect(
|
|
307
|
+
body.getByRole('menuitem', { name: 'Sign out' }),
|
|
308
|
+
).toBeVisible();
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
await step(
|
|
313
|
+
'screen-reader: the identity block is a label, not a fifth choice',
|
|
314
|
+
async () => {
|
|
315
|
+
await waitFor(async () => {
|
|
316
|
+
await expect(
|
|
317
|
+
body.getByText('christina.neumann@example.com'),
|
|
318
|
+
).toBeVisible();
|
|
319
|
+
});
|
|
320
|
+
await expect(
|
|
321
|
+
body.queryByRole('menuitem', { name: /Christina Neumann/ }),
|
|
322
|
+
).toBeNull();
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const withItemIconsTemplateSource = `<UiDropdownMenuContent class="${CARD}" align="start">
|
|
329
|
+
<!-- identity header + separator, as in the Default story -->
|
|
330
|
+
|
|
331
|
+
<UiDropdownMenuItem>
|
|
332
|
+
<UiIcon name="lock" size="s" />
|
|
333
|
+
Your organization settings
|
|
334
|
+
</UiDropdownMenuItem>
|
|
335
|
+
<UiDropdownMenuItem>
|
|
336
|
+
<UiIcon name="settings" size="s" />
|
|
337
|
+
Your account settings
|
|
338
|
+
</UiDropdownMenuItem>
|
|
339
|
+
<UiDropdownMenuItem>
|
|
340
|
+
<UiIcon name="eye" size="s" />
|
|
341
|
+
Privacy policy
|
|
342
|
+
</UiDropdownMenuItem>
|
|
343
|
+
<UiDropdownMenuItem>
|
|
344
|
+
<UiIcon name="file-text" size="s" />
|
|
345
|
+
Terms and conditions
|
|
346
|
+
</UiDropdownMenuItem>
|
|
347
|
+
|
|
348
|
+
<UiDropdownMenuSeparator />
|
|
349
|
+
<UiDropdownMenuItem>
|
|
350
|
+
<UiIcon name="log-out" size="s" />
|
|
351
|
+
Sign out
|
|
352
|
+
</UiDropdownMenuItem>
|
|
353
|
+
</UiDropdownMenuContent>`;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The card with an icon on every item.
|
|
357
|
+
*/
|
|
358
|
+
export const WithItemIcons: Story = {
|
|
359
|
+
render: (args) => ({
|
|
360
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
361
|
+
setup() {
|
|
362
|
+
return useOpenState(args);
|
|
363
|
+
},
|
|
364
|
+
template: stage(`
|
|
365
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
366
|
+
${HIDDEN_TRIGGER}
|
|
367
|
+
<UiDropdownMenuContent
|
|
368
|
+
v-bind="stayOpen"
|
|
369
|
+
class="${CARD}"
|
|
370
|
+
align="start"
|
|
371
|
+
:avoid-collisions="false"
|
|
372
|
+
>
|
|
373
|
+
${HEADER}
|
|
374
|
+
<UiDropdownMenuItem>
|
|
375
|
+
<UiIcon name="lock" size="s" />
|
|
376
|
+
Your organization settings
|
|
377
|
+
</UiDropdownMenuItem>
|
|
378
|
+
${ICON_LINKS}
|
|
379
|
+
${SIGN_OUT}
|
|
380
|
+
</UiDropdownMenuContent>
|
|
381
|
+
</UiDropdownMenu>
|
|
382
|
+
`),
|
|
383
|
+
}),
|
|
384
|
+
parameters: {
|
|
385
|
+
docs: { source: { code: withItemIconsTemplateSource } },
|
|
386
|
+
},
|
|
387
|
+
play: async ({ step }) => {
|
|
388
|
+
// Scenario (UiProfileCard): the leading icons are decoration, so each item
|
|
389
|
+
// is still announced by its visible label alone.
|
|
390
|
+
const body = within(document.body);
|
|
391
|
+
|
|
392
|
+
await step(
|
|
393
|
+
'screen-reader: decorative icons stay out of the accessible name (WCAG 1.1.1)',
|
|
394
|
+
async () => {
|
|
395
|
+
await expect(
|
|
396
|
+
await body.findByRole('menuitem', {
|
|
397
|
+
name: 'Your organization settings',
|
|
398
|
+
}),
|
|
399
|
+
).toBeVisible();
|
|
400
|
+
await expect(
|
|
401
|
+
body.getByRole('menuitem', { name: 'Your account settings' }),
|
|
402
|
+
).toBeVisible();
|
|
403
|
+
await expect(
|
|
404
|
+
body.getByRole('menuitem', { name: 'Sign out' }),
|
|
405
|
+
).toBeVisible();
|
|
406
|
+
},
|
|
407
|
+
);
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const withSubmenusTemplateSource = `<UiDropdownMenuContent class="${CARD}" align="start">
|
|
412
|
+
<!-- identity header + separator, as in the Default story -->
|
|
413
|
+
|
|
414
|
+
<UiDropdownMenuItem>
|
|
415
|
+
<UiIcon name="lock" size="s" />
|
|
416
|
+
Your organization settings
|
|
417
|
+
<UiIcon name="external-link" size="s" class="ml-auto" />
|
|
418
|
+
</UiDropdownMenuItem>
|
|
419
|
+
|
|
420
|
+
<UiDropdownMenuSub>
|
|
421
|
+
<UiDropdownMenuSubTrigger>
|
|
422
|
+
<UiIcon name="languages" size="s" class="mr-2" />
|
|
423
|
+
Languages
|
|
424
|
+
</UiDropdownMenuSubTrigger>
|
|
425
|
+
<UiDropdownMenuSubContent class="w-40 ${STACK}">
|
|
426
|
+
<UiDropdownMenuRadioGroup v-model="language" class="${STACK}">
|
|
427
|
+
<UiDropdownMenuRadioItem value="en" class="pl-2">
|
|
428
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
429
|
+
English
|
|
430
|
+
<UiIcon v-if="language === 'en'" name="check" size="s" class="ml-auto" />
|
|
431
|
+
</UiDropdownMenuRadioItem>
|
|
432
|
+
<UiDropdownMenuRadioItem value="de" class="pl-2">
|
|
433
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
434
|
+
German
|
|
435
|
+
<UiIcon v-if="language === 'de'" name="check" size="s" class="ml-auto" />
|
|
436
|
+
</UiDropdownMenuRadioItem>
|
|
437
|
+
</UiDropdownMenuRadioGroup>
|
|
438
|
+
</UiDropdownMenuSubContent>
|
|
439
|
+
</UiDropdownMenuSub>
|
|
440
|
+
|
|
441
|
+
<!-- Help and Learn more follow the same UiDropdownMenuSub shape -->
|
|
442
|
+
|
|
443
|
+
<UiDropdownMenuSeparator />
|
|
444
|
+
<UiDropdownMenuItem>
|
|
445
|
+
<UiIcon name="log-out" size="s" />
|
|
446
|
+
Sign out
|
|
447
|
+
</UiDropdownMenuItem>
|
|
448
|
+
</UiDropdownMenuContent>`;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The card with items that open a second level.
|
|
452
|
+
*/
|
|
453
|
+
export const WithSubmenus: Story = {
|
|
454
|
+
render: (args) => ({
|
|
455
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
456
|
+
setup() {
|
|
457
|
+
const language = ref('en');
|
|
458
|
+
return { ...useOpenState(args), language };
|
|
459
|
+
},
|
|
460
|
+
template: stage(`
|
|
461
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
462
|
+
${HIDDEN_TRIGGER}
|
|
463
|
+
<UiDropdownMenuContent
|
|
464
|
+
v-bind="stayOpen"
|
|
465
|
+
class="${CARD}"
|
|
466
|
+
align="start"
|
|
467
|
+
:avoid-collisions="false"
|
|
468
|
+
>
|
|
469
|
+
${HEADER}
|
|
470
|
+
${ORGANIZATION_LINK}
|
|
471
|
+
${languagesSubmenu()}
|
|
472
|
+
<UiDropdownMenuSub>
|
|
473
|
+
<UiDropdownMenuSubTrigger>
|
|
474
|
+
<UiIcon name="life-buoy" size="s" class="mr-2" />
|
|
475
|
+
Help
|
|
476
|
+
</UiDropdownMenuSubTrigger>
|
|
477
|
+
<UiDropdownMenuSubContent class="w-48 ${STACK}">
|
|
478
|
+
<UiDropdownMenuItem>Documentation</UiDropdownMenuItem>
|
|
479
|
+
<UiDropdownMenuItem>Contact support</UiDropdownMenuItem>
|
|
480
|
+
</UiDropdownMenuSubContent>
|
|
481
|
+
</UiDropdownMenuSub>
|
|
482
|
+
<UiDropdownMenuSub>
|
|
483
|
+
<UiDropdownMenuSubTrigger>
|
|
484
|
+
<UiIcon name="info" size="s" class="mr-2" />
|
|
485
|
+
Learn more
|
|
486
|
+
</UiDropdownMenuSubTrigger>
|
|
487
|
+
<UiDropdownMenuSubContent class="w-48 ${STACK}">
|
|
488
|
+
<UiDropdownMenuItem>What's new</UiDropdownMenuItem>
|
|
489
|
+
<UiDropdownMenuItem>Keyboard shortcuts</UiDropdownMenuItem>
|
|
490
|
+
</UiDropdownMenuSubContent>
|
|
491
|
+
</UiDropdownMenuSub>
|
|
492
|
+
${SIGN_OUT}
|
|
493
|
+
</UiDropdownMenuContent>
|
|
494
|
+
</UiDropdownMenu>
|
|
495
|
+
`),
|
|
496
|
+
}),
|
|
497
|
+
parameters: {
|
|
498
|
+
docs: { source: { code: withSubmenusTemplateSource } },
|
|
499
|
+
},
|
|
500
|
+
play: async ({ step }) => {
|
|
501
|
+
// Scenario (UiProfileCard): a screen-reader user can tell the three submenu
|
|
502
|
+
// triggers from the plain links, because each reports that it opens a menu
|
|
503
|
+
// and whether that menu is currently expanded.
|
|
504
|
+
const body = within(document.body);
|
|
505
|
+
|
|
506
|
+
await step(
|
|
507
|
+
'screen-reader: submenu triggers announce their popup and collapsed state (WCAG 4.1.2)',
|
|
508
|
+
async () => {
|
|
509
|
+
for (const name of ['Languages', 'Help', 'Learn more']) {
|
|
510
|
+
const trigger = await body.findByRole('menuitem', { name });
|
|
511
|
+
await expect(trigger).toHaveAttribute('aria-haspopup', 'menu');
|
|
512
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
await step(
|
|
518
|
+
'screen-reader: the external link stays a plain menu item',
|
|
519
|
+
async () => {
|
|
520
|
+
await expect(
|
|
521
|
+
body.getByRole('menuitem', { name: 'Your organization settings' }),
|
|
522
|
+
).not.toHaveAttribute('aria-haspopup');
|
|
523
|
+
},
|
|
524
|
+
);
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const languagePickerTemplateSource = `<UiDropdownMenuSub>
|
|
529
|
+
<UiDropdownMenuSubTrigger>
|
|
530
|
+
<UiIcon name="languages" size="s" class="mr-2" />
|
|
531
|
+
Languages
|
|
532
|
+
</UiDropdownMenuSubTrigger>
|
|
533
|
+
<UiDropdownMenuSubContent class="w-40 ${STACK}">
|
|
534
|
+
<UiDropdownMenuRadioGroup v-model="language" class="${STACK}">
|
|
535
|
+
<!-- An empty indicator drops the radio dot; the trailing check marks the choice -->
|
|
536
|
+
<UiDropdownMenuRadioItem value="en" class="pl-2">
|
|
537
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
538
|
+
English
|
|
539
|
+
<UiIcon v-if="language === 'en'" name="check" size="s" class="ml-auto" />
|
|
540
|
+
</UiDropdownMenuRadioItem>
|
|
541
|
+
<UiDropdownMenuRadioItem value="de" class="pl-2">
|
|
542
|
+
<template #indicator-icon><span class="hidden" /></template>
|
|
543
|
+
German
|
|
544
|
+
<UiIcon v-if="language === 'de'" name="check" size="s" class="ml-auto" />
|
|
545
|
+
</UiDropdownMenuRadioItem>
|
|
546
|
+
</UiDropdownMenuRadioGroup>
|
|
547
|
+
</UiDropdownMenuSubContent>
|
|
548
|
+
</UiDropdownMenuSub>`;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* The card with a submenu for picking one language.
|
|
552
|
+
*/
|
|
553
|
+
export const LanguagePicker: Story = {
|
|
554
|
+
render: (args) => ({
|
|
555
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
556
|
+
setup() {
|
|
557
|
+
const language = ref('en');
|
|
558
|
+
return { ...useOpenState(args), language };
|
|
559
|
+
},
|
|
560
|
+
template: stage(`
|
|
561
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
562
|
+
${HIDDEN_TRIGGER}
|
|
563
|
+
<UiDropdownMenuContent
|
|
564
|
+
v-bind="stayOpen"
|
|
565
|
+
class="${CARD}"
|
|
566
|
+
align="start"
|
|
567
|
+
:avoid-collisions="false"
|
|
568
|
+
>
|
|
569
|
+
${HEADER}
|
|
570
|
+
${ORGANIZATION_LINK}
|
|
571
|
+
${languagesSubmenu()}
|
|
572
|
+
${SIGN_OUT}
|
|
573
|
+
</UiDropdownMenuContent>
|
|
574
|
+
</UiDropdownMenu>
|
|
575
|
+
`),
|
|
576
|
+
}),
|
|
577
|
+
parameters: {
|
|
578
|
+
docs: { source: { code: languagePickerTemplateSource } },
|
|
579
|
+
},
|
|
580
|
+
play: async ({ step }) => {
|
|
581
|
+
// Scenario (UiProfileCard): assistive tech reads Languages as an item that
|
|
582
|
+
// leads to a second level, and hears that the level is still closed. The
|
|
583
|
+
// radio options themselves are driven in the keyboard test, which opens the
|
|
584
|
+
// submenu; here the assertions stay non-mutating so the Chromatic snapshot
|
|
585
|
+
// for this story stays valid.
|
|
586
|
+
const body = within(document.body);
|
|
587
|
+
|
|
588
|
+
await step(
|
|
589
|
+
'screen-reader: the collapsed submenu is announced on its trigger (WCAG 4.1.2)',
|
|
590
|
+
async () => {
|
|
591
|
+
const languages = await body.findByRole('menuitem', {
|
|
592
|
+
name: 'Languages',
|
|
593
|
+
});
|
|
594
|
+
await expect(languages).toHaveAttribute('aria-haspopup', 'menu');
|
|
595
|
+
await expect(languages).toHaveAttribute('aria-expanded', 'false');
|
|
596
|
+
},
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
await step('screen-reader: no second level is exposed yet', async () => {
|
|
600
|
+
await expect(
|
|
601
|
+
body.queryByRole('menuitemradio', { name: 'English' }),
|
|
602
|
+
).toBeNull();
|
|
603
|
+
});
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* A card for the accessibility story: open, anchored to a hidden trigger, and
|
|
609
|
+
* given the theme class on the content itself, since the card is portalled out
|
|
610
|
+
* of any wrapper further up the page.
|
|
611
|
+
* @param themeClass Extra classes for the card surface.
|
|
612
|
+
*/
|
|
613
|
+
const themedCard = (themeClass = '') => `
|
|
614
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
615
|
+
${HIDDEN_TRIGGER}
|
|
616
|
+
<UiDropdownMenuContent
|
|
617
|
+
v-bind="stayOpen"
|
|
618
|
+
class="${CARD} ${themeClass}"
|
|
619
|
+
align="start"
|
|
620
|
+
:avoid-collisions="false"
|
|
621
|
+
>
|
|
622
|
+
${HEADER}
|
|
623
|
+
<UiDropdownMenuItem>
|
|
624
|
+
<UiIcon name="settings" size="s" />
|
|
625
|
+
Your account settings
|
|
626
|
+
</UiDropdownMenuItem>
|
|
627
|
+
<UiDropdownMenuItem>
|
|
628
|
+
<UiIcon name="eye" size="s" />
|
|
629
|
+
Privacy policy
|
|
630
|
+
</UiDropdownMenuItem>
|
|
631
|
+
${SIGN_OUT}
|
|
632
|
+
</UiDropdownMenuContent>
|
|
633
|
+
</UiDropdownMenu>
|
|
634
|
+
`;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* How the card behaves for keyboard and screen-reader users.
|
|
638
|
+
*/
|
|
639
|
+
export const Accessibility: Story = {
|
|
640
|
+
tags: ['!autodocs'],
|
|
641
|
+
parameters: {
|
|
642
|
+
chromatic: { disableSnapshot: true },
|
|
643
|
+
docs: { canvas: { sourceState: 'none' } },
|
|
644
|
+
},
|
|
645
|
+
render: (args) => ({
|
|
646
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
647
|
+
setup() {
|
|
648
|
+
return useOpenState(args);
|
|
649
|
+
},
|
|
650
|
+
template: `
|
|
651
|
+
<section class="flex flex-col gap-6 p-4">
|
|
652
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
653
|
+
Accessibility
|
|
654
|
+
</h2>
|
|
655
|
+
|
|
656
|
+
<div class="flex flex-col gap-2">
|
|
657
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
658
|
+
Requirements
|
|
659
|
+
</h3>
|
|
660
|
+
<ul class="body-16-regular list-disc pl-5 text-content-on-surface-primary">
|
|
661
|
+
<li>The avatar is a button and needs a name of its own, since a picture of a person says nothing about what clicking it does.</li>
|
|
662
|
+
<li>The avatar tells assistive technology that it opens a menu, and whether that menu is currently open.</li>
|
|
663
|
+
<li>The card is announced as a menu and each row as one of its items, named by the text you can see.</li>
|
|
664
|
+
<li>The name and email at the top are a heading for the menu, not a choice — they cannot be focused or activated.</li>
|
|
665
|
+
<li>Enter or Space opens the card, the arrow keys walk it, and Escape closes it and puts focus back on the avatar.</li>
|
|
666
|
+
<li>Items that lead to a second level say so, and open with the right arrow key as well as on hover.</li>
|
|
667
|
+
<li>A list of options such as the languages is announced as a set of choices, with the current one marked as selected.</li>
|
|
668
|
+
<li>Icons are decoration: every item still reads the same with images off.</li>
|
|
669
|
+
<li>The avatar needs a touch target of at least 24px; the one below is 40px.</li>
|
|
670
|
+
</ul>
|
|
671
|
+
</div>
|
|
672
|
+
|
|
673
|
+
<div class="flex flex-col gap-2">
|
|
674
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
675
|
+
Enable accessibility theme
|
|
676
|
+
</h3>
|
|
677
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
678
|
+
When accessibility is required, enable our accessibility theme. This
|
|
679
|
+
increases contrast and ensures there are no color contrast issues.
|
|
680
|
+
</p>
|
|
681
|
+
</div>
|
|
682
|
+
|
|
683
|
+
<div class="flex flex-wrap gap-12">
|
|
684
|
+
<div class="flex w-80 flex-col gap-3">
|
|
685
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
686
|
+
Default
|
|
687
|
+
</h3>
|
|
688
|
+
<!--
|
|
689
|
+
A block, not a flex column: the card is anchored to the hidden
|
|
690
|
+
trigger, and a flex container would park that trigger in its top
|
|
691
|
+
corner, behind the heading.
|
|
692
|
+
-->
|
|
693
|
+
<div class="min-h-72">${themedCard()}</div>
|
|
694
|
+
</div>
|
|
695
|
+
|
|
696
|
+
<div class="flex w-80 flex-col gap-3">
|
|
697
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
698
|
+
Accessible
|
|
699
|
+
</h3>
|
|
700
|
+
<div class="min-h-72">${themedCard('accessible-theme')}</div>
|
|
701
|
+
</div>
|
|
702
|
+
</div>
|
|
703
|
+
</section>
|
|
704
|
+
`,
|
|
705
|
+
}),
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
const avatarTriggerTemplateSource = `<UiDropdownMenu v-model:open="open" :modal="false">
|
|
709
|
+
<UiDropdownMenuTrigger as-child>
|
|
710
|
+
<button type="button" aria-label="Open profile menu" class="ui-focus-ring rounded-full">
|
|
711
|
+
<UiAvatar :size="10">
|
|
712
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
713
|
+
</UiAvatar>
|
|
714
|
+
</button>
|
|
715
|
+
</UiDropdownMenuTrigger>
|
|
716
|
+
|
|
717
|
+
<UiDropdownMenuContent class="${CARD}" align="start">
|
|
718
|
+
<!-- any of the cards above -->
|
|
719
|
+
</UiDropdownMenuContent>
|
|
720
|
+
</UiDropdownMenu>`;
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* The card together with the avatar that opens it.
|
|
724
|
+
*/
|
|
725
|
+
export const WithAvatarTrigger: Story = {
|
|
726
|
+
render: (args) => ({
|
|
727
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
728
|
+
setup() {
|
|
729
|
+
return useOpenState(args);
|
|
730
|
+
},
|
|
731
|
+
template: stage(`
|
|
732
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
733
|
+
${AVATAR_TRIGGER}
|
|
734
|
+
<UiDropdownMenuContent
|
|
735
|
+
v-bind="stayOpen"
|
|
736
|
+
class="${CARD}"
|
|
737
|
+
align="start"
|
|
738
|
+
:avoid-collisions="false"
|
|
739
|
+
>
|
|
740
|
+
${HEADER}
|
|
741
|
+
<UiDropdownMenuItem>Account settings</UiDropdownMenuItem>
|
|
742
|
+
<UiDropdownMenuItem>Privacy policy</UiDropdownMenuItem>
|
|
743
|
+
<UiDropdownMenuItem>Terms and conditions</UiDropdownMenuItem>
|
|
744
|
+
${SIGN_OUT}
|
|
745
|
+
</UiDropdownMenuContent>
|
|
746
|
+
</UiDropdownMenu>
|
|
747
|
+
`),
|
|
748
|
+
}),
|
|
749
|
+
parameters: {
|
|
750
|
+
docs: { source: { code: avatarTriggerTemplateSource } },
|
|
751
|
+
},
|
|
752
|
+
play: async ({ canvasElement, step }) => {
|
|
753
|
+
// Scenario (UiProfileCard): assistive tech reads the avatar as the control
|
|
754
|
+
// that owns the card, and can follow the link between the two. Non-mutating
|
|
755
|
+
// assertions only, so the Chromatic snapshot for this story stays valid.
|
|
756
|
+
const canvas = within(canvasElement);
|
|
757
|
+
const body = within(document.body);
|
|
758
|
+
const trigger = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
759
|
+
|
|
760
|
+
await step(
|
|
761
|
+
'screen-reader: the avatar announces that it opens a menu (WCAG 4.1.2)',
|
|
762
|
+
async () => {
|
|
763
|
+
await expect(trigger).toHaveAttribute('aria-haspopup', 'menu');
|
|
764
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
765
|
+
},
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
await step(
|
|
769
|
+
'screen-reader: the card is named after the avatar that opened it',
|
|
770
|
+
async () => {
|
|
771
|
+
const menu = await body.findByRole('menu');
|
|
772
|
+
await expect(menu).toHaveAttribute('aria-labelledby', trigger.id);
|
|
773
|
+
},
|
|
774
|
+
);
|
|
775
|
+
},
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
const onSelect = fn();
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Waits for the card to be open and painted. The content fades and zooms in, so
|
|
782
|
+
* it is in the DOM a frame before it is visible.
|
|
783
|
+
* @param body Queries bound to the document body, where the card is portalled.
|
|
784
|
+
*/
|
|
785
|
+
async function expectOpenCard(body: ReturnType<typeof within>) {
|
|
786
|
+
const menu = await body.findByRole('menu');
|
|
787
|
+
await waitFor(async () => {
|
|
788
|
+
await expect(menu).toBeVisible();
|
|
789
|
+
});
|
|
790
|
+
return menu;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The card the hidden test stories drive: closed on load, so a play function
|
|
795
|
+
* can open it the way a user would.
|
|
796
|
+
*/
|
|
797
|
+
function renderTestCard() {
|
|
798
|
+
return {
|
|
799
|
+
components: PROFILE_CARD_COMPONENTS,
|
|
800
|
+
setup() {
|
|
801
|
+
const open = ref(false);
|
|
802
|
+
const language = ref('en');
|
|
803
|
+
return { open, language, onSelect };
|
|
804
|
+
},
|
|
805
|
+
template: stage(`
|
|
806
|
+
<UiDropdownMenu v-model:open="open" :modal="false">
|
|
807
|
+
${AVATAR_TRIGGER}
|
|
808
|
+
<UiDropdownMenuContent class="${CARD}" align="start">
|
|
809
|
+
${HEADER}
|
|
810
|
+
<UiDropdownMenuItem @select="onSelect">
|
|
811
|
+
<UiIcon name="settings" size="s" />
|
|
812
|
+
Your account settings
|
|
813
|
+
</UiDropdownMenuItem>
|
|
814
|
+
<UiDropdownMenuItem>
|
|
815
|
+
<UiIcon name="eye" size="s" />
|
|
816
|
+
Privacy policy
|
|
817
|
+
</UiDropdownMenuItem>
|
|
818
|
+
${languagesSubmenu()}
|
|
819
|
+
${SIGN_OUT}
|
|
820
|
+
</UiDropdownMenuContent>
|
|
821
|
+
</UiDropdownMenu>
|
|
822
|
+
`),
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Opening the card from the avatar, choosing an item, and having the card close
|
|
828
|
+
* behind the choice. Hidden test-only story.
|
|
829
|
+
*/
|
|
830
|
+
export const PointerInteraction: Story = {
|
|
831
|
+
name: 'test - Pointer interaction',
|
|
832
|
+
tags: ['!dev', '!autodocs'],
|
|
833
|
+
parameters: {
|
|
834
|
+
chromatic: { disableSnapshot: true },
|
|
835
|
+
docs: {
|
|
836
|
+
description: {
|
|
837
|
+
story: 'Click the avatar to open the card, then choose an item.',
|
|
838
|
+
},
|
|
839
|
+
},
|
|
840
|
+
},
|
|
841
|
+
render: renderTestCard,
|
|
842
|
+
play: async ({ canvasElement, step }) => {
|
|
843
|
+
// Scenario (UiProfileCard): a pointer user opens the card from the avatar,
|
|
844
|
+
// picks "Your account settings", and the card closes behind the choice.
|
|
845
|
+
onSelect.mockClear();
|
|
846
|
+
const canvas = within(canvasElement);
|
|
847
|
+
const body = within(document.body);
|
|
848
|
+
const trigger = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
849
|
+
|
|
850
|
+
await step('interaction: the avatar opens the card', async () => {
|
|
851
|
+
await userEvent.click(trigger);
|
|
852
|
+
await expectOpenCard(body);
|
|
853
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
await step('interaction: choosing an item closes the card', async () => {
|
|
857
|
+
await userEvent.click(
|
|
858
|
+
body.getByRole('menuitem', { name: 'Your account settings' }),
|
|
859
|
+
);
|
|
860
|
+
await expect(onSelect).toHaveBeenCalledTimes(1);
|
|
861
|
+
await waitFor(async () => {
|
|
862
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
863
|
+
});
|
|
864
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
865
|
+
});
|
|
866
|
+
},
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Reaching the card, its items, and its submenu without a pointer. Hidden
|
|
871
|
+
* test-only story.
|
|
872
|
+
*/
|
|
873
|
+
export const KeyboardNavigation: Story = {
|
|
874
|
+
name: 'test - Keyboard navigation',
|
|
875
|
+
tags: ['!dev', '!autodocs'],
|
|
876
|
+
parameters: {
|
|
877
|
+
chromatic: { disableSnapshot: true },
|
|
878
|
+
docs: {
|
|
879
|
+
description: {
|
|
880
|
+
story:
|
|
881
|
+
'Press `Tab` to focus the avatar, `Enter` to open, arrow keys to move, and `Escape` to dismiss.',
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
render: renderTestCard,
|
|
886
|
+
play: async ({ canvasElement, step }) => {
|
|
887
|
+
// Scenario (UiProfileCard): a keyboard user tabs to the avatar, opens the
|
|
888
|
+
// card with Enter, walks the items, opens the Languages submenu with
|
|
889
|
+
// ArrowRight, and dismisses everything with Escape.
|
|
890
|
+
const canvas = within(canvasElement);
|
|
891
|
+
const body = within(document.body);
|
|
892
|
+
const trigger = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
893
|
+
|
|
894
|
+
await step(
|
|
895
|
+
'keyboard: the avatar is reachable via Tab (WCAG 2.1.1)',
|
|
896
|
+
async () => {
|
|
897
|
+
await userEvent.tab();
|
|
898
|
+
await expect(trigger).toHaveFocus();
|
|
899
|
+
},
|
|
900
|
+
);
|
|
901
|
+
|
|
902
|
+
await step('keyboard: Enter opens the card', async () => {
|
|
903
|
+
await userEvent.keyboard('{Enter}');
|
|
904
|
+
await expectOpenCard(body);
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
await step(
|
|
908
|
+
'keyboard: arrow keys move focus through the items (WCAG 2.4.3)',
|
|
909
|
+
async () => {
|
|
910
|
+
await waitFor(async () => {
|
|
911
|
+
await expect(
|
|
912
|
+
body.getByRole('menuitem', { name: 'Your account settings' }),
|
|
913
|
+
).toHaveFocus();
|
|
914
|
+
});
|
|
915
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
916
|
+
await expect(
|
|
917
|
+
body.getByRole('menuitem', { name: 'Privacy policy' }),
|
|
918
|
+
).toHaveFocus();
|
|
919
|
+
},
|
|
920
|
+
);
|
|
921
|
+
|
|
922
|
+
await step('keyboard: ArrowRight opens the submenu', async () => {
|
|
923
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
924
|
+
const languages = body.getByRole('menuitem', { name: 'Languages' });
|
|
925
|
+
await expect(languages).toHaveFocus();
|
|
926
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
927
|
+
await waitFor(async () => {
|
|
928
|
+
await expect(
|
|
929
|
+
body.getByRole('menuitemradio', { name: 'English' }),
|
|
930
|
+
).toBeVisible();
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
await step(
|
|
935
|
+
'screen-reader: the languages are radio options with a selected state (WCAG 4.1.2)',
|
|
936
|
+
async () => {
|
|
937
|
+
await expect(
|
|
938
|
+
body.getByRole('menuitemradio', { name: 'English' }),
|
|
939
|
+
).toHaveAttribute('aria-checked', 'true');
|
|
940
|
+
await expect(
|
|
941
|
+
body.getByRole('menuitemradio', { name: 'German' }),
|
|
942
|
+
).toHaveAttribute('aria-checked', 'false');
|
|
943
|
+
},
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
await step(
|
|
947
|
+
'keyboard: Escape closes the card and restores focus to the avatar (WCAG 2.1.2)',
|
|
948
|
+
async () => {
|
|
949
|
+
await userEvent.keyboard('{Escape}');
|
|
950
|
+
await userEvent.keyboard('{Escape}');
|
|
951
|
+
await waitFor(async () => {
|
|
952
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
953
|
+
});
|
|
954
|
+
// Reka hands focus back on the next tick, after the closing animation
|
|
955
|
+
// has been kicked off.
|
|
956
|
+
await waitFor(async () => {
|
|
957
|
+
await expect(trigger).toHaveFocus();
|
|
958
|
+
});
|
|
959
|
+
},
|
|
960
|
+
);
|
|
961
|
+
},
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
966
|
+
* try 400% reflow (WCAG 1.4.10); the card must stay readable and operable.
|
|
967
|
+
* Hidden test-only story.
|
|
968
|
+
*/
|
|
969
|
+
export const ZoomMagnification: Story = {
|
|
970
|
+
name: 'test - Zoom magnification',
|
|
971
|
+
tags: ['!dev', '!autodocs'],
|
|
972
|
+
globals: { zoom: '200' },
|
|
973
|
+
parameters: {
|
|
974
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
975
|
+
// already covers magnified snapshots, so skip this one.
|
|
976
|
+
chromatic: { disableSnapshot: true },
|
|
977
|
+
docs: {
|
|
978
|
+
description: {
|
|
979
|
+
story:
|
|
980
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
981
|
+
},
|
|
982
|
+
},
|
|
983
|
+
},
|
|
984
|
+
render: renderTestCard,
|
|
985
|
+
play: async ({ canvasElement, step }) => {
|
|
986
|
+
// Scenario (UiProfileCard): at 200% page zoom the avatar keeps its
|
|
987
|
+
// accessible name and the card still opens with readable items.
|
|
988
|
+
const canvas = within(canvasElement);
|
|
989
|
+
const body = within(document.body);
|
|
990
|
+
const trigger = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
991
|
+
|
|
992
|
+
await step(
|
|
993
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
994
|
+
async () => {
|
|
995
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
996
|
+
},
|
|
997
|
+
);
|
|
998
|
+
|
|
999
|
+
await step('zoom: the avatar keeps its accessible name', async () => {
|
|
1000
|
+
await expect(trigger).toBeVisible();
|
|
1001
|
+
await expect(trigger).toHaveAccessibleName('Open profile menu');
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
await step('zoom: the card opens and stays readable', async () => {
|
|
1005
|
+
await userEvent.click(trigger);
|
|
1006
|
+
await expectOpenCard(body);
|
|
1007
|
+
await expect(
|
|
1008
|
+
body.getByRole('menuitem', { name: 'Sign out' }),
|
|
1009
|
+
).toBeVisible();
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Rendered at the 320px mobile reflow breakpoint. The avatar meets the minimum
|
|
1016
|
+
* touch-target size and the card stays operable. Hidden test-only story.
|
|
1017
|
+
*/
|
|
1018
|
+
export const MobileBreakpoint: Story = {
|
|
1019
|
+
name: 'test - Mobile breakpoint',
|
|
1020
|
+
tags: ['!dev', '!autodocs'],
|
|
1021
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1022
|
+
parameters: {
|
|
1023
|
+
// Reflow snapshots are already covered by the accessible-reflow Chromatic
|
|
1024
|
+
// mode, and the play opens the card, so skip this snapshot.
|
|
1025
|
+
chromatic: { disableSnapshot: true },
|
|
1026
|
+
docs: {
|
|
1027
|
+
description: {
|
|
1028
|
+
story:
|
|
1029
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1030
|
+
},
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
render: renderTestCard,
|
|
1034
|
+
play: async ({ canvasElement, step }) => {
|
|
1035
|
+
// Scenario (UiProfileCard): at the 320px mobile breakpoint the avatar is a
|
|
1036
|
+
// large enough touch target and the card opens within the viewport.
|
|
1037
|
+
const canvas = within(canvasElement);
|
|
1038
|
+
const body = within(document.body);
|
|
1039
|
+
const trigger = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
1040
|
+
|
|
1041
|
+
await step(
|
|
1042
|
+
'mobile: the avatar meets the minimum touch-target size (WCAG 2.5.8)',
|
|
1043
|
+
async () => {
|
|
1044
|
+
const { width, height } = trigger.getBoundingClientRect();
|
|
1045
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1046
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1047
|
+
},
|
|
1048
|
+
);
|
|
1049
|
+
|
|
1050
|
+
await step(
|
|
1051
|
+
'mobile: the card opens and its items stay operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
|
|
1052
|
+
async () => {
|
|
1053
|
+
await userEvent.click(trigger);
|
|
1054
|
+
await expectOpenCard(body);
|
|
1055
|
+
await userEvent.click(
|
|
1056
|
+
body.getByRole('menuitem', { name: 'Privacy policy' }),
|
|
1057
|
+
);
|
|
1058
|
+
await waitFor(async () => {
|
|
1059
|
+
await expect(body.queryByRole('menu')).toBeNull();
|
|
1060
|
+
});
|
|
1061
|
+
},
|
|
1062
|
+
);
|
|
1063
|
+
},
|
|
1064
|
+
};
|