@aleph-alpha/ui-library 7.0.0 → 7.0.2
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/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +1 -1
- package/dist/system/icons/story-sidebar-icons.json +74 -17
- package/dist/system/lib.js +1167 -1162
- package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +74 -17
- package/package.json +8 -3
- package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
- package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
- package/src/components/UiAlert/UiAlert.guidance.md +66 -0
- package/src/components/UiAlert/UiAlert.stories.ts +167 -143
- package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
- package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
- package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
- package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
- package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
- package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
- package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
- package/src/components/UiBadge/UiBadge.guidance.md +65 -0
- package/src/components/UiBadge/UiBadge.stories.ts +325 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
- package/src/components/UiButton/UiButton.stories.ts +5 -2
- package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
- package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
- package/src/components/UiCard/UiCard.guidance.md +65 -0
- package/src/components/UiCard/UiCard.stories.ts +393 -0
- package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
- package/src/components/UiChip/UiChip.guidance.md +64 -0
- package/src/components/UiChip/UiChip.stories.ts +162 -138
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
- package/src/components/UiDialog/UiDialog.guidance.md +66 -0
- package/src/components/UiDialog/UiDialog.stories.ts +90 -66
- package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
- package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
- package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +332 -85
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +134 -0
- package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +23 -2
- package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
- package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
- package/src/components/UiField/UiField.guidance.md +63 -0
- package/src/components/UiField/UiField.stories.ts +90 -113
- package/src/components/UiFileType/UiFileType.stories.ts +254 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
- package/src/components/UiIcon/UiIcon.stories.ts +256 -1
- package/src/components/UiInput/UiInput.guidance.md +64 -0
- package/src/components/UiInput/UiInput.stories.ts +132 -80
- package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
- package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
- package/src/components/UiItem/UiItem.guidance.md +66 -0
- package/src/components/UiItem/UiItem.stories.ts +81 -28
- package/src/components/UiKbd/UiKbd.guidance.md +65 -0
- package/src/components/UiKbd/UiKbd.stories.ts +373 -3
- package/src/components/UiLabel/UiLabel.guidance.md +65 -0
- package/src/components/UiLabel/UiLabel.stories.ts +163 -139
- package/src/components/UiListbox/UiListbox.stories.ts +197 -195
- package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
- package/src/components/UiPopover/UiPopover.guidance.md +65 -0
- package/src/components/UiPopover/UiPopover.stories.ts +115 -91
- package/src/components/UiProgress/UiProgress.guidance.md +65 -0
- package/src/components/UiProgress/UiProgress.stories.ts +300 -0
- package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
- package/src/components/UiResizable/UiResizable.guidance.md +65 -0
- package/src/components/UiResizable/UiResizable.stories.ts +176 -152
- package/src/components/UiSelect/UiSelect.guidance.md +66 -0
- package/src/components/UiSelect/UiSelect.stories.ts +150 -126
- package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
- package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
- package/src/components/UiSheet/UiSheet.guidance.md +66 -0
- package/src/components/UiSheet/UiSheet.stories.ts +194 -170
- package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
- package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
- package/src/components/UiSlider/UiSlider.guidance.md +66 -0
- package/src/components/UiSlider/UiSlider.stories.ts +150 -126
- package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
- package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
- package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
- package/src/components/UiStepper/UiStepper.guidance.md +66 -0
- package/src/components/UiStepper/UiStepper.stories.ts +142 -124
- package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
- package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
- package/src/components/UiTable/UiTable.guidance.md +66 -0
- package/src/components/UiTable/UiTable.stories.ts +530 -12
- package/src/components/UiTabs/UiTabs.guidance.md +66 -0
- package/src/components/UiTabs/UiTabs.stories.ts +174 -150
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
- package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
- package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
- package/src/components/UiToggle/UiToggle.guidance.md +66 -0
- package/src/components/UiToggle/UiToggle.stories.ts +183 -159
- package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
- package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
- package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
- package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
- package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
- package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
- package/src/patterns/UiPlaceholder/types.ts +1 -0
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +74 -72
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
figma: '29176:16323'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<!-- Synced from Figma by scripts/sync-figma-docs.mjs. Edit the copy in Figma: changes made here are overwritten. -->
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
The Dropdown Menu component presents a set of actions in a temporary surface that opens from a trigger. It keeps secondary and contextual commands out of the way until a user needs them, without taking the user away from the current view.
|
|
10
|
+
|
|
11
|
+
Use it for actions a user performs on an object or in a context. It is not a form control: choosing a value that will be submitted belongs to Select or Combobox.
|
|
12
|
+
|
|
13
|
+
### Actions, not values
|
|
14
|
+
|
|
15
|
+
A dropdown menu triggers behaviour, it never holds a value:
|
|
16
|
+
|
|
17
|
+
- Dropdown Menu for commands such as Edit, Duplicate, Move or Delete
|
|
18
|
+
- Select for choosing one value in a form
|
|
19
|
+
- Combobox when the list is long enough to need filtering
|
|
20
|
+
- Popover when the surface holds rich content instead of a list of items
|
|
21
|
+
|
|
22
|
+
### Progressive disclosure
|
|
23
|
+
|
|
24
|
+
Reveal one layer at a time, and only where it helps the user act:
|
|
25
|
+
|
|
26
|
+
1. Trigger names what the menu will act on
|
|
27
|
+
2. Menu lists the actions available right now
|
|
28
|
+
3. Submenu holds variations of a single action, never a second topic
|
|
29
|
+
4. Separators and labels appear only when a grouping carries meaning
|
|
30
|
+
|
|
31
|
+
### Consistency
|
|
32
|
+
|
|
33
|
+
Every menu is composed from the same parts, whatever opens it:
|
|
34
|
+
|
|
35
|
+
- Trigger (button, icon button, avatar)
|
|
36
|
+
- Menu surface
|
|
37
|
+
- Item (default, checkbox, radio, icon)
|
|
38
|
+
- Item label (level 1, level 2)
|
|
39
|
+
- Separator
|
|
40
|
+
- Sub-trigger and submenu
|
|
41
|
+
- User item
|
|
42
|
+
|
|
43
|
+
## Do
|
|
44
|
+
|
|
45
|
+
- Order items by how often they are used, most frequent first
|
|
46
|
+
- Start item labels with a verb and keep them to a few words
|
|
47
|
+
- Group related items with a separator, and add a label when the group needs naming
|
|
48
|
+
- Place destructive actions last, separated from the rest
|
|
49
|
+
- Limit menus to a single level of submenu
|
|
50
|
+
- Close the menu as soon as an action is chosen
|
|
51
|
+
|
|
52
|
+
## Don't
|
|
53
|
+
|
|
54
|
+
- Use a dropdown menu to select a value in a form
|
|
55
|
+
- Open or close the menu on hover alone
|
|
56
|
+
- Nest submenus more than one level deep
|
|
57
|
+
- Put more than roughly ten items in a menu without grouping them
|
|
58
|
+
- Mix unrelated actions into a single submenu
|
|
59
|
+
- Leave an icon-only trigger without an accessible name
|
|
60
|
+
|
|
61
|
+
## Accessibility
|
|
62
|
+
|
|
63
|
+
- The trigger is a button with aria-haspopup="menu" and aria-expanded reflecting the open state
|
|
64
|
+
- The surface uses role="menu"; items use menuitem, menuitemcheckbox or menuitemradio
|
|
65
|
+
- Enter or Space opens the menu and moves focus to the first item; Escape closes it and returns focus to the trigger
|
|
66
|
+
- Arrow keys move between items, Home and End jump to first and last, Right and Left open and close a submenu
|
|
67
|
+
- Checkbox and radio items expose aria-checked, so state never rests on the check icon alone
|
|
68
|
+
- Unavailable items are marked aria-disabled and explained, never silently removed
|
|
@@ -30,6 +30,16 @@ import {
|
|
|
30
30
|
GlobeIcon,
|
|
31
31
|
MessageSquareIcon,
|
|
32
32
|
} from '@/icons/lucide';
|
|
33
|
+
import {
|
|
34
|
+
accessibilityRequirementsTemplate,
|
|
35
|
+
designNotesStory,
|
|
36
|
+
guidanceLinks,
|
|
37
|
+
guidanceSectionClass,
|
|
38
|
+
parseGuidance,
|
|
39
|
+
} from '../../../.storybook/guidance';
|
|
40
|
+
import guidanceMarkdown from './UiDropdownMenu.guidance.md?raw';
|
|
41
|
+
|
|
42
|
+
const guidance = parseGuidance(guidanceMarkdown);
|
|
33
43
|
|
|
34
44
|
/**
|
|
35
45
|
* UiDropdownMenu is a floating menu of actions or settings anchored to a trigger element, with support for submenus, checkboxes, and radio groups.
|
|
@@ -55,6 +65,7 @@ const meta: Meta<typeof UiDropdownMenu> = {
|
|
|
55
65
|
modal: true,
|
|
56
66
|
},
|
|
57
67
|
parameters: {
|
|
68
|
+
docs: { links: guidanceLinks(guidance) },
|
|
58
69
|
a11y: {
|
|
59
70
|
options: {
|
|
60
71
|
rules: {
|
|
@@ -161,6 +172,102 @@ export const Default: Story = {
|
|
|
161
172
|
},
|
|
162
173
|
};
|
|
163
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Usage, guidelines, and do's and don'ts from the Figma documentation.
|
|
177
|
+
*/
|
|
178
|
+
export const DesignNotes: Story = {
|
|
179
|
+
...designNotesStory(guidance),
|
|
180
|
+
tags: ['!autodocs'],
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* How the menu behaves for keyboard and screen-reader users.
|
|
185
|
+
*/
|
|
186
|
+
export const Accessibility: Story = {
|
|
187
|
+
tags: ['!autodocs'],
|
|
188
|
+
parameters: {
|
|
189
|
+
surface: 'primary',
|
|
190
|
+
a11y: { test: 'off' },
|
|
191
|
+
chromatic: { disableSnapshot: true },
|
|
192
|
+
docs: { canvas: { sourceState: 'none' } },
|
|
193
|
+
},
|
|
194
|
+
render: () => ({
|
|
195
|
+
components: {
|
|
196
|
+
UiDropdownMenu,
|
|
197
|
+
UiDropdownMenuTrigger,
|
|
198
|
+
UiDropdownMenuContent,
|
|
199
|
+
UiDropdownMenuItem,
|
|
200
|
+
UiDropdownMenuLabel,
|
|
201
|
+
UiDropdownMenuSeparator,
|
|
202
|
+
UiDropdownMenuCheckboxItem,
|
|
203
|
+
UiDropdownMenuSub,
|
|
204
|
+
UiDropdownMenuSubTrigger,
|
|
205
|
+
UiDropdownMenuSubContent,
|
|
206
|
+
UiButton,
|
|
207
|
+
},
|
|
208
|
+
setup() {
|
|
209
|
+
const open = ref(true);
|
|
210
|
+
return { open, stayOpen };
|
|
211
|
+
},
|
|
212
|
+
template: `
|
|
213
|
+
<section class="${guidanceSectionClass}">
|
|
214
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
215
|
+
Accessibility
|
|
216
|
+
</h2>
|
|
217
|
+
|
|
218
|
+
${accessibilityRequirementsTemplate(guidance.accessibility, 'Requirements')}
|
|
219
|
+
|
|
220
|
+
<div class="flex flex-col gap-2">
|
|
221
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
222
|
+
In code
|
|
223
|
+
</h3>
|
|
224
|
+
<ul class="body-m-regular list-disc pl-5 text-content-on-surface-primary">
|
|
225
|
+
<li>The trigger needs a name of its own: give an icon-only trigger an <code class="label-s-regular">aria-label</code>, since the icon is not read out.</li>
|
|
226
|
+
<li>The trigger tells assistive technology that it opens a menu, and whether that menu is currently open.</li>
|
|
227
|
+
<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>
|
|
228
|
+
<li>A label groups the items below it and is not a choice — it cannot be focused or activated.</li>
|
|
229
|
+
<li>A disabled item says it is disabled and is skipped by the arrow keys, so it is never a dead end.</li>
|
|
230
|
+
<li>Checkbox and radio items report checked and selected, so the state is spoken and not carried by the tick alone.</li>
|
|
231
|
+
<li>An item that leads to a second level says so, and opens with the right arrow key as well as on hover.</li>
|
|
232
|
+
<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>
|
|
233
|
+
<li>A modal menu hides the rest of the page from assistive technology. Pass <code class="label-s-regular">:modal="false"</code> when what is behind the menu should stay available.</li>
|
|
234
|
+
<li>Triggers need a touch target of at least 24px; every row is 36px tall, so it meets that on its own.</li>
|
|
235
|
+
<li>On a phone only five rows are in view and the rest scroll under a fade. The fade is decoration: the rows behind it are still in the tree, the arrow keys still reach them, and the list scrolls to keep the focused row visible.</li>
|
|
236
|
+
<li>On a phone a second level opens stacked 8px above or below its row, as wide as the menu, and dims the rest of the menu. It is still a menu named by its row: the row says it is expanded, the right arrow key opens it and moves focus into it, and the left arrow key closes it and puts focus back on the row.</li>
|
|
237
|
+
<li>Put the checked state on the row, not on a control inside it: a switch or checkbox inside a menu item is nested interactive content. Give the row <code class="label-s-regular">role="menuitemcheckbox"</code> and <code class="label-s-regular">aria-checked</code>, and mark the visual control <code class="label-s-regular">inert</code>.</li>
|
|
238
|
+
</ul>
|
|
239
|
+
</div>
|
|
240
|
+
|
|
241
|
+
<div class="flex flex-col gap-2">
|
|
242
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
243
|
+
Enable accessibility theme
|
|
244
|
+
</h3>
|
|
245
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
246
|
+
When accessibility is required, enable our accessibility theme. This
|
|
247
|
+
increases contrast and ensures there are no color contrast issues.
|
|
248
|
+
</p>
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<div class="flex flex-wrap gap-12">
|
|
252
|
+
<div class="flex w-64 flex-col gap-3">
|
|
253
|
+
<h3 class="label-m-medium text-content-on-surface-primary">
|
|
254
|
+
Default
|
|
255
|
+
</h3>
|
|
256
|
+
<div class="min-h-72">${themedMenu()}</div>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<div class="flex w-64 flex-col gap-3">
|
|
260
|
+
<h3 class="label-m-medium text-content-on-surface-primary">
|
|
261
|
+
Accessible
|
|
262
|
+
</h3>
|
|
263
|
+
<div class="min-h-72">${themedMenu('accessible-theme')}</div>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
</section>
|
|
267
|
+
`,
|
|
268
|
+
}),
|
|
269
|
+
};
|
|
270
|
+
|
|
164
271
|
const withLabelsTemplateSource = `<script setup lang="ts">
|
|
165
272
|
import { ref } from 'vue'
|
|
166
273
|
import {
|
|
@@ -1952,91 +2059,6 @@ const themedMenu = (themeClass = '') => `
|
|
|
1952
2059
|
</UiDropdownMenu>
|
|
1953
2060
|
`;
|
|
1954
2061
|
|
|
1955
|
-
/**
|
|
1956
|
-
* How the menu behaves for keyboard and screen-reader users.
|
|
1957
|
-
*/
|
|
1958
|
-
export const Accessibility: Story = {
|
|
1959
|
-
tags: ['!autodocs'],
|
|
1960
|
-
parameters: {
|
|
1961
|
-
a11y: { test: 'off' },
|
|
1962
|
-
chromatic: { disableSnapshot: true },
|
|
1963
|
-
docs: { canvas: { sourceState: 'none' } },
|
|
1964
|
-
},
|
|
1965
|
-
render: () => ({
|
|
1966
|
-
components: {
|
|
1967
|
-
UiDropdownMenu,
|
|
1968
|
-
UiDropdownMenuTrigger,
|
|
1969
|
-
UiDropdownMenuContent,
|
|
1970
|
-
UiDropdownMenuItem,
|
|
1971
|
-
UiDropdownMenuLabel,
|
|
1972
|
-
UiDropdownMenuSeparator,
|
|
1973
|
-
UiDropdownMenuCheckboxItem,
|
|
1974
|
-
UiDropdownMenuSub,
|
|
1975
|
-
UiDropdownMenuSubTrigger,
|
|
1976
|
-
UiDropdownMenuSubContent,
|
|
1977
|
-
UiButton,
|
|
1978
|
-
},
|
|
1979
|
-
setup() {
|
|
1980
|
-
const open = ref(true);
|
|
1981
|
-
return { open, stayOpen };
|
|
1982
|
-
},
|
|
1983
|
-
template: `
|
|
1984
|
-
<section class="flex flex-col gap-6 p-4">
|
|
1985
|
-
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
1986
|
-
Accessibility
|
|
1987
|
-
</h2>
|
|
1988
|
-
|
|
1989
|
-
<div class="flex flex-col gap-2">
|
|
1990
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
1991
|
-
Requirements
|
|
1992
|
-
</h3>
|
|
1993
|
-
<ul class="body-m-regular list-disc pl-5 text-content-on-surface-primary">
|
|
1994
|
-
<li>The trigger needs a name of its own: give an icon-only trigger an <code class="label-s-regular">aria-label</code>, since the icon is not read out.</li>
|
|
1995
|
-
<li>The trigger tells assistive technology that it opens a menu, and whether that menu is currently open.</li>
|
|
1996
|
-
<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>
|
|
1997
|
-
<li>A label groups the items below it and is not a choice — it cannot be focused or activated.</li>
|
|
1998
|
-
<li>A disabled item says it is disabled and is skipped by the arrow keys, so it is never a dead end.</li>
|
|
1999
|
-
<li>Checkbox and radio items report checked and selected, so the state is spoken and not carried by the tick alone.</li>
|
|
2000
|
-
<li>An item that leads to a second level says so, and opens with the right arrow key as well as on hover.</li>
|
|
2001
|
-
<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>
|
|
2002
|
-
<li>A modal menu hides the rest of the page from assistive technology. Pass <code class="label-s-regular">:modal="false"</code> when what is behind the menu should stay available.</li>
|
|
2003
|
-
<li>Triggers need a touch target of at least 24px; every row is 36px tall, so it meets that on its own.</li>
|
|
2004
|
-
<li>On a phone only five rows are in view and the rest scroll under a fade. The fade is decoration: the rows behind it are still in the tree, the arrow keys still reach them, and the list scrolls to keep the focused row visible.</li>
|
|
2005
|
-
<li>On a phone a second level opens stacked 8px above or below its row, as wide as the menu, and dims the rest of the menu. It is still a menu named by its row: the row says it is expanded, the right arrow key opens it and moves focus into it, and the left arrow key closes it and puts focus back on the row.</li>
|
|
2006
|
-
<li>Put the checked state on the row, not on a control inside it: a switch or checkbox inside a menu item is nested interactive content. Give the row <code class="label-s-regular">role="menuitemcheckbox"</code> and <code class="label-s-regular">aria-checked</code>, and mark the visual control <code class="label-s-regular">inert</code>.</li>
|
|
2007
|
-
</ul>
|
|
2008
|
-
</div>
|
|
2009
|
-
|
|
2010
|
-
<div class="flex flex-col gap-2">
|
|
2011
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
2012
|
-
Enable accessibility theme
|
|
2013
|
-
</h3>
|
|
2014
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
2015
|
-
When accessibility is required, enable our accessibility theme. This
|
|
2016
|
-
increases contrast and ensures there are no color contrast issues.
|
|
2017
|
-
</p>
|
|
2018
|
-
</div>
|
|
2019
|
-
|
|
2020
|
-
<div class="flex flex-wrap gap-12">
|
|
2021
|
-
<div class="flex w-64 flex-col gap-3">
|
|
2022
|
-
<h3 class="label-m-medium text-content-on-surface-primary">
|
|
2023
|
-
Default
|
|
2024
|
-
</h3>
|
|
2025
|
-
<div class="min-h-72">${themedMenu()}</div>
|
|
2026
|
-
</div>
|
|
2027
|
-
|
|
2028
|
-
<div class="flex w-64 flex-col gap-3">
|
|
2029
|
-
<h3 class="label-m-medium text-content-on-surface-primary">
|
|
2030
|
-
Accessible
|
|
2031
|
-
</h3>
|
|
2032
|
-
<div class="min-h-72">${themedMenu('accessible-theme')}</div>
|
|
2033
|
-
</div>
|
|
2034
|
-
</div>
|
|
2035
|
-
</section>
|
|
2036
|
-
`,
|
|
2037
|
-
}),
|
|
2038
|
-
};
|
|
2039
|
-
|
|
2040
2062
|
/*
|
|
2041
2063
|
* ─────────────────────────────────────────────────────────────────────────────
|
|
2042
2064
|
* Interaction & accessibility tests (play functions)
|
|
@@ -2715,3 +2737,228 @@ export const MobileSubmenu: Story = {
|
|
|
2715
2737
|
);
|
|
2716
2738
|
},
|
|
2717
2739
|
};
|
|
2740
|
+
|
|
2741
|
+
/**
|
|
2742
|
+
* Makes the menu placement see a window `height` pixels tall, in the same
|
|
2743
|
+
* pixels as `getBoundingClientRect`. The test-runner opens mobile stories in a
|
|
2744
|
+
* 320 × 900 viewport, where a five-row submenu always fits beside its row, so
|
|
2745
|
+
* the short window has to be reported rather than resized.
|
|
2746
|
+
* @param height The window height to report.
|
|
2747
|
+
* @returns Restores the real window height.
|
|
2748
|
+
*/
|
|
2749
|
+
function pretendWindowHeight(height: number) {
|
|
2750
|
+
const own = Object.getOwnPropertyDescriptor(window, 'innerHeight');
|
|
2751
|
+
Object.defineProperty(window, 'innerHeight', {
|
|
2752
|
+
configurable: true,
|
|
2753
|
+
get: () => height,
|
|
2754
|
+
});
|
|
2755
|
+
return () => {
|
|
2756
|
+
if (own) {
|
|
2757
|
+
Object.defineProperty(window, 'innerHeight', own);
|
|
2758
|
+
} else {
|
|
2759
|
+
Reflect.deleteProperty(window, 'innerHeight');
|
|
2760
|
+
}
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
/** Resolves after two frames, once scroll events and placement have run. */
|
|
2765
|
+
function settle() {
|
|
2766
|
+
return new Promise((resolve) => {
|
|
2767
|
+
requestAnimationFrame(() => requestAnimationFrame(resolve));
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
/**
|
|
2772
|
+
* Waits for an element's CSS animations to finish so its geometry is stable.
|
|
2773
|
+
* `finished` rejects when an animation is cancelled, which is not a failure
|
|
2774
|
+
* here — it just means the element settled another way.
|
|
2775
|
+
* @param element Element whose animations should settle.
|
|
2776
|
+
*/
|
|
2777
|
+
async function settleAnimations(element: HTMLElement) {
|
|
2778
|
+
if (typeof element.getAnimations !== 'function') return;
|
|
2779
|
+
await Promise.all(
|
|
2780
|
+
element
|
|
2781
|
+
.getAnimations()
|
|
2782
|
+
.map((animation) => animation.finished.catch(() => undefined)),
|
|
2783
|
+
);
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
/**
|
|
2787
|
+
* Waits until `row` sits fully inside the visible part of `scroll`.
|
|
2788
|
+
* @param row A menu row.
|
|
2789
|
+
* @param scroll The scroll box that holds it.
|
|
2790
|
+
*/
|
|
2791
|
+
async function expectRowInList(row: HTMLElement, scroll: HTMLElement) {
|
|
2792
|
+
await waitFor(async () => {
|
|
2793
|
+
const rowRect = row.getBoundingClientRect();
|
|
2794
|
+
const listRect = scroll.getBoundingClientRect();
|
|
2795
|
+
await expect(rowRect.top).toBeGreaterThanOrEqual(listRect.top - 1);
|
|
2796
|
+
await expect(rowRect.bottom).toBeLessThanOrEqual(listRect.bottom + 1);
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
/**
|
|
2801
|
+
* A capped submenu on a short phone screen, such as 400% zoom: neither side of
|
|
2802
|
+
* its row can hold five rows, so its list is cut to the room left and every
|
|
2803
|
+
* row stays reachable by scrolling, by keyboard, and after the submenu is
|
|
2804
|
+
* placed again. Hidden test-only story.
|
|
2805
|
+
*/
|
|
2806
|
+
export const MobileCappedSubmenu: Story = {
|
|
2807
|
+
name: 'test - Mobile capped submenu',
|
|
2808
|
+
tags: ['!dev', '!autodocs'],
|
|
2809
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
2810
|
+
parameters: {
|
|
2811
|
+
// The play moves focus into the submenu, and the reflow Chromatic mode
|
|
2812
|
+
// already snapshots the mobile layout.
|
|
2813
|
+
chromatic: { disableSnapshot: true },
|
|
2814
|
+
},
|
|
2815
|
+
render: () => ({
|
|
2816
|
+
components: {
|
|
2817
|
+
UiDropdownMenu,
|
|
2818
|
+
UiDropdownMenuTrigger,
|
|
2819
|
+
UiDropdownMenuContent,
|
|
2820
|
+
UiDropdownMenuItem,
|
|
2821
|
+
UiDropdownMenuSub,
|
|
2822
|
+
UiDropdownMenuSubTrigger,
|
|
2823
|
+
UiDropdownMenuSubContent,
|
|
2824
|
+
UiButton,
|
|
2825
|
+
},
|
|
2826
|
+
setup() {
|
|
2827
|
+
const folders = Array.from({ length: 12 }, (_, i) => `Folder ${i + 1}`);
|
|
2828
|
+
return { folders };
|
|
2829
|
+
},
|
|
2830
|
+
template: `<div class="flex min-h-100 items-start p-6">
|
|
2831
|
+
<UiDropdownMenu :modal="false">
|
|
2832
|
+
<UiDropdownMenuTrigger as-child>
|
|
2833
|
+
<UiButton variant="outline">Open Menu</UiButton>
|
|
2834
|
+
</UiDropdownMenuTrigger>
|
|
2835
|
+
<UiDropdownMenuContent class="w-56" align="start">
|
|
2836
|
+
<UiDropdownMenuSub>
|
|
2837
|
+
<UiDropdownMenuSubTrigger>Move to</UiDropdownMenuSubTrigger>
|
|
2838
|
+
<UiDropdownMenuSubContent>
|
|
2839
|
+
<UiDropdownMenuItem v-for="folder in folders" :key="folder">
|
|
2840
|
+
{{ folder }}
|
|
2841
|
+
</UiDropdownMenuItem>
|
|
2842
|
+
</UiDropdownMenuSubContent>
|
|
2843
|
+
</UiDropdownMenuSub>
|
|
2844
|
+
<UiDropdownMenuItem>Rename</UiDropdownMenuItem>
|
|
2845
|
+
<UiDropdownMenuItem>Delete</UiDropdownMenuItem>
|
|
2846
|
+
</UiDropdownMenuContent>
|
|
2847
|
+
</UiDropdownMenu>
|
|
2848
|
+
</div>`,
|
|
2849
|
+
}),
|
|
2850
|
+
play: async ({ canvasElement, step }) => {
|
|
2851
|
+
// Scenario (UiDropdownMenu): on a short phone screen a keyboard user opens
|
|
2852
|
+
// "Move to", gets a submenu capped to the room below its row, scrolls it
|
|
2853
|
+
// to "Folder 12", jumps between its ends with Home and End, and still
|
|
2854
|
+
// reaches the last folder after the submenu is placed again.
|
|
2855
|
+
const canvas = within(canvasElement);
|
|
2856
|
+
const body = within(document.body);
|
|
2857
|
+
let restoreHeight: (() => void) | undefined;
|
|
2858
|
+
|
|
2859
|
+
try {
|
|
2860
|
+
await step(
|
|
2861
|
+
'mobile: in a short window the submenu caps its list to the room left (WCAG 1.4.10 Reflow)',
|
|
2862
|
+
async () => {
|
|
2863
|
+
await userEvent.click(
|
|
2864
|
+
canvas.getByRole('button', { name: 'Open Menu' }),
|
|
2865
|
+
);
|
|
2866
|
+
// The menu slides in from 8px higher. Measured mid-animation, the row
|
|
2867
|
+
// still moves once the slide ends, and placing the submenu again for
|
|
2868
|
+
// that shrinks its cap after the list has been scrolled to its end.
|
|
2869
|
+
await settleAnimations(await expectOpenMenu(body));
|
|
2870
|
+
const row = body.getByRole('menuitem', { name: 'Move to' });
|
|
2871
|
+
// 120px under the row and less above it: neither side holds five rows.
|
|
2872
|
+
const height = Math.round(row.getBoundingClientRect().bottom + 120);
|
|
2873
|
+
restoreHeight = pretendWindowHeight(height);
|
|
2874
|
+
|
|
2875
|
+
row.focus();
|
|
2876
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
2877
|
+
const submenu = await waitFor(() => {
|
|
2878
|
+
const found = body
|
|
2879
|
+
.getAllByRole('menu')
|
|
2880
|
+
.find((menu) => menu.getAttribute('aria-labelledby') === row.id);
|
|
2881
|
+
if (!found) throw new Error('The submenu is not open.');
|
|
2882
|
+
return found;
|
|
2883
|
+
});
|
|
2884
|
+
await waitFor(async () => {
|
|
2885
|
+
await expect(submenu).toHaveAttribute('data-mobile-clamped');
|
|
2886
|
+
const rect = submenu.getBoundingClientRect();
|
|
2887
|
+
await expect(rect.top).toBeGreaterThanOrEqual(0);
|
|
2888
|
+
await expect(rect.bottom).toBeLessThanOrEqual(height + 1);
|
|
2889
|
+
});
|
|
2890
|
+
await settleAnimations(submenu);
|
|
2891
|
+
},
|
|
2892
|
+
);
|
|
2893
|
+
|
|
2894
|
+
await step(
|
|
2895
|
+
'interaction: the capped list scrolls all the way to its last row',
|
|
2896
|
+
async () => {
|
|
2897
|
+
const submenu = body.getByRole('menu', { name: 'Move to' });
|
|
2898
|
+
const { scroll } = getMobileViewport(submenu);
|
|
2899
|
+
await expect(scroll.scrollHeight).toBeGreaterThan(
|
|
2900
|
+
scroll.clientHeight,
|
|
2901
|
+
);
|
|
2902
|
+
scroll.scrollTop = scroll.scrollHeight;
|
|
2903
|
+
await settle();
|
|
2904
|
+
await expectRowInList(
|
|
2905
|
+
body.getByRole('menuitem', { name: 'Folder 12' }),
|
|
2906
|
+
scroll,
|
|
2907
|
+
);
|
|
2908
|
+
},
|
|
2909
|
+
);
|
|
2910
|
+
|
|
2911
|
+
await step(
|
|
2912
|
+
'keyboard: End and Home scroll the focused row into the capped list (WCAG 2.4.11)',
|
|
2913
|
+
async () => {
|
|
2914
|
+
const submenu = body.getByRole('menu', { name: 'Move to' });
|
|
2915
|
+
const { scroll } = getMobileViewport(submenu);
|
|
2916
|
+
// Back at the top, with focus still on "Folder 1" from opening it.
|
|
2917
|
+
scroll.scrollTop = 0;
|
|
2918
|
+
await settle();
|
|
2919
|
+
|
|
2920
|
+
await userEvent.keyboard('{End}');
|
|
2921
|
+
const last = body.getByRole('menuitem', { name: 'Folder 12' });
|
|
2922
|
+
await waitFor(async () => {
|
|
2923
|
+
await expect(last).toHaveFocus();
|
|
2924
|
+
});
|
|
2925
|
+
await settle();
|
|
2926
|
+
await expectRowInList(last, scroll);
|
|
2927
|
+
|
|
2928
|
+
await userEvent.keyboard('{Home}');
|
|
2929
|
+
const first = body.getByRole('menuitem', { name: 'Folder 1' });
|
|
2930
|
+
await waitFor(async () => {
|
|
2931
|
+
await expect(first).toHaveFocus();
|
|
2932
|
+
});
|
|
2933
|
+
await settle();
|
|
2934
|
+
await expectRowInList(first, scroll);
|
|
2935
|
+
},
|
|
2936
|
+
);
|
|
2937
|
+
|
|
2938
|
+
await step(
|
|
2939
|
+
'mobile: placing the submenu again on resize or a parent scroll keeps the last row in view',
|
|
2940
|
+
async () => {
|
|
2941
|
+
const submenu = body.getByRole('menu', { name: 'Move to' });
|
|
2942
|
+
const parent = body
|
|
2943
|
+
.getAllByRole('menu')
|
|
2944
|
+
.find((menu) => menu !== submenu) as HTMLElement;
|
|
2945
|
+
const { scroll } = getMobileViewport(submenu);
|
|
2946
|
+
const last = body.getByRole('menuitem', { name: 'Folder 12' });
|
|
2947
|
+
scroll.scrollTop = scroll.scrollHeight;
|
|
2948
|
+
await settle();
|
|
2949
|
+
await expectRowInList(last, scroll);
|
|
2950
|
+
|
|
2951
|
+
window.dispatchEvent(new Event('resize'));
|
|
2952
|
+
await settle();
|
|
2953
|
+
await expectRowInList(last, scroll);
|
|
2954
|
+
|
|
2955
|
+
getMobileViewport(parent).scroll.dispatchEvent(new Event('scroll'));
|
|
2956
|
+
await settle();
|
|
2957
|
+
await expectRowInList(last, scroll);
|
|
2958
|
+
},
|
|
2959
|
+
);
|
|
2960
|
+
} finally {
|
|
2961
|
+
restoreHeight?.();
|
|
2962
|
+
}
|
|
2963
|
+
},
|
|
2964
|
+
};
|
|
@@ -499,6 +499,140 @@ describe('UiDropdownMenuSub', () => {
|
|
|
499
499
|
restore();
|
|
500
500
|
}
|
|
501
501
|
});
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Gives the submenu's list a browser's scroll range, which jsdom lacks: 480px
|
|
505
|
+
* of rows in a box that is five 36px rows tall, or the capped height while
|
|
506
|
+
* the cap is set. Reading the panel's layout height clamps the scroll
|
|
507
|
+
* position to the range at that moment, as a browser's layout pass does.
|
|
508
|
+
* @param submenu The open submenu panel.
|
|
509
|
+
* @returns The submenu's scroll box.
|
|
510
|
+
*/
|
|
511
|
+
function stubScrollRange(submenu: HTMLElement) {
|
|
512
|
+
const scroll = submenu.querySelector<HTMLElement>(
|
|
513
|
+
'[data-slot="dropdown-menu-scroll"]',
|
|
514
|
+
) as HTMLElement;
|
|
515
|
+
const scrollHeight = 480;
|
|
516
|
+
const clientHeight = () =>
|
|
517
|
+
Number.parseFloat(
|
|
518
|
+
submenu.style.getPropertyValue(
|
|
519
|
+
'--ui-dropdown-submenu-scroll-max-height',
|
|
520
|
+
),
|
|
521
|
+
) || 36 * 5;
|
|
522
|
+
let position = 0;
|
|
523
|
+
const clamp = (value: number) =>
|
|
524
|
+
Math.min(Math.max(value, 0), scrollHeight - clientHeight());
|
|
525
|
+
Object.defineProperty(scroll, 'scrollTop', {
|
|
526
|
+
configurable: true,
|
|
527
|
+
get: () => position,
|
|
528
|
+
set: (value: number) => {
|
|
529
|
+
position = clamp(value);
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
Object.defineProperty(submenu, 'offsetHeight', {
|
|
533
|
+
configurable: true,
|
|
534
|
+
get: () => {
|
|
535
|
+
position = clamp(position);
|
|
536
|
+
return 190;
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
return scroll;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
test('keeps a capped submenu scrolled to its last row while its list scrolls', async () => {
|
|
543
|
+
const geometry = {
|
|
544
|
+
content: new DOMRect(0, 40, 320, 240),
|
|
545
|
+
subTrigger: new DOMRect(8, 142, 304, 36),
|
|
546
|
+
subContent: new DOMRect(0, 0, 320, 190),
|
|
547
|
+
innerHeight: 320,
|
|
548
|
+
};
|
|
549
|
+
const restore = stubMobileGeometry(geometry);
|
|
550
|
+
|
|
551
|
+
try {
|
|
552
|
+
const { submenu } = await openStackedSubmenu();
|
|
553
|
+
const scroll = stubScrollRange(submenu);
|
|
554
|
+
|
|
555
|
+
// The list is capped at 134px, so its end is at 480 - 134 = 346. With
|
|
556
|
+
// the cap lifted it would be 480 - 180 = 300.
|
|
557
|
+
scroll.scrollTop = 346;
|
|
558
|
+
scroll.dispatchEvent(new Event('scroll'));
|
|
559
|
+
expect(scroll.scrollTop).toBe(346);
|
|
560
|
+
|
|
561
|
+
// Its own scroll leaves the row where it was, so the placement stays.
|
|
562
|
+
geometry.subTrigger = new DOMRect(8, 120, 304, 36);
|
|
563
|
+
scroll.dispatchEvent(new Event('scroll'));
|
|
564
|
+
expect(submenu.style.getPropertyValue('--ui-dropdown-submenu-top')).toBe(
|
|
565
|
+
'0px',
|
|
566
|
+
);
|
|
567
|
+
} finally {
|
|
568
|
+
restore();
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test('ignores scrolls in panels that do not hold its row', async () => {
|
|
573
|
+
const geometry = {
|
|
574
|
+
content: new DOMRect(0, 40, 320, 240),
|
|
575
|
+
subTrigger: new DOMRect(8, 142, 304, 36),
|
|
576
|
+
subContent: new DOMRect(0, 0, 320, 190),
|
|
577
|
+
innerHeight: 320,
|
|
578
|
+
};
|
|
579
|
+
const restore = stubMobileGeometry(geometry);
|
|
580
|
+
// Another portalled panel, such as a sibling submenu.
|
|
581
|
+
const other = document.createElement('div');
|
|
582
|
+
document.body.append(other);
|
|
583
|
+
|
|
584
|
+
try {
|
|
585
|
+
const { submenu } = await openStackedSubmenu();
|
|
586
|
+
geometry.subTrigger = new DOMRect(8, 120, 304, 36);
|
|
587
|
+
other.dispatchEvent(new Event('scroll'));
|
|
588
|
+
expect(submenu.style.getPropertyValue('--ui-dropdown-submenu-top')).toBe(
|
|
589
|
+
'0px',
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
// The page scrolling does move the row, so the submenu follows it.
|
|
593
|
+
document.dispatchEvent(new Event('scroll'));
|
|
594
|
+
expect(submenu.style.getPropertyValue('--ui-dropdown-submenu-top')).toBe(
|
|
595
|
+
'164px',
|
|
596
|
+
);
|
|
597
|
+
} finally {
|
|
598
|
+
other.remove();
|
|
599
|
+
restore();
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test('keeps the submenu list where it was when the parent menu scrolls', async () => {
|
|
604
|
+
const geometry = {
|
|
605
|
+
content: new DOMRect(0, 40, 320, 240),
|
|
606
|
+
subTrigger: new DOMRect(8, 142, 304, 36),
|
|
607
|
+
subContent: new DOMRect(0, 0, 320, 190),
|
|
608
|
+
innerHeight: 320,
|
|
609
|
+
};
|
|
610
|
+
const restore = stubMobileGeometry(geometry);
|
|
611
|
+
|
|
612
|
+
try {
|
|
613
|
+
const { submenu } = await openStackedSubmenu();
|
|
614
|
+
const scroll = stubScrollRange(submenu);
|
|
615
|
+
// Past 300, where the list could not be with the cap lifted.
|
|
616
|
+
scroll.scrollTop = 320;
|
|
617
|
+
|
|
618
|
+
// The parent list scrolls the row 10px down: the submenu follows it with
|
|
619
|
+
// 10px more room above, and its list keeps its place.
|
|
620
|
+
geometry.subTrigger = new DOMRect(8, 152, 304, 36);
|
|
621
|
+
const parent = document.querySelector<HTMLElement>(
|
|
622
|
+
'[data-slot="dropdown-menu-content"]',
|
|
623
|
+
) as HTMLElement;
|
|
624
|
+
parent.dispatchEvent(new Event('scroll'));
|
|
625
|
+
|
|
626
|
+
expect(
|
|
627
|
+
submenu.style.getPropertyValue(
|
|
628
|
+
'--ui-dropdown-submenu-scroll-max-height',
|
|
629
|
+
),
|
|
630
|
+
).toBe('144px');
|
|
631
|
+
expect(scroll.scrollTop).toBe(320);
|
|
632
|
+
} finally {
|
|
633
|
+
restore();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
502
636
|
});
|
|
503
637
|
|
|
504
638
|
describe('UiDropdownMenuContent', () => {
|