@aleph-alpha/ui-library 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.d.ts +9 -0
- package/config.js +12 -3
- package/dist/system/lib.js +6461 -6397
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +5 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +1 -0
- package/src/components/UiButton/UiButton.stories.ts +9 -9
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiField/UiField.stories.ts +608 -1
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/core/checkbox/Checkbox.vue +0 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
-
import {
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
3
|
+
import { reactive, ref, useId } from 'vue';
|
|
3
4
|
import UiFloatActions from './UiFloatActions.vue';
|
|
4
5
|
import { UiFloatActionItems } from './index';
|
|
5
6
|
import { UiIcon } from '../../components/UiIcon';
|
|
6
7
|
import { UiTooltip } from '../../components/UiTooltip';
|
|
7
8
|
import { UiSwitch } from '../../components/UiSwitch';
|
|
9
|
+
import { UiCheckbox } from '../../components/UiCheckbox';
|
|
8
10
|
import { useAnchorFloat } from '../../lib/useAnchorFloat';
|
|
9
11
|
import type { UiFloatActionsPlacement, UiFloatActionsTrigger } from './types';
|
|
10
12
|
|
|
@@ -90,6 +92,11 @@ const meta = {
|
|
|
90
92
|
export default meta;
|
|
91
93
|
type Story = StoryObj<typeof meta>;
|
|
92
94
|
|
|
95
|
+
// A `UiFloatActionItems` button emits a native-style `click`. Play functions that
|
|
96
|
+
// assert the emit bind this module-level spy via `@click` and `mockClear()` it
|
|
97
|
+
// first (passing `onClick` through `args` wouldn't type-check).
|
|
98
|
+
const onItemClick = fn();
|
|
99
|
+
|
|
93
100
|
/**
|
|
94
101
|
* Trigger modes: `hover`, `click`, `focus`, and `manual`.
|
|
95
102
|
* Each anchor renders as a focusable button, so keyboard users get the same
|
|
@@ -102,6 +109,9 @@ export const ShowModes: Story = {
|
|
|
102
109
|
components: { UiFloatActions, UiFloatActionItems, UiIcon, UiSwitch },
|
|
103
110
|
setup() {
|
|
104
111
|
const manualOpen = ref(false);
|
|
112
|
+
// `v-model` turns a toolbar into a single-select control: the active item
|
|
113
|
+
// gets the sliding background indicator.
|
|
114
|
+
const view = ref('grid');
|
|
105
115
|
const modes = [
|
|
106
116
|
{
|
|
107
117
|
trigger: 'hover' as const,
|
|
@@ -128,10 +138,11 @@ export const ShowModes: Story = {
|
|
|
128
138
|
icon: 'star',
|
|
129
139
|
},
|
|
130
140
|
];
|
|
131
|
-
return { modes, manualOpen };
|
|
141
|
+
return { modes, manualOpen, view };
|
|
132
142
|
},
|
|
133
143
|
template: `
|
|
134
|
-
<div class="
|
|
144
|
+
<div class="flex min-h-96 flex-col items-center gap-10 p-8">
|
|
145
|
+
<div class="grid w-full grid-cols-1 place-items-center gap-10 md:grid-cols-2">
|
|
135
146
|
<div
|
|
136
147
|
v-for="mode in modes"
|
|
137
148
|
:key="mode.trigger"
|
|
@@ -170,6 +181,60 @@ export const ShowModes: Story = {
|
|
|
170
181
|
</label>
|
|
171
182
|
</div>
|
|
172
183
|
</div>
|
|
184
|
+
|
|
185
|
+
<div class="grid w-full grid-cols-1 place-items-center gap-10 md:grid-cols-2">
|
|
186
|
+
<!-- Clickable: stateless action buttons revealed on hover -->
|
|
187
|
+
<div class="flex flex-col items-center gap-3">
|
|
188
|
+
<span class="label-14-medium text-content-on-surface-secondary">Clickable</span>
|
|
189
|
+
<UiFloatActions trigger="hover" placement="top" :offset="10" aria-label="Clickable actions">
|
|
190
|
+
<template #container>
|
|
191
|
+
<span class="rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-2 body-14-regular">
|
|
192
|
+
Hover to reveal actions
|
|
193
|
+
</span>
|
|
194
|
+
</template>
|
|
195
|
+
<template #action>
|
|
196
|
+
<UiFloatActionItems aria-label="Clickable actions">
|
|
197
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
198
|
+
<UiIcon name="edit" size="s" />
|
|
199
|
+
</UiFloatActionItems>
|
|
200
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
201
|
+
<UiIcon name="copy" size="s" />
|
|
202
|
+
</UiFloatActionItems>
|
|
203
|
+
<UiFloatActionItems type="button" aria-label="Delete">
|
|
204
|
+
<UiIcon name="trash" size="s" />
|
|
205
|
+
</UiFloatActionItems>
|
|
206
|
+
</UiFloatActionItems>
|
|
207
|
+
</template>
|
|
208
|
+
</UiFloatActions>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- Selectable (v-model): single-select with the sliding indicator, revealed on hover -->
|
|
212
|
+
<div class="flex flex-col items-center gap-3">
|
|
213
|
+
<span class="label-14-medium text-content-on-surface-secondary">Selectable (v-model)</span>
|
|
214
|
+
<UiFloatActions trigger="hover" placement="top" :offset="10" aria-label="Selectable view mode">
|
|
215
|
+
<template #container>
|
|
216
|
+
<span class="rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-2 body-14-regular">
|
|
217
|
+
Hover to reveal view modes
|
|
218
|
+
</span>
|
|
219
|
+
</template>
|
|
220
|
+
<template #action>
|
|
221
|
+
<UiFloatActionItems v-model="view" aria-label="View mode">
|
|
222
|
+
<UiFloatActionItems type="button" value="grid" aria-label="Grid" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
223
|
+
<UiIcon name="layout-grid" size="s" />Grid
|
|
224
|
+
</UiFloatActionItems>
|
|
225
|
+
<UiFloatActionItems type="button" value="list" aria-label="List" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
226
|
+
<UiIcon name="list" size="s" />List
|
|
227
|
+
</UiFloatActionItems>
|
|
228
|
+
<UiFloatActionItems type="button" value="table" aria-label="Table" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
229
|
+
<UiIcon name="table" size="s" />Table
|
|
230
|
+
</UiFloatActionItems>
|
|
231
|
+
</UiFloatActionItems>
|
|
232
|
+
</template>
|
|
233
|
+
</UiFloatActions>
|
|
234
|
+
<span class="label-12-regular text-content-on-surface-muted">Selected: {{ view }}</span>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
173
238
|
`,
|
|
174
239
|
}),
|
|
175
240
|
parameters: {
|
|
@@ -178,6 +243,184 @@ export const ShowModes: Story = {
|
|
|
178
243
|
},
|
|
179
244
|
};
|
|
180
245
|
|
|
246
|
+
/**
|
|
247
|
+
* A gallery of common `UiFloatActionItems` toolbar compositions.
|
|
248
|
+
* These are **examples** only — mix and match the item types (`button`, `text`,
|
|
249
|
+
* `input`, `separator`, `group`) and `orientation` to build your own toolbars.
|
|
250
|
+
*/
|
|
251
|
+
export const Examples: Story = {
|
|
252
|
+
name: 'Item examples',
|
|
253
|
+
render: () => ({
|
|
254
|
+
components: { UiFloatActionItems, UiIcon, UiCheckbox },
|
|
255
|
+
setup() {
|
|
256
|
+
// Toggle to turn the labelled (icon + text / text) toolbars into `v-model`
|
|
257
|
+
// single-select controls — each active item then shows the sliding
|
|
258
|
+
// background indicator. Icon-only and input toolbars stay stateless.
|
|
259
|
+
const withModel = ref(true);
|
|
260
|
+
const selection = reactive({
|
|
261
|
+
labels: 'fullscreen',
|
|
262
|
+
text: 'fullscreen',
|
|
263
|
+
vLabels: 'fullscreen',
|
|
264
|
+
vText: 'fullscreen',
|
|
265
|
+
});
|
|
266
|
+
return { withModel, selection };
|
|
267
|
+
},
|
|
268
|
+
template: `
|
|
269
|
+
<div class="flex min-h-96 flex-col items-center gap-8 p-8">
|
|
270
|
+
<p class="max-w-md text-center body-14-regular text-content-on-surface-secondary">
|
|
271
|
+
These are examples — combine the item types and orientation to compose your own toolbars.
|
|
272
|
+
</p>
|
|
273
|
+
|
|
274
|
+
<label class="flex items-center gap-2 label-14-medium text-content-on-surface-secondary">
|
|
275
|
+
<UiCheckbox name="examples-with-model" v-model="withModel" />
|
|
276
|
+
Enable v-model (active indicator)
|
|
277
|
+
</label>
|
|
278
|
+
|
|
279
|
+
<div class="grid grid-cols-[auto_1fr] items-center gap-x-6 gap-y-8">
|
|
280
|
+
<!-- Labelled toolbars (icon + text / text) support v-model in every orientation -->
|
|
281
|
+
<!-- Icon + text buttons -->
|
|
282
|
+
<UiFloatActionItems
|
|
283
|
+
aria-label="View options with labels"
|
|
284
|
+
class="justify-self-center"
|
|
285
|
+
:model-value="withModel ? selection.labels : undefined"
|
|
286
|
+
@update:model-value="selection.labels = $event"
|
|
287
|
+
>
|
|
288
|
+
<UiFloatActionItems type="button" value="fullscreen" aria-label="Fullscreen" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
289
|
+
<UiIcon name="maximize" size="s" />Fullscreen
|
|
290
|
+
</UiFloatActionItems>
|
|
291
|
+
<UiFloatActionItems type="button" value="sidebar" aria-label="Sidebar" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
292
|
+
<UiIcon name="panel-left" size="s" />Sidebar
|
|
293
|
+
</UiFloatActionItems>
|
|
294
|
+
<UiFloatActionItems type="button" value="dashboard" aria-label="Dashboard" class="w-auto gap-1.5 px-3 label-14-medium">
|
|
295
|
+
<UiIcon name="layout-grid" size="s" />Dashboard
|
|
296
|
+
</UiFloatActionItems>
|
|
297
|
+
</UiFloatActionItems>
|
|
298
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (icon + text)</span>
|
|
299
|
+
|
|
300
|
+
<!-- Text-only buttons -->
|
|
301
|
+
<UiFloatActionItems
|
|
302
|
+
aria-label="View options"
|
|
303
|
+
class="justify-self-center"
|
|
304
|
+
:model-value="withModel ? selection.text : undefined"
|
|
305
|
+
@update:model-value="selection.text = $event"
|
|
306
|
+
>
|
|
307
|
+
<UiFloatActionItems type="button" value="fullscreen" aria-label="Fullscreen" class="w-auto px-3 label-14-medium">
|
|
308
|
+
Fullscreen
|
|
309
|
+
</UiFloatActionItems>
|
|
310
|
+
<UiFloatActionItems type="button" value="sidebar" aria-label="Sidebar" class="w-auto px-3 label-14-medium">
|
|
311
|
+
Sidebar
|
|
312
|
+
</UiFloatActionItems>
|
|
313
|
+
<UiFloatActionItems type="button" value="dashboard" aria-label="Dashboard" class="w-auto px-3 label-14-medium">
|
|
314
|
+
Dashboard
|
|
315
|
+
</UiFloatActionItems>
|
|
316
|
+
</UiFloatActionItems>
|
|
317
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (text)</span>
|
|
318
|
+
|
|
319
|
+
<!-- Vertical with icon + text -->
|
|
320
|
+
<UiFloatActionItems
|
|
321
|
+
aria-label="Vertical view options with labels"
|
|
322
|
+
orientation="vertical"
|
|
323
|
+
class="justify-self-center"
|
|
324
|
+
:model-value="withModel ? selection.vLabels : undefined"
|
|
325
|
+
@update:model-value="selection.vLabels = $event"
|
|
326
|
+
>
|
|
327
|
+
<UiFloatActionItems type="button" value="fullscreen" aria-label="Fullscreen" class="w-full justify-start gap-1.5 px-3 label-14-medium">
|
|
328
|
+
<UiIcon name="maximize" size="s" />Fullscreen
|
|
329
|
+
</UiFloatActionItems>
|
|
330
|
+
<UiFloatActionItems type="button" value="sidebar" aria-label="Sidebar" class="w-full justify-start gap-1.5 px-3 label-14-medium">
|
|
331
|
+
<UiIcon name="panel-left" size="s" />Sidebar
|
|
332
|
+
</UiFloatActionItems>
|
|
333
|
+
<UiFloatActionItems type="button" value="dashboard" aria-label="Dashboard" class="w-full justify-start gap-1.5 px-3 label-14-medium">
|
|
334
|
+
<UiIcon name="layout-grid" size="s" />Dashboard
|
|
335
|
+
</UiFloatActionItems>
|
|
336
|
+
</UiFloatActionItems>
|
|
337
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (icon + text) · vertical</span>
|
|
338
|
+
|
|
339
|
+
<!-- Vertical text only -->
|
|
340
|
+
<UiFloatActionItems
|
|
341
|
+
aria-label="Vertical view options"
|
|
342
|
+
orientation="vertical"
|
|
343
|
+
class="justify-self-center"
|
|
344
|
+
:model-value="withModel ? selection.vText : undefined"
|
|
345
|
+
@update:model-value="selection.vText = $event"
|
|
346
|
+
>
|
|
347
|
+
<UiFloatActionItems type="button" value="fullscreen" aria-label="Fullscreen" class="w-full justify-start px-3 label-14-medium">
|
|
348
|
+
Fullscreen
|
|
349
|
+
</UiFloatActionItems>
|
|
350
|
+
<UiFloatActionItems type="button" value="sidebar" aria-label="Sidebar" class="w-full justify-start px-3 label-14-medium">
|
|
351
|
+
Sidebar
|
|
352
|
+
</UiFloatActionItems>
|
|
353
|
+
<UiFloatActionItems type="button" value="dashboard" aria-label="Dashboard" class="w-full justify-start px-3 label-14-medium">
|
|
354
|
+
Dashboard
|
|
355
|
+
</UiFloatActionItems>
|
|
356
|
+
</UiFloatActionItems>
|
|
357
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (text) · vertical</span>
|
|
358
|
+
|
|
359
|
+
<!-- Stateless toolbars (icon-only and inputs) — no v-model -->
|
|
360
|
+
<!-- Icon-only buttons -->
|
|
361
|
+
<UiFloatActionItems aria-label="View options icons" class="justify-self-center">
|
|
362
|
+
<UiFloatActionItems type="button" aria-label="Fullscreen">
|
|
363
|
+
<UiIcon name="maximize" size="s" />
|
|
364
|
+
</UiFloatActionItems>
|
|
365
|
+
<UiFloatActionItems type="button" aria-label="Sidebar">
|
|
366
|
+
<UiIcon name="panel-left" size="s" />
|
|
367
|
+
</UiFloatActionItems>
|
|
368
|
+
<UiFloatActionItems type="button" aria-label="Dashboard">
|
|
369
|
+
<UiIcon name="layout-grid" size="s" />
|
|
370
|
+
</UiFloatActionItems>
|
|
371
|
+
</UiFloatActionItems>
|
|
372
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (icon only)</span>
|
|
373
|
+
|
|
374
|
+
<!-- Icon-only buttons (edit actions) -->
|
|
375
|
+
<UiFloatActionItems aria-label="Edit actions" class="justify-self-center">
|
|
376
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
377
|
+
<UiIcon name="edit" size="s" />
|
|
378
|
+
</UiFloatActionItems>
|
|
379
|
+
<UiFloatActionItems type="button" aria-label="Delete">
|
|
380
|
+
<UiIcon name="trash" size="s" />
|
|
381
|
+
</UiFloatActionItems>
|
|
382
|
+
</UiFloatActionItems>
|
|
383
|
+
<span class="label-14-regular text-content-on-surface-secondary">button (icon only)</span>
|
|
384
|
+
|
|
385
|
+
<!-- With input (pagination) -->
|
|
386
|
+
<UiFloatActionItems aria-label="Pagination" class="justify-self-center">
|
|
387
|
+
<UiFloatActionItems type="button" aria-label="Previous page">
|
|
388
|
+
<UiIcon name="chevron-left" size="s" />
|
|
389
|
+
</UiFloatActionItems>
|
|
390
|
+
<UiFloatActionItems type="input" aria-label="Page number" placeholder="0/0" class="w-14 text-center" />
|
|
391
|
+
<UiFloatActionItems type="button" aria-label="Next page">
|
|
392
|
+
<UiIcon name="chevron-right" size="s" />
|
|
393
|
+
</UiFloatActionItems>
|
|
394
|
+
</UiFloatActionItems>
|
|
395
|
+
<span class="label-14-regular text-content-on-surface-secondary">button + input + button</span>
|
|
396
|
+
|
|
397
|
+
<!-- With input (zoom level) -->
|
|
398
|
+
<UiFloatActionItems aria-label="Zoom" class="justify-self-center">
|
|
399
|
+
<UiFloatActionItems type="button" aria-label="Zoom out">
|
|
400
|
+
<UiIcon name="minus" size="s" />
|
|
401
|
+
</UiFloatActionItems>
|
|
402
|
+
<UiFloatActionItems type="input" aria-label="Zoom level" placeholder="100%" class="w-16 text-center" />
|
|
403
|
+
<UiFloatActionItems type="button" aria-label="Zoom in">
|
|
404
|
+
<UiIcon name="plus" size="s" />
|
|
405
|
+
</UiFloatActionItems>
|
|
406
|
+
</UiFloatActionItems>
|
|
407
|
+
<span class="label-14-regular text-content-on-surface-secondary">button + input + button</span>
|
|
408
|
+
</div>
|
|
409
|
+
</div>
|
|
410
|
+
`,
|
|
411
|
+
}),
|
|
412
|
+
parameters: {
|
|
413
|
+
controls: { disable: true },
|
|
414
|
+
docs: {
|
|
415
|
+
canvas: { sourceState: 'none' },
|
|
416
|
+
description: {
|
|
417
|
+
story:
|
|
418
|
+
'Example toolbars grouped by kind: the labelled variants (icon + text and text only, in both orientations) support v-model — toggle "Enable v-model" to give them a sliding active indicator. Below them, the stateless icon-only and input toolbars (edit actions, pagination, zoom) stay plain. These are examples — adapt them to your use case.',
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
|
|
181
424
|
const iconOnlyWithTooltipSource = `<script setup lang="ts">
|
|
182
425
|
import { UiFloatActions, UiFloatActionItems, UiIcon, UiTooltip } from '@aleph-alpha/ui-library';
|
|
183
426
|
</script>
|
|
@@ -423,6 +666,24 @@ export const Orientation: Story = {
|
|
|
423
666
|
controls: { disable: true },
|
|
424
667
|
docs: { source: { code: orientationSource } },
|
|
425
668
|
},
|
|
669
|
+
play: async ({ canvasElement, step }) => {
|
|
670
|
+
// Scenario (UiFloatActionItems): orientation is announced via
|
|
671
|
+
// `aria-orientation` so assistive tech knows which Arrow keys move between
|
|
672
|
+
// items. These checks don't move focus, so the visual snapshot stays stable.
|
|
673
|
+
const canvas = within(canvasElement);
|
|
674
|
+
|
|
675
|
+
await step(
|
|
676
|
+
'screen-reader: each toolbar announces its orientation via aria-orientation (WCAG 1.3.1)',
|
|
677
|
+
async () => {
|
|
678
|
+
await expect(
|
|
679
|
+
canvas.getByRole('toolbar', { name: 'Horizontal actions' }),
|
|
680
|
+
).toHaveAttribute('aria-orientation', 'horizontal');
|
|
681
|
+
await expect(
|
|
682
|
+
canvas.getByRole('toolbar', { name: 'Vertical actions' }),
|
|
683
|
+
).toHaveAttribute('aria-orientation', 'vertical');
|
|
684
|
+
},
|
|
685
|
+
);
|
|
686
|
+
},
|
|
426
687
|
};
|
|
427
688
|
|
|
428
689
|
const itemTypesSource = `<script setup lang="ts">
|
|
@@ -499,6 +760,36 @@ export const ItemTypes: Story = {
|
|
|
499
760
|
controls: { disable: true },
|
|
500
761
|
docs: { source: { code: itemTypesSource } },
|
|
501
762
|
},
|
|
763
|
+
play: async ({ canvasElement, step }) => {
|
|
764
|
+
// Scenario (UiFloatActionItems): every item type is exposed with the right
|
|
765
|
+
// role and accessible name so assistive tech can describe the toolbar. These
|
|
766
|
+
// checks don't move focus or mutate state, so the snapshot stays stable.
|
|
767
|
+
const canvas = within(canvasElement);
|
|
768
|
+
const toolbar = canvas.getByRole('toolbar', { name: 'All item types' });
|
|
769
|
+
|
|
770
|
+
await step(
|
|
771
|
+
'screen-reader: the toolbar and its nested items expose roles and accessible names (WCAG 4.1.2)',
|
|
772
|
+
async () => {
|
|
773
|
+
await expect(toolbar).toBeInTheDocument();
|
|
774
|
+
await expect(canvas.getByRole('group')).toBeInTheDocument();
|
|
775
|
+
await expect(
|
|
776
|
+
canvas.getByRole('button', { name: 'Previous page' }),
|
|
777
|
+
).toBeInTheDocument();
|
|
778
|
+
await expect(
|
|
779
|
+
canvas.getByRole('textbox', { name: 'Filter value' }),
|
|
780
|
+
).toBeInTheDocument();
|
|
781
|
+
},
|
|
782
|
+
);
|
|
783
|
+
|
|
784
|
+
await step(
|
|
785
|
+
'interaction: renders each supported item type (button, group, text, input, separator)',
|
|
786
|
+
async () => {
|
|
787
|
+
await expect(canvas.getAllByRole('button')).toHaveLength(4);
|
|
788
|
+
await expect(canvas.getAllByRole('separator')).toHaveLength(2);
|
|
789
|
+
await expect(within(toolbar).getByText('2/2')).toBeInTheDocument();
|
|
790
|
+
},
|
|
791
|
+
);
|
|
792
|
+
},
|
|
502
793
|
};
|
|
503
794
|
|
|
504
795
|
/**
|
|
@@ -804,3 +1095,599 @@ export const Composable: Story = {
|
|
|
804
1095
|
docs: { source: { code: composableUsageSource } },
|
|
805
1096
|
},
|
|
806
1097
|
};
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Accessibility guidance for the floating trigger and its toolbar: popup
|
|
1101
|
+
* semantics on the anchor, roving arrow-key focus in the toolbar, accessible
|
|
1102
|
+
* names on every item, and the accessibility theme for contrast.
|
|
1103
|
+
*/
|
|
1104
|
+
export const Accessibility: Story = {
|
|
1105
|
+
render: () => ({
|
|
1106
|
+
components: { UiFloatActionItems, UiIcon },
|
|
1107
|
+
template: `
|
|
1108
|
+
<section class="flex flex-col gap-6 p-4">
|
|
1109
|
+
<div>
|
|
1110
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
1111
|
+
Accessibility
|
|
1112
|
+
</h2>
|
|
1113
|
+
</div>
|
|
1114
|
+
|
|
1115
|
+
<div class="flex flex-col gap-6">
|
|
1116
|
+
<div class="flex flex-col gap-2">
|
|
1117
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1118
|
+
Requirements
|
|
1119
|
+
</h3>
|
|
1120
|
+
<ul class="body-16-regular list-disc pl-5 text-content-on-surface-primary">
|
|
1121
|
+
<li>The trigger is a focusable button exposing <code class="label-14-regular">aria-haspopup</code> and <code class="label-14-regular">aria-expanded</code>, pointing at the open panel via <code class="label-14-regular">aria-controls</code>.</li>
|
|
1122
|
+
<li>Focus or hover opens the panel; <code class="label-14-regular">Escape</code> closes it and restores focus to the trigger.</li>
|
|
1123
|
+
<li>The toolbar uses <code class="label-14-regular">role="toolbar"</code> with roving arrow-key focus — one Tab stop enters and leaves it, Arrow keys move between items.</li>
|
|
1124
|
+
<li>Every icon-only button and input item has an accessible name via <code class="label-14-regular">aria-label</code>.</li>
|
|
1125
|
+
</ul>
|
|
1126
|
+
</div>
|
|
1127
|
+
|
|
1128
|
+
<div class="flex flex-col gap-2">
|
|
1129
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1130
|
+
Enable accessibility theme
|
|
1131
|
+
</h3>
|
|
1132
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
1133
|
+
When accessibility is required, enable our accessibility theme. This
|
|
1134
|
+
increases contrast and ensures there are no color contrast issues.
|
|
1135
|
+
</p>
|
|
1136
|
+
</div>
|
|
1137
|
+
</div>
|
|
1138
|
+
|
|
1139
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
1140
|
+
<div class="flex flex-col gap-3">
|
|
1141
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
1142
|
+
Default
|
|
1143
|
+
</h3>
|
|
1144
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
1145
|
+
<UiFloatActionItems aria-label="Default paragraph actions">
|
|
1146
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
1147
|
+
<UiIcon name="edit" size="s" />
|
|
1148
|
+
</UiFloatActionItems>
|
|
1149
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1150
|
+
<UiIcon name="copy" size="s" />
|
|
1151
|
+
</UiFloatActionItems>
|
|
1152
|
+
<UiFloatActionItems type="separator" />
|
|
1153
|
+
<UiFloatActionItems type="button" aria-label="Delete">
|
|
1154
|
+
<UiIcon name="trash" size="s" />
|
|
1155
|
+
</UiFloatActionItems>
|
|
1156
|
+
</UiFloatActionItems>
|
|
1157
|
+
</div>
|
|
1158
|
+
</div>
|
|
1159
|
+
|
|
1160
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
1161
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
1162
|
+
Accessible
|
|
1163
|
+
</h3>
|
|
1164
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
1165
|
+
<UiFloatActionItems aria-label="Accessible paragraph actions">
|
|
1166
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
1167
|
+
<UiIcon name="edit" size="s" />
|
|
1168
|
+
</UiFloatActionItems>
|
|
1169
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1170
|
+
<UiIcon name="copy" size="s" />
|
|
1171
|
+
</UiFloatActionItems>
|
|
1172
|
+
<UiFloatActionItems type="separator" />
|
|
1173
|
+
<UiFloatActionItems type="button" aria-label="Delete">
|
|
1174
|
+
<UiIcon name="trash" size="s" />
|
|
1175
|
+
</UiFloatActionItems>
|
|
1176
|
+
</UiFloatActionItems>
|
|
1177
|
+
</div>
|
|
1178
|
+
</div>
|
|
1179
|
+
</div>
|
|
1180
|
+
</section>
|
|
1181
|
+
`,
|
|
1182
|
+
}),
|
|
1183
|
+
tags: ['!autodocs'],
|
|
1184
|
+
parameters: {
|
|
1185
|
+
a11y: { test: 'off' },
|
|
1186
|
+
chromatic: {
|
|
1187
|
+
disableSnapshot: true,
|
|
1188
|
+
},
|
|
1189
|
+
docs: {
|
|
1190
|
+
canvas: {
|
|
1191
|
+
sourceState: 'none',
|
|
1192
|
+
},
|
|
1193
|
+
},
|
|
1194
|
+
},
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
/*
|
|
1198
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
1199
|
+
* Interaction & accessibility tests (play functions)
|
|
1200
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
1201
|
+
* How these tests are built and reported:
|
|
1202
|
+
*
|
|
1203
|
+
* - Each story below is a hidden, test-only story (`name: 'test - …'`,
|
|
1204
|
+
* `tags: ['!dev', '!autodocs']`). It is excluded from the sidebar and docs but
|
|
1205
|
+
* still runs in the Storybook `test-runner` on every PR, in the accessible
|
|
1206
|
+
* theme, alongside the axe audit.
|
|
1207
|
+
* - Every play opens with a `Scenario (Component): …` comment stating the user
|
|
1208
|
+
* story it verifies, then drives the UI with `userEvent` and asserts with
|
|
1209
|
+
* `expect` from `storybook/test`.
|
|
1210
|
+
* - Assertions are grouped into category-labelled `step()` calls. The prefix is
|
|
1211
|
+
* the contract for reporting — it is parsed statically into the per-story
|
|
1212
|
+
* summary table and the scenarios PDF (`pnpm report:scenarios-pdf`), so keep
|
|
1213
|
+
* it accurate. Between them, these stories cover every report column:
|
|
1214
|
+
* • `interaction:` behaviour, guards, emitted events (WCAG 4.1.2)
|
|
1215
|
+
* • `keyboard:` Tab order, Enter / Space / Arrow / Escape (WCAG 2.1.1, 2.4.3)
|
|
1216
|
+
* • `screen-reader:` accessible names, roles, ARIA state (WCAG 4.1.2)
|
|
1217
|
+
* • `zoom:` usable at 200% page zoom (WCAG 1.4.4)
|
|
1218
|
+
* • `mobile:` 320px reflow + touch-target size (WCAG 1.4.10, 2.5.8)
|
|
1219
|
+
* The Accessibility column is filled automatically by the axe audit that runs
|
|
1220
|
+
* on every story — never add an `a11y:` prefix.
|
|
1221
|
+
* - Coverage is split across stories: non-mutating `screen-reader`/`interaction`
|
|
1222
|
+
* checks are co-located on the visible `Orientation` and `ItemTypes` stories
|
|
1223
|
+
* (so their Chromatic snapshots stay valid), while focus-moving flows live in
|
|
1224
|
+
* the dedicated `test - …` stories below (Focus / Hover / Click / Toolbar /
|
|
1225
|
+
* Zoom / Mobile).
|
|
1226
|
+
* - The floating panel is teleported to `document.body`, so panel content is
|
|
1227
|
+
* queried with `within(document.body)` rather than the story canvas.
|
|
1228
|
+
* - Stories whose play moves focus, opens the panel, or rescales the layout
|
|
1229
|
+
* disable their Chromatic snapshot. Pure render/logic coverage lives in Vitest
|
|
1230
|
+
* under `__tests__/`.
|
|
1231
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
1232
|
+
*/
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* A `focus` trigger opens the panel when the anchor receives keyboard focus and
|
|
1236
|
+
* exposes popup semantics; `Escape` closes it and restores focus to the anchor.
|
|
1237
|
+
* Hidden test-only story.
|
|
1238
|
+
*/
|
|
1239
|
+
export const FocusTriggerKeyboard: Story = {
|
|
1240
|
+
name: 'test - Focus trigger & escape',
|
|
1241
|
+
tags: ['!dev', '!autodocs'],
|
|
1242
|
+
render: () => ({
|
|
1243
|
+
components: { UiFloatActions, UiFloatActionItems, UiIcon },
|
|
1244
|
+
template: `
|
|
1245
|
+
<div class="flex min-h-64 items-center justify-center p-8">
|
|
1246
|
+
<UiFloatActions trigger="focus" placement="top" :offset="10" aria-label="Paragraph actions">
|
|
1247
|
+
<template #container>
|
|
1248
|
+
<span class="rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-2 body-14-regular">
|
|
1249
|
+
Tab to reveal actions
|
|
1250
|
+
</span>
|
|
1251
|
+
</template>
|
|
1252
|
+
<template #action>
|
|
1253
|
+
<UiFloatActionItems aria-label="Paragraph actions">
|
|
1254
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
1255
|
+
<UiIcon name="edit" size="s" />
|
|
1256
|
+
</UiFloatActionItems>
|
|
1257
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1258
|
+
<UiIcon name="copy" size="s" />
|
|
1259
|
+
</UiFloatActionItems>
|
|
1260
|
+
</UiFloatActionItems>
|
|
1261
|
+
</template>
|
|
1262
|
+
</UiFloatActions>
|
|
1263
|
+
</div>
|
|
1264
|
+
`,
|
|
1265
|
+
}),
|
|
1266
|
+
parameters: {
|
|
1267
|
+
// The play function moves focus and opens the teleported panel; skip the
|
|
1268
|
+
// snapshot so the focus ring and open panel don't register as a diff.
|
|
1269
|
+
chromatic: { disableSnapshot: true },
|
|
1270
|
+
docs: {
|
|
1271
|
+
description: {
|
|
1272
|
+
story:
|
|
1273
|
+
'Press `Tab` to focus the anchor and open the panel, then `Escape` to close it and restore focus.',
|
|
1274
|
+
},
|
|
1275
|
+
},
|
|
1276
|
+
},
|
|
1277
|
+
play: async ({ canvasElement, step }) => {
|
|
1278
|
+
// Scenario (UiFloatActions): a keyboard user Tabs to a `focus`-trigger
|
|
1279
|
+
// anchor, which opens the panel and exposes popup semantics (aria-haspopup /
|
|
1280
|
+
// aria-expanded / aria-controls); Escape then closes it and returns focus to
|
|
1281
|
+
// the anchor. The panel is teleported to `document.body`, so its content is
|
|
1282
|
+
// queried against the body rather than the story canvas.
|
|
1283
|
+
const canvas = within(canvasElement);
|
|
1284
|
+
const body = within(document.body);
|
|
1285
|
+
const anchor = canvas.getByRole('button', { name: 'Paragraph actions' });
|
|
1286
|
+
|
|
1287
|
+
await step(
|
|
1288
|
+
'screen-reader: the collapsed trigger exposes popup semantics (WCAG 4.1.2)',
|
|
1289
|
+
async () => {
|
|
1290
|
+
await expect(anchor).toHaveAttribute('aria-haspopup', 'true');
|
|
1291
|
+
await expect(anchor).toHaveAttribute('aria-expanded', 'false');
|
|
1292
|
+
},
|
|
1293
|
+
);
|
|
1294
|
+
|
|
1295
|
+
await step(
|
|
1296
|
+
'keyboard: focusing the trigger opens the panel and links it via aria-controls (WCAG 2.1.1 / 4.1.2)',
|
|
1297
|
+
async () => {
|
|
1298
|
+
await userEvent.tab();
|
|
1299
|
+
await expect(anchor).toHaveFocus();
|
|
1300
|
+
await waitFor(() =>
|
|
1301
|
+
expect(anchor).toHaveAttribute('aria-expanded', 'true'),
|
|
1302
|
+
);
|
|
1303
|
+
await expect(anchor).toHaveAttribute('aria-controls');
|
|
1304
|
+
await expect(
|
|
1305
|
+
await body.findByRole('toolbar', { name: 'Paragraph actions' }),
|
|
1306
|
+
).toBeInTheDocument();
|
|
1307
|
+
},
|
|
1308
|
+
);
|
|
1309
|
+
|
|
1310
|
+
await step(
|
|
1311
|
+
'keyboard: Escape closes the panel and restores focus to the trigger (WCAG 2.1.2)',
|
|
1312
|
+
async () => {
|
|
1313
|
+
await userEvent.keyboard('{Escape}');
|
|
1314
|
+
await waitFor(() =>
|
|
1315
|
+
expect(anchor).toHaveAttribute('aria-expanded', 'false'),
|
|
1316
|
+
);
|
|
1317
|
+
await expect(anchor).toHaveFocus();
|
|
1318
|
+
await waitFor(() =>
|
|
1319
|
+
expect(
|
|
1320
|
+
body.queryByRole('toolbar', { name: 'Paragraph actions' }),
|
|
1321
|
+
).not.toBeInTheDocument(),
|
|
1322
|
+
);
|
|
1323
|
+
},
|
|
1324
|
+
);
|
|
1325
|
+
},
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* A `hover` trigger also opens on keyboard focus, so keyboard-only users reach
|
|
1330
|
+
* the same actions as pointer users. Hidden test-only story.
|
|
1331
|
+
*/
|
|
1332
|
+
export const HoverTriggerKeyboard: Story = {
|
|
1333
|
+
name: 'test - Hover trigger keyboard',
|
|
1334
|
+
tags: ['!dev', '!autodocs'],
|
|
1335
|
+
render: () => ({
|
|
1336
|
+
components: { UiFloatActions, UiFloatActionItems, UiIcon },
|
|
1337
|
+
template: `
|
|
1338
|
+
<div class="flex min-h-64 items-center justify-center p-8">
|
|
1339
|
+
<UiFloatActions trigger="hover" placement="top" :offset="10" aria-label="Text actions">
|
|
1340
|
+
<template #container>
|
|
1341
|
+
<span class="rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-2 body-14-regular">
|
|
1342
|
+
Hover or Tab to reveal actions
|
|
1343
|
+
</span>
|
|
1344
|
+
</template>
|
|
1345
|
+
<template #action>
|
|
1346
|
+
<UiFloatActionItems aria-label="Text actions">
|
|
1347
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1348
|
+
<UiIcon name="copy" size="s" />
|
|
1349
|
+
</UiFloatActionItems>
|
|
1350
|
+
</UiFloatActionItems>
|
|
1351
|
+
</template>
|
|
1352
|
+
</UiFloatActions>
|
|
1353
|
+
</div>
|
|
1354
|
+
`,
|
|
1355
|
+
}),
|
|
1356
|
+
parameters: {
|
|
1357
|
+
chromatic: { disableSnapshot: true },
|
|
1358
|
+
docs: {
|
|
1359
|
+
description: {
|
|
1360
|
+
story:
|
|
1361
|
+
'Press `Tab` to focus the hover anchor — the panel opens for keyboard users just like it does on pointer hover.',
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
},
|
|
1365
|
+
play: async ({ canvasElement, step }) => {
|
|
1366
|
+
// Scenario (UiFloatActions): a `hover` trigger must also open on keyboard
|
|
1367
|
+
// focus so keyboard-only users reach the same actions as pointer users.
|
|
1368
|
+
// Tabbing to the anchor opens the teleported panel (queried on the body).
|
|
1369
|
+
const canvas = within(canvasElement);
|
|
1370
|
+
const body = within(document.body);
|
|
1371
|
+
const anchor = canvas.getByRole('button', { name: 'Text actions' });
|
|
1372
|
+
|
|
1373
|
+
await step(
|
|
1374
|
+
'keyboard: focusing a hover trigger opens the panel for keyboard users (WCAG 2.1.1)',
|
|
1375
|
+
async () => {
|
|
1376
|
+
await expect(anchor).toHaveAttribute('aria-haspopup', 'true');
|
|
1377
|
+
await userEvent.tab();
|
|
1378
|
+
await expect(anchor).toHaveFocus();
|
|
1379
|
+
await waitFor(() =>
|
|
1380
|
+
expect(anchor).toHaveAttribute('aria-expanded', 'true'),
|
|
1381
|
+
);
|
|
1382
|
+
await expect(
|
|
1383
|
+
await body.findByRole('button', { name: 'Copy' }),
|
|
1384
|
+
).toBeInTheDocument();
|
|
1385
|
+
},
|
|
1386
|
+
);
|
|
1387
|
+
},
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* A `click` trigger toggles the panel with `Enter` and `Space` (and pointer
|
|
1392
|
+
* click), flipping `aria-expanded`. Hidden test-only story.
|
|
1393
|
+
*/
|
|
1394
|
+
export const ClickTriggerKeyboard: Story = {
|
|
1395
|
+
name: 'test - Click toggle keyboard',
|
|
1396
|
+
tags: ['!dev', '!autodocs'],
|
|
1397
|
+
render: () => ({
|
|
1398
|
+
components: { UiFloatActions, UiFloatActionItems, UiIcon },
|
|
1399
|
+
template: `
|
|
1400
|
+
<div class="flex min-h-64 items-center justify-center p-8">
|
|
1401
|
+
<UiFloatActions trigger="click" placement="top" :offset="10" aria-label="Open actions">
|
|
1402
|
+
<template #container>
|
|
1403
|
+
<span class="rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-2 body-14-regular">
|
|
1404
|
+
Click or press Enter / Space
|
|
1405
|
+
</span>
|
|
1406
|
+
</template>
|
|
1407
|
+
<template #action>
|
|
1408
|
+
<UiFloatActionItems aria-label="Open actions">
|
|
1409
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
1410
|
+
<UiIcon name="edit" size="s" />
|
|
1411
|
+
</UiFloatActionItems>
|
|
1412
|
+
</UiFloatActionItems>
|
|
1413
|
+
</template>
|
|
1414
|
+
</UiFloatActions>
|
|
1415
|
+
</div>
|
|
1416
|
+
`,
|
|
1417
|
+
}),
|
|
1418
|
+
parameters: {
|
|
1419
|
+
chromatic: { disableSnapshot: true },
|
|
1420
|
+
docs: {
|
|
1421
|
+
description: {
|
|
1422
|
+
story:
|
|
1423
|
+
'Focus the anchor, then press `Enter` to open and `Space` to close the panel.',
|
|
1424
|
+
},
|
|
1425
|
+
},
|
|
1426
|
+
},
|
|
1427
|
+
play: async ({ canvasElement, step }) => {
|
|
1428
|
+
// Scenario (UiFloatActions): a `click` trigger toggles from the keyboard —
|
|
1429
|
+
// focus alone must not open it, Enter opens the panel and Space closes it,
|
|
1430
|
+
// flipping aria-expanded each time.
|
|
1431
|
+
const canvas = within(canvasElement);
|
|
1432
|
+
const body = within(document.body);
|
|
1433
|
+
const anchor = canvas.getByRole('button', { name: 'Open actions' });
|
|
1434
|
+
|
|
1435
|
+
await step(
|
|
1436
|
+
'keyboard: Enter opens the click-trigger panel (WCAG 2.1.1 / 4.1.2)',
|
|
1437
|
+
async () => {
|
|
1438
|
+
await userEvent.tab();
|
|
1439
|
+
await expect(anchor).toHaveFocus();
|
|
1440
|
+
// Focus alone must not open a click trigger.
|
|
1441
|
+
await expect(anchor).toHaveAttribute('aria-expanded', 'false');
|
|
1442
|
+
await userEvent.keyboard('{Enter}');
|
|
1443
|
+
await waitFor(() =>
|
|
1444
|
+
expect(anchor).toHaveAttribute('aria-expanded', 'true'),
|
|
1445
|
+
);
|
|
1446
|
+
await expect(
|
|
1447
|
+
await body.findByRole('button', { name: 'Edit' }),
|
|
1448
|
+
).toBeInTheDocument();
|
|
1449
|
+
},
|
|
1450
|
+
);
|
|
1451
|
+
|
|
1452
|
+
await step(
|
|
1453
|
+
'keyboard: Space closes the click-trigger panel (WCAG 2.1.1)',
|
|
1454
|
+
async () => {
|
|
1455
|
+
await userEvent.keyboard(' ');
|
|
1456
|
+
await waitFor(() =>
|
|
1457
|
+
expect(anchor).toHaveAttribute('aria-expanded', 'false'),
|
|
1458
|
+
);
|
|
1459
|
+
await waitFor(() =>
|
|
1460
|
+
expect(
|
|
1461
|
+
body.queryByRole('button', { name: 'Edit' }),
|
|
1462
|
+
).not.toBeInTheDocument(),
|
|
1463
|
+
);
|
|
1464
|
+
},
|
|
1465
|
+
);
|
|
1466
|
+
},
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* The toolbar follows the WAI-ARIA APG pattern: `role="toolbar"` with roving
|
|
1471
|
+
* arrow-key focus, accessibly named items, and `click` events from buttons.
|
|
1472
|
+
* Hidden test-only story.
|
|
1473
|
+
*/
|
|
1474
|
+
export const ToolbarKeyboard: Story = {
|
|
1475
|
+
name: 'test - Toolbar keyboard & items',
|
|
1476
|
+
tags: ['!dev', '!autodocs'],
|
|
1477
|
+
render: () => ({
|
|
1478
|
+
components: { UiFloatActionItems, UiIcon },
|
|
1479
|
+
setup() {
|
|
1480
|
+
return { onItemClick };
|
|
1481
|
+
},
|
|
1482
|
+
template: `
|
|
1483
|
+
<div class="flex min-h-48 items-center justify-center p-8">
|
|
1484
|
+
<UiFloatActionItems aria-label="Paragraph actions">
|
|
1485
|
+
<UiFloatActionItems type="button" aria-label="Edit" @click="onItemClick">
|
|
1486
|
+
<UiIcon name="edit" size="s" />
|
|
1487
|
+
</UiFloatActionItems>
|
|
1488
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1489
|
+
<UiIcon name="copy" size="s" />
|
|
1490
|
+
</UiFloatActionItems>
|
|
1491
|
+
<UiFloatActionItems type="separator" />
|
|
1492
|
+
<UiFloatActionItems type="input" aria-label="Filter value" placeholder="Filter..." />
|
|
1493
|
+
</UiFloatActionItems>
|
|
1494
|
+
</div>
|
|
1495
|
+
`,
|
|
1496
|
+
}),
|
|
1497
|
+
parameters: {
|
|
1498
|
+
chromatic: { disableSnapshot: true },
|
|
1499
|
+
docs: {
|
|
1500
|
+
description: {
|
|
1501
|
+
story:
|
|
1502
|
+
'Tab once to enter the toolbar, then use the Arrow keys to move roving focus between items.',
|
|
1503
|
+
},
|
|
1504
|
+
},
|
|
1505
|
+
},
|
|
1506
|
+
play: async ({ canvasElement, step }) => {
|
|
1507
|
+
// Scenario (UiFloatActionItems): the toolbar follows the WAI-ARIA APG
|
|
1508
|
+
// pattern — a single Tab stop enters it, Arrow keys move roving focus
|
|
1509
|
+
// between items, every item is accessibly named, and activating a button
|
|
1510
|
+
// emits its click event (asserted via the module-level `onItemClick` spy).
|
|
1511
|
+
onItemClick.mockClear();
|
|
1512
|
+
const canvas = within(canvasElement);
|
|
1513
|
+
const toolbar = canvas.getByRole('toolbar', { name: 'Paragraph actions' });
|
|
1514
|
+
const edit = canvas.getByRole('button', { name: 'Edit' });
|
|
1515
|
+
const copy = canvas.getByRole('button', { name: 'Copy' });
|
|
1516
|
+
const filter = canvas.getByRole('textbox', { name: 'Filter value' });
|
|
1517
|
+
|
|
1518
|
+
await step(
|
|
1519
|
+
'screen-reader: the toolbar and its items expose roles and accessible names (WCAG 4.1.2)',
|
|
1520
|
+
async () => {
|
|
1521
|
+
await expect(toolbar).toHaveAttribute('aria-orientation', 'horizontal');
|
|
1522
|
+
await expect(edit).toBeInTheDocument();
|
|
1523
|
+
await expect(filter).toHaveAttribute('placeholder', 'Filter...');
|
|
1524
|
+
},
|
|
1525
|
+
);
|
|
1526
|
+
|
|
1527
|
+
await step(
|
|
1528
|
+
'keyboard: the toolbar is a single Tab stop and Arrow keys move roving focus (WCAG 2.1.1)',
|
|
1529
|
+
async () => {
|
|
1530
|
+
await userEvent.tab();
|
|
1531
|
+
await expect(edit).toHaveFocus();
|
|
1532
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1533
|
+
await expect(copy).toHaveFocus();
|
|
1534
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1535
|
+
await expect(filter).toHaveFocus();
|
|
1536
|
+
},
|
|
1537
|
+
);
|
|
1538
|
+
|
|
1539
|
+
await step(
|
|
1540
|
+
'interaction: activating a button item emits its click event',
|
|
1541
|
+
async () => {
|
|
1542
|
+
await userEvent.click(edit);
|
|
1543
|
+
await expect(onItemClick).toHaveBeenCalledTimes(1);
|
|
1544
|
+
},
|
|
1545
|
+
);
|
|
1546
|
+
},
|
|
1547
|
+
};
|
|
1548
|
+
|
|
1549
|
+
/**
|
|
1550
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1551
|
+
* try 400% reflow (WCAG 1.4.10); the toolbar must stay visible and operable.
|
|
1552
|
+
* Hidden test-only story.
|
|
1553
|
+
*/
|
|
1554
|
+
export const ZoomMagnification: Story = {
|
|
1555
|
+
name: 'test - Zoom magnification',
|
|
1556
|
+
tags: ['!dev', '!autodocs'],
|
|
1557
|
+
globals: { zoom: '200' },
|
|
1558
|
+
render: () => ({
|
|
1559
|
+
components: { UiFloatActionItems, UiIcon },
|
|
1560
|
+
setup() {
|
|
1561
|
+
return { onItemClick };
|
|
1562
|
+
},
|
|
1563
|
+
template: `
|
|
1564
|
+
<div class="flex min-h-48 items-center justify-center p-8">
|
|
1565
|
+
<UiFloatActionItems aria-label="Paragraph actions">
|
|
1566
|
+
<UiFloatActionItems type="button" aria-label="Edit" @click="onItemClick">
|
|
1567
|
+
<UiIcon name="edit" size="s" />
|
|
1568
|
+
</UiFloatActionItems>
|
|
1569
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1570
|
+
<UiIcon name="copy" size="s" />
|
|
1571
|
+
</UiFloatActionItems>
|
|
1572
|
+
<UiFloatActionItems type="button" aria-label="Delete">
|
|
1573
|
+
<UiIcon name="trash" size="s" />
|
|
1574
|
+
</UiFloatActionItems>
|
|
1575
|
+
</UiFloatActionItems>
|
|
1576
|
+
</div>
|
|
1577
|
+
`,
|
|
1578
|
+
}),
|
|
1579
|
+
parameters: {
|
|
1580
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
1581
|
+
// already covers magnified snapshots, so skip this one.
|
|
1582
|
+
chromatic: { disableSnapshot: true },
|
|
1583
|
+
docs: {
|
|
1584
|
+
description: {
|
|
1585
|
+
story:
|
|
1586
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1587
|
+
},
|
|
1588
|
+
},
|
|
1589
|
+
},
|
|
1590
|
+
play: async ({ canvasElement, step }) => {
|
|
1591
|
+
// Scenario (UiFloatActionItems): at 200% page zoom the toolbar stays visible,
|
|
1592
|
+
// keeps its accessible names, and remains operable.
|
|
1593
|
+
onItemClick.mockClear();
|
|
1594
|
+
const canvas = within(canvasElement);
|
|
1595
|
+
const edit = canvas.getByRole('button', { name: 'Edit' });
|
|
1596
|
+
|
|
1597
|
+
await step(
|
|
1598
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1599
|
+
async () => {
|
|
1600
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1601
|
+
},
|
|
1602
|
+
);
|
|
1603
|
+
|
|
1604
|
+
await step(
|
|
1605
|
+
'zoom: the toolbar and its buttons stay visible with their accessible names',
|
|
1606
|
+
async () => {
|
|
1607
|
+
await expect(
|
|
1608
|
+
canvas.getByRole('toolbar', { name: 'Paragraph actions' }),
|
|
1609
|
+
).toBeVisible();
|
|
1610
|
+
await expect(edit).toBeVisible();
|
|
1611
|
+
await expect(edit).toHaveAccessibleName('Edit');
|
|
1612
|
+
},
|
|
1613
|
+
);
|
|
1614
|
+
|
|
1615
|
+
await step('zoom: remains operable when magnified', async () => {
|
|
1616
|
+
await userEvent.click(edit);
|
|
1617
|
+
await expect(onItemClick).toHaveBeenCalledTimes(1);
|
|
1618
|
+
});
|
|
1619
|
+
},
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* Rendered at the 320px mobile reflow breakpoint. The toolbar stays labelled,
|
|
1624
|
+
* keyboard operable via roving focus, and its buttons meet the minimum
|
|
1625
|
+
* touch-target size. Hidden test-only story.
|
|
1626
|
+
*/
|
|
1627
|
+
export const MobileBreakpoint: Story = {
|
|
1628
|
+
name: 'test - Mobile breakpoint',
|
|
1629
|
+
tags: ['!dev', '!autodocs'],
|
|
1630
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1631
|
+
render: () => ({
|
|
1632
|
+
components: { UiFloatActionItems, UiIcon },
|
|
1633
|
+
template: `
|
|
1634
|
+
<div class="flex min-h-48 items-center justify-center p-8">
|
|
1635
|
+
<UiFloatActionItems aria-label="Paragraph actions">
|
|
1636
|
+
<UiFloatActionItems type="button" aria-label="Edit">
|
|
1637
|
+
<UiIcon name="edit" size="s" />
|
|
1638
|
+
</UiFloatActionItems>
|
|
1639
|
+
<UiFloatActionItems type="button" aria-label="Copy">
|
|
1640
|
+
<UiIcon name="copy" size="s" />
|
|
1641
|
+
</UiFloatActionItems>
|
|
1642
|
+
</UiFloatActionItems>
|
|
1643
|
+
</div>
|
|
1644
|
+
`,
|
|
1645
|
+
}),
|
|
1646
|
+
parameters: {
|
|
1647
|
+
// Reflow snapshots are already covered by the accessible-reflow Chromatic
|
|
1648
|
+
// mode, and the play moves focus, so skip this snapshot.
|
|
1649
|
+
chromatic: { disableSnapshot: true },
|
|
1650
|
+
docs: {
|
|
1651
|
+
description: {
|
|
1652
|
+
story:
|
|
1653
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1654
|
+
},
|
|
1655
|
+
},
|
|
1656
|
+
},
|
|
1657
|
+
play: async ({ canvasElement, step }) => {
|
|
1658
|
+
// Scenario (UiFloatActionItems): at the 320px mobile breakpoint the toolbar
|
|
1659
|
+
// stays labelled, keyboard operable (roving focus), and its buttons meet the
|
|
1660
|
+
// minimum touch-target size.
|
|
1661
|
+
const canvas = within(canvasElement);
|
|
1662
|
+
const toolbar = canvas.getByRole('toolbar', { name: 'Paragraph actions' });
|
|
1663
|
+
const edit = canvas.getByRole('button', { name: 'Edit' });
|
|
1664
|
+
const copy = canvas.getByRole('button', { name: 'Copy' });
|
|
1665
|
+
|
|
1666
|
+
await step(
|
|
1667
|
+
'mobile: exposes a labelled toolbar and named items at the 320px breakpoint (WCAG 4.1.2)',
|
|
1668
|
+
async () => {
|
|
1669
|
+
await expect(toolbar).toBeVisible();
|
|
1670
|
+
await expect(edit).toHaveAccessibleName('Edit');
|
|
1671
|
+
},
|
|
1672
|
+
);
|
|
1673
|
+
|
|
1674
|
+
await step(
|
|
1675
|
+
'mobile: stays keyboard operable — Tab enters the toolbar and Arrow keys move roving focus (WCAG 2.1.1)',
|
|
1676
|
+
async () => {
|
|
1677
|
+
await userEvent.tab();
|
|
1678
|
+
await expect(edit).toHaveFocus();
|
|
1679
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1680
|
+
await expect(copy).toHaveFocus();
|
|
1681
|
+
},
|
|
1682
|
+
);
|
|
1683
|
+
|
|
1684
|
+
await step(
|
|
1685
|
+
'mobile: the toolbar buttons meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1686
|
+
async () => {
|
|
1687
|
+
const { width, height } = edit.getBoundingClientRect();
|
|
1688
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1689
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1690
|
+
},
|
|
1691
|
+
);
|
|
1692
|
+
},
|
|
1693
|
+
};
|