@aleph-alpha/ui-library 6.0.0 → 6.1.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 +28 -4
- package/config.js +99 -23
- package/dist/system/components/UiTagsInput/UiTagsInput.vue.d.ts +2 -0
- package/dist/system/components/UiTagsInput/UiTagsInputItemDelete.vue.d.ts +2 -1
- package/dist/system/components/UiTagsInput/types.d.ts +21 -2
- package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
- package/dist/system/icons/story-sidebar-icons.json +7 -0
- package/dist/system/lib.js +1752 -1708
- package/dist/system/story-sidebar-icons.json +7 -0
- package/docs/public-docs/migration-guide.md +402 -0
- package/docs/public-docs/quick-start.md +19 -10
- package/package.json +4 -1
- package/src/components/UiAlert/UiAlert.stories.ts +732 -0
- package/src/components/UiAlert/__tests__/UiAlert.test.ts +57 -11
- package/src/components/UiChip/UiChip.stories.ts +756 -2
- package/src/components/UiChip/UiChip.vue +7 -6
- package/src/components/UiChip/__tests__/UiChip.test.ts +38 -61
- package/src/components/UiDrawer/UiDrawer.stories.ts +665 -0
- package/src/components/UiDrawer/__tests__/UiDrawer.test.ts +6 -190
- package/src/components/UiLabel/UiLabel.stories.ts +691 -16
- package/src/components/UiLabel/__tests__/UiLabel.test.ts +18 -26
- package/src/components/UiSheet/UiSheet.stories.ts +751 -0
- package/src/components/UiSheet/__tests__/UiSheet.test.ts +6 -190
- package/src/components/UiSlider/UiSlider.stories.ts +716 -0
- package/src/components/UiSlider/__tests__/UiSlider.test.ts +8 -45
- package/src/components/UiSwitch/UiSwitch.stories.ts +11 -5
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +850 -4
- package/src/components/UiTagsInput/UiTagsInput.vue +34 -0
- package/src/components/UiTagsInput/UiTagsInputItemDelete.vue +4 -1
- package/src/components/UiTagsInput/__tests__/UiTagsInput.test.ts +113 -29
- package/src/components/UiTagsInput/types.ts +24 -2
- package/src/components/core/sheet/SheetContent.vue +6 -1
- package/src/components/core/switch/index.ts +8 -7
- package/src/components/core/tags-input/TagsInput.vue +4 -1
- package/src/components/core/tags-input/TagsInputItem.vue +13 -1
- package/src/components/core/tags-input/TagsInputItemDelete.vue +40 -7
- package/src/theme/Typography.stories.ts +125 -133
- package/tokens.json +8132 -2475
- package/dist/system/icons/mobile-device-frame.png +0 -0
- package/dist/system/mobile-device-frame.png +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
2
3
|
import { ref } from 'vue';
|
|
3
4
|
import UiChip from './UiChip.vue';
|
|
4
5
|
import { UiIcon } from '../UiIcon';
|
|
@@ -62,6 +63,12 @@ export default meta;
|
|
|
62
63
|
|
|
63
64
|
type Story = StoryObj<typeof UiChip>;
|
|
64
65
|
|
|
66
|
+
// `UiChip` emits `remove` and `update:modelValue`; neither is a handler prop,
|
|
67
|
+
// so play functions bind these module-level spies in the template and
|
|
68
|
+
// `mockClear()` them first.
|
|
69
|
+
const onRemove = fn();
|
|
70
|
+
const onUpdateSelected = fn();
|
|
71
|
+
|
|
65
72
|
/**
|
|
66
73
|
* Static chips are non-interactive and work as labels/tags.
|
|
67
74
|
*/
|
|
@@ -79,6 +86,36 @@ export const Static: Story = {
|
|
|
79
86
|
</div>
|
|
80
87
|
`,
|
|
81
88
|
}),
|
|
89
|
+
play: async ({ canvasElement, step }) => {
|
|
90
|
+
// Scenario (UiChip variant="static"): a read-only tag. It must read as
|
|
91
|
+
// plain text — no actionable role, no tab stop — so assistive tech does
|
|
92
|
+
// not promise an interaction that does not exist. Non-mutating.
|
|
93
|
+
const canvas = within(canvasElement);
|
|
94
|
+
|
|
95
|
+
await step(
|
|
96
|
+
'screen-reader: a static chip is plain text, not a control (WCAG 4.1.2)',
|
|
97
|
+
async () => {
|
|
98
|
+
await expect(canvas.getByText('Data Analysis')).toBeVisible();
|
|
99
|
+
await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
await step(
|
|
104
|
+
'screen-reader: a disabled static chip exposes aria-disabled',
|
|
105
|
+
async () => {
|
|
106
|
+
await expect(canvas.getByText('Disabled')).toHaveAttribute(
|
|
107
|
+
'aria-disabled',
|
|
108
|
+
'true',
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
await step('interaction: static chips are not focusable', async () => {
|
|
114
|
+
for (const label of ['Data Analysis', 'With icon', 'Disabled']) {
|
|
115
|
+
await expect(canvas.getByText(label)).not.toHaveAttribute('tabindex');
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
},
|
|
82
119
|
};
|
|
83
120
|
|
|
84
121
|
/**
|
|
@@ -100,6 +137,36 @@ export const Selectable: Story = {
|
|
|
100
137
|
</div>
|
|
101
138
|
`,
|
|
102
139
|
}),
|
|
140
|
+
play: async ({ canvasElement, step }) => {
|
|
141
|
+
// Scenario (UiChip variant="selectable"): each chip is a toggle button, so
|
|
142
|
+
// selection has to reach assistive tech through `aria-pressed` rather than
|
|
143
|
+
// through the highlighted background alone. Non-mutating.
|
|
144
|
+
const canvas = within(canvasElement);
|
|
145
|
+
|
|
146
|
+
await step(
|
|
147
|
+
'screen-reader: selectable chips are toggle buttons with a name (WCAG 4.1.2)',
|
|
148
|
+
async () => {
|
|
149
|
+
const chip = canvas.getByRole('button', { name: 'Default' });
|
|
150
|
+
await expect(chip).toHaveAccessibleName('Default');
|
|
151
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'false');
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
await step(
|
|
156
|
+
'screen-reader: selection is exposed as pressed state, not colour alone (WCAG 1.4.1)',
|
|
157
|
+
async () => {
|
|
158
|
+
await expect(
|
|
159
|
+
canvas.getByRole('button', { name: 'Active' }),
|
|
160
|
+
).toHaveAttribute('aria-pressed', 'true');
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
await step('interaction: a disabled selectable chip is inert', async () => {
|
|
165
|
+
await expect(
|
|
166
|
+
canvas.getByRole('button', { name: 'Disabled' }),
|
|
167
|
+
).toBeDisabled();
|
|
168
|
+
});
|
|
169
|
+
},
|
|
103
170
|
};
|
|
104
171
|
|
|
105
172
|
/**
|
|
@@ -141,6 +208,48 @@ export const Removable: Story = {
|
|
|
141
208
|
</div>
|
|
142
209
|
`,
|
|
143
210
|
}),
|
|
211
|
+
play: async ({ canvasElement, step }) => {
|
|
212
|
+
// Scenario (UiChip variant="removable"): the remove control is icon-only,
|
|
213
|
+
// so its `removeLabel` is the only thing a screen reader can announce. The
|
|
214
|
+
// label itself is only a button when the chip is also selectable.
|
|
215
|
+
// Non-mutating, so no chip is actually removed here.
|
|
216
|
+
const canvas = within(canvasElement);
|
|
217
|
+
|
|
218
|
+
await step(
|
|
219
|
+
'screen-reader: the icon-only remove control is announced by its label (WCAG 4.1.2)',
|
|
220
|
+
async () => {
|
|
221
|
+
const removeControls = canvas.getAllByRole('button', {
|
|
222
|
+
name: 'Remove chip',
|
|
223
|
+
});
|
|
224
|
+
await expect(removeControls.length).toBeGreaterThan(0);
|
|
225
|
+
for (const control of removeControls) {
|
|
226
|
+
await expect(control).toHaveAccessibleName('Remove chip');
|
|
227
|
+
await expect(control).toBeEnabled();
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
await step(
|
|
233
|
+
'screen-reader: a removable chip that cannot be selected exposes no primary button',
|
|
234
|
+
async () => {
|
|
235
|
+
// Only the remove control is actionable, so the label stays a plain
|
|
236
|
+
// `span` rather than a button that does nothing.
|
|
237
|
+
await expect(
|
|
238
|
+
canvas.queryByRole('button', { name: 'Data Analysis' }),
|
|
239
|
+
).not.toBeInTheDocument();
|
|
240
|
+
await expect(canvas.getByText('Data Analysis')).toBeVisible();
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
await step(
|
|
245
|
+
'screen-reader: a selectable removable chip exposes a pressed primary button',
|
|
246
|
+
async () => {
|
|
247
|
+
await expect(
|
|
248
|
+
canvas.getByRole('button', { name: 'Selectable removable' }),
|
|
249
|
+
).toHaveAttribute('aria-pressed', 'true');
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
},
|
|
144
253
|
};
|
|
145
254
|
|
|
146
255
|
/**
|
|
@@ -165,6 +274,37 @@ export const WithAndWithoutLeadingIcon: Story = {
|
|
|
165
274
|
</div>
|
|
166
275
|
`,
|
|
167
276
|
}),
|
|
277
|
+
play: async ({ canvasElement, step }) => {
|
|
278
|
+
// Scenario (UiChip startIcon): the leading icon is decoration. It must not
|
|
279
|
+
// leak into the chip's accessible name, or a screen reader would announce
|
|
280
|
+
// the glyph alongside the label. Non-mutating.
|
|
281
|
+
const canvas = within(canvasElement);
|
|
282
|
+
|
|
283
|
+
await step(
|
|
284
|
+
'screen-reader: a leading icon is hidden from assistive tech',
|
|
285
|
+
async () => {
|
|
286
|
+
const chip = canvas.getByRole('button', {
|
|
287
|
+
name: 'Selectable with icon',
|
|
288
|
+
});
|
|
289
|
+
const icon = chip.querySelector('svg');
|
|
290
|
+
await expect(icon).not.toBeNull();
|
|
291
|
+
await expect(icon).toHaveAttribute('aria-hidden', 'true');
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
await step(
|
|
296
|
+
'screen-reader: the icon leaves the accessible name unchanged (WCAG 4.1.2)',
|
|
297
|
+
async () => {
|
|
298
|
+
// The chip reads the same with and without decoration.
|
|
299
|
+
await expect(
|
|
300
|
+
canvas.getByRole('button', { name: 'Selectable with icon' }),
|
|
301
|
+
).toHaveAccessibleName('Selectable with icon');
|
|
302
|
+
await expect(
|
|
303
|
+
canvas.getByRole('button', { name: 'Selectable no icon' }),
|
|
304
|
+
).toHaveAccessibleName('Selectable no icon');
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
},
|
|
168
308
|
};
|
|
169
309
|
|
|
170
310
|
/**
|
|
@@ -214,8 +354,9 @@ export const Group: Story = {
|
|
|
214
354
|
};
|
|
215
355
|
|
|
216
356
|
/**
|
|
217
|
-
* Focus order for interactive chips
|
|
218
|
-
* selectable chip
|
|
357
|
+
* Focus order for interactive chips. Only controls that do something are tab
|
|
358
|
+
* stops: a selectable chip is one, a selectable removable chip is two (label
|
|
359
|
+
* then dismiss), and a remove-only chip is one (its dismiss action).
|
|
219
360
|
*/
|
|
220
361
|
export const FocusOrderInteractive: Story = {
|
|
221
362
|
render: () => ({
|
|
@@ -247,4 +388,617 @@ export const FocusOrderInteractive: Story = {
|
|
|
247
388
|
</div>
|
|
248
389
|
`,
|
|
249
390
|
}),
|
|
391
|
+
play: async ({ canvasElement, step }) => {
|
|
392
|
+
// Scenario (UiChip): the documented focus order is exactly the set of
|
|
393
|
+
// controls that do something — a selectable chip, a selectable removable
|
|
394
|
+
// chip plus its remove control, and a remove-only chip. Non-mutating: the
|
|
395
|
+
// count is checked without moving focus.
|
|
396
|
+
const canvas = within(canvasElement);
|
|
397
|
+
|
|
398
|
+
await step(
|
|
399
|
+
'screen-reader: every tab stop is a real control with a name (WCAG 4.1.2)',
|
|
400
|
+
async () => {
|
|
401
|
+
const controls = canvas.getAllByRole('button');
|
|
402
|
+
await expect(controls).toHaveLength(4);
|
|
403
|
+
for (const control of controls) {
|
|
404
|
+
await expect(control).toHaveAccessibleName();
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
await step(
|
|
410
|
+
'interaction: the remove-only chip contributes one tab stop, not two',
|
|
411
|
+
async () => {
|
|
412
|
+
await expect(
|
|
413
|
+
canvas.queryByRole('button', { name: 'Focus 4' }),
|
|
414
|
+
).not.toBeInTheDocument();
|
|
415
|
+
await expect(canvas.getByText('Focus 4')).toBeVisible();
|
|
416
|
+
},
|
|
417
|
+
);
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Accessibility guidance for choosing a variant, naming the remove control,
|
|
423
|
+
* exposing selection, and contrast.
|
|
424
|
+
*/
|
|
425
|
+
export const Accessibility: Story = {
|
|
426
|
+
render: () => ({
|
|
427
|
+
components: { UiChip },
|
|
428
|
+
setup() {
|
|
429
|
+
const selected = ref(true);
|
|
430
|
+
const accessibleSelected = ref(true);
|
|
431
|
+
return { selected, accessibleSelected, TagIcon };
|
|
432
|
+
},
|
|
433
|
+
template: `
|
|
434
|
+
<section class="flex flex-col gap-6 p-4">
|
|
435
|
+
<div>
|
|
436
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
437
|
+
Accessibility
|
|
438
|
+
</h2>
|
|
439
|
+
</div>
|
|
440
|
+
|
|
441
|
+
<div class="flex flex-col gap-6">
|
|
442
|
+
<div class="flex flex-col gap-2">
|
|
443
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
444
|
+
Let the variant match the behaviour
|
|
445
|
+
</h3>
|
|
446
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
447
|
+
Each variant renders different semantics on purpose:
|
|
448
|
+
<code>static</code> is a plain <code>span</code> with no role and
|
|
449
|
+
no tab stop, <code>selectable</code> is a toggle button, and
|
|
450
|
+
<code>removable</code> exposes a remove button. Don't wire a
|
|
451
|
+
click handler onto a static chip — it would look interactive
|
|
452
|
+
while being invisible to keyboard and screen-reader users.
|
|
453
|
+
</p>
|
|
454
|
+
</div>
|
|
455
|
+
|
|
456
|
+
<div class="flex flex-col gap-2">
|
|
457
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
458
|
+
Name the remove control after its chip
|
|
459
|
+
</h3>
|
|
460
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
461
|
+
The remove control is icon-only, so
|
|
462
|
+
<code>removeLabel</code> is the only thing announced. The default
|
|
463
|
+
<code>Remove chip</code> is fine for a single chip, but in a list
|
|
464
|
+
every control would read identically — pass
|
|
465
|
+
<code>removeLabel="Remove Data Analysis"</code> so it is clear
|
|
466
|
+
which chip is about to go.
|
|
467
|
+
</p>
|
|
468
|
+
</div>
|
|
469
|
+
|
|
470
|
+
<div class="flex flex-col gap-2">
|
|
471
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
472
|
+
Selection is announced, not just coloured
|
|
473
|
+
</h3>
|
|
474
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
475
|
+
A selected chip changes its background, and
|
|
476
|
+
<code>aria-pressed</code> carries the same state for anyone who
|
|
477
|
+
cannot see it (WCAG 1.4.1). This only applies to interactive
|
|
478
|
+
chips; set <code>selectable</code> on a removable chip when it
|
|
479
|
+
should toggle as well as dismiss.
|
|
480
|
+
</p>
|
|
481
|
+
</div>
|
|
482
|
+
|
|
483
|
+
<div class="flex flex-col gap-2">
|
|
484
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
485
|
+
Keep chips reachable
|
|
486
|
+
</h3>
|
|
487
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
488
|
+
Interactive chips are ordinary buttons: <code>Tab</code> reaches
|
|
489
|
+
them and <code>Enter</code> or <code>Space</code> activates them.
|
|
490
|
+
A removable chip that also selects contributes two tab stops —
|
|
491
|
+
the label, then the remove control.
|
|
492
|
+
</p>
|
|
493
|
+
</div>
|
|
494
|
+
|
|
495
|
+
<div class="flex flex-col gap-2">
|
|
496
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
497
|
+
Enable accessibility theme
|
|
498
|
+
</h3>
|
|
499
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
500
|
+
When accessibility is required, enable our accessibility theme.
|
|
501
|
+
This increases contrast and makes sure there are no color
|
|
502
|
+
contrast issues.
|
|
503
|
+
</p>
|
|
504
|
+
</div>
|
|
505
|
+
</div>
|
|
506
|
+
|
|
507
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
508
|
+
<div class="flex flex-col gap-3">
|
|
509
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
510
|
+
Default
|
|
511
|
+
</h3>
|
|
512
|
+
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
513
|
+
<UiChip variant="static">Static</UiChip>
|
|
514
|
+
<UiChip v-model="selected" variant="selectable">Selectable</UiChip>
|
|
515
|
+
<UiChip
|
|
516
|
+
variant="removable"
|
|
517
|
+
:start-icon="TagIcon"
|
|
518
|
+
remove-label="Remove Data Analysis"
|
|
519
|
+
>
|
|
520
|
+
Data Analysis
|
|
521
|
+
</UiChip>
|
|
522
|
+
</div>
|
|
523
|
+
</div>
|
|
524
|
+
|
|
525
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
526
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
527
|
+
Accessible
|
|
528
|
+
</h3>
|
|
529
|
+
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
530
|
+
<UiChip variant="static">Static</UiChip>
|
|
531
|
+
<UiChip v-model="accessibleSelected" variant="selectable">Selectable</UiChip>
|
|
532
|
+
<UiChip
|
|
533
|
+
variant="removable"
|
|
534
|
+
:start-icon="TagIcon"
|
|
535
|
+
remove-label="Remove Data Analysis"
|
|
536
|
+
>
|
|
537
|
+
Data Analysis
|
|
538
|
+
</UiChip>
|
|
539
|
+
</div>
|
|
540
|
+
</div>
|
|
541
|
+
</div>
|
|
542
|
+
</section>
|
|
543
|
+
`,
|
|
544
|
+
}),
|
|
545
|
+
tags: ['!autodocs'],
|
|
546
|
+
parameters: {
|
|
547
|
+
a11y: { test: 'off' },
|
|
548
|
+
chromatic: {
|
|
549
|
+
disableSnapshot: true,
|
|
550
|
+
},
|
|
551
|
+
docs: {
|
|
552
|
+
canvas: {
|
|
553
|
+
sourceState: 'none',
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
/*
|
|
560
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
561
|
+
* Interaction & accessibility tests (play functions)
|
|
562
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
563
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
564
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
565
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
566
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
567
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
568
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2)
|
|
569
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
570
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
571
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
572
|
+
* an `a11y:` prefix.
|
|
573
|
+
*
|
|
574
|
+
* The shared render below puts all three variants on screen at once, which is
|
|
575
|
+
* what makes the semantic differences testable: the static chip and the
|
|
576
|
+
* remove-only chip's label must be skipped by Tab, while the selectable chip,
|
|
577
|
+
* the selectable removable chip's label, and every remove control must be
|
|
578
|
+
* reachable and operable. `removeLabel` is set per chip so each remove control
|
|
579
|
+
* has a unique accessible name to query by.
|
|
580
|
+
*/
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The chips the test stories drive: one of each variant, plus a removable chip
|
|
584
|
+
* that also selects. Removal is backed by a list so a play function can watch a
|
|
585
|
+
* chip actually disappear.
|
|
586
|
+
* @returns Vue component options for a story `render` function.
|
|
587
|
+
*/
|
|
588
|
+
function renderTestChips() {
|
|
589
|
+
return {
|
|
590
|
+
components: { UiChip },
|
|
591
|
+
setup() {
|
|
592
|
+
const selected = ref(false);
|
|
593
|
+
const comboSelected = ref(false);
|
|
594
|
+
const chips = ref(['Alpha', 'Beta']);
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Drops a chip from the list, mirroring what a consumer does on `remove`.
|
|
598
|
+
* @param label Label of the chip to remove.
|
|
599
|
+
*/
|
|
600
|
+
function removeChip(label: string) {
|
|
601
|
+
chips.value = chips.value.filter((chip) => chip !== label);
|
|
602
|
+
onRemove(label);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return { selected, comboSelected, chips, removeChip, onUpdateSelected };
|
|
606
|
+
},
|
|
607
|
+
template: `
|
|
608
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
609
|
+
<UiChip variant="static">Static chip</UiChip>
|
|
610
|
+
|
|
611
|
+
<UiChip
|
|
612
|
+
v-model="selected"
|
|
613
|
+
variant="selectable"
|
|
614
|
+
@update:model-value="onUpdateSelected"
|
|
615
|
+
>
|
|
616
|
+
Selectable chip
|
|
617
|
+
</UiChip>
|
|
618
|
+
|
|
619
|
+
<UiChip
|
|
620
|
+
v-for="chip in chips"
|
|
621
|
+
:key="chip"
|
|
622
|
+
variant="removable"
|
|
623
|
+
:remove-label="'Remove ' + chip"
|
|
624
|
+
@remove="removeChip(chip)"
|
|
625
|
+
>
|
|
626
|
+
{{ chip }}
|
|
627
|
+
</UiChip>
|
|
628
|
+
|
|
629
|
+
<UiChip
|
|
630
|
+
v-model="comboSelected"
|
|
631
|
+
variant="removable"
|
|
632
|
+
selectable
|
|
633
|
+
remove-label="Remove Combo"
|
|
634
|
+
>
|
|
635
|
+
Combo chip
|
|
636
|
+
</UiChip>
|
|
637
|
+
</div>
|
|
638
|
+
`,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Selecting toggles pressed state and removing drops the chip. Hidden test-only
|
|
644
|
+
* story.
|
|
645
|
+
*/
|
|
646
|
+
export const ChipInteraction: Story = {
|
|
647
|
+
name: 'test - Chip Interaction',
|
|
648
|
+
tags: ['!dev', '!autodocs'],
|
|
649
|
+
parameters: {
|
|
650
|
+
// Selection state changes and a chip is removed during the play function.
|
|
651
|
+
chromatic: { disableSnapshot: true },
|
|
652
|
+
docs: {
|
|
653
|
+
description: {
|
|
654
|
+
story:
|
|
655
|
+
'Click a selectable chip to toggle it, and a remove control to drop its chip.',
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
render: renderTestChips,
|
|
660
|
+
play: async ({ canvasElement, step }) => {
|
|
661
|
+
// Scenario (UiChip): a pointer user toggles a selectable chip on and off,
|
|
662
|
+
// removes a chip, and finds the static chip inert throughout.
|
|
663
|
+
onRemove.mockClear();
|
|
664
|
+
onUpdateSelected.mockClear();
|
|
665
|
+
const canvas = within(canvasElement);
|
|
666
|
+
|
|
667
|
+
await step(
|
|
668
|
+
'interaction: activating a selectable chip toggles its pressed state',
|
|
669
|
+
async () => {
|
|
670
|
+
const chip = canvas.getByRole('button', { name: 'Selectable chip' });
|
|
671
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'false');
|
|
672
|
+
|
|
673
|
+
await userEvent.click(chip);
|
|
674
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'true');
|
|
675
|
+
await expect(onUpdateSelected).toHaveBeenLastCalledWith(true);
|
|
676
|
+
|
|
677
|
+
await userEvent.click(chip);
|
|
678
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'false');
|
|
679
|
+
await expect(onUpdateSelected).toHaveBeenLastCalledWith(false);
|
|
680
|
+
},
|
|
681
|
+
);
|
|
682
|
+
|
|
683
|
+
await step(
|
|
684
|
+
'interaction: a removable chip that also selects toggles without removing',
|
|
685
|
+
async () => {
|
|
686
|
+
const combo = canvas.getByRole('button', { name: 'Combo chip' });
|
|
687
|
+
await userEvent.click(combo);
|
|
688
|
+
await expect(combo).toHaveAttribute('aria-pressed', 'true');
|
|
689
|
+
await expect(combo).toBeVisible();
|
|
690
|
+
await expect(onRemove).not.toHaveBeenCalled();
|
|
691
|
+
},
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
await step(
|
|
695
|
+
'interaction: activating the remove control removes that chip only',
|
|
696
|
+
async () => {
|
|
697
|
+
await userEvent.click(
|
|
698
|
+
canvas.getByRole('button', { name: 'Remove Alpha' }),
|
|
699
|
+
);
|
|
700
|
+
await expect(onRemove).toHaveBeenCalledWith('Alpha');
|
|
701
|
+
await waitFor(async () => {
|
|
702
|
+
await expect(canvas.queryByText('Alpha')).toBeNull();
|
|
703
|
+
});
|
|
704
|
+
await expect(canvas.getByText('Beta')).toBeVisible();
|
|
705
|
+
},
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
await step(
|
|
709
|
+
'interaction: the static chip never becomes a control',
|
|
710
|
+
async () => {
|
|
711
|
+
await expect(
|
|
712
|
+
canvas.queryByRole('button', { name: 'Static chip' }),
|
|
713
|
+
).not.toBeInTheDocument();
|
|
714
|
+
},
|
|
715
|
+
);
|
|
716
|
+
},
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Tab reaches every real control and skips the inert ones; Enter and Space both
|
|
721
|
+
* activate. Hidden test-only story.
|
|
722
|
+
*/
|
|
723
|
+
export const KeyboardNavigation: Story = {
|
|
724
|
+
name: 'test - Keyboard Navigation',
|
|
725
|
+
tags: ['!dev', '!autodocs'],
|
|
726
|
+
parameters: {
|
|
727
|
+
// Focus moves and a chip is removed during the play function.
|
|
728
|
+
chromatic: { disableSnapshot: true },
|
|
729
|
+
docs: {
|
|
730
|
+
description: {
|
|
731
|
+
story:
|
|
732
|
+
'Press `Tab` to walk the interactive chips and remove controls, then `Enter` or `Space` to activate one.',
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
render: renderTestChips,
|
|
737
|
+
play: async ({ canvasElement, step }) => {
|
|
738
|
+
// Scenario (UiChip): a keyboard user tabs through the group and lands only
|
|
739
|
+
// on controls that do something — the static chip and the remove-only
|
|
740
|
+
// labels are skipped — then activates a chip and a remove control.
|
|
741
|
+
onRemove.mockClear();
|
|
742
|
+
onUpdateSelected.mockClear();
|
|
743
|
+
const canvas = within(canvasElement);
|
|
744
|
+
|
|
745
|
+
await step(
|
|
746
|
+
'keyboard: Tab reaches the interactive chips in document order (WCAG 2.1.1, 2.4.3)',
|
|
747
|
+
async () => {
|
|
748
|
+
// Static chips and the labels of remove-only chips are not controls,
|
|
749
|
+
// so the expected order is exactly the actionable elements.
|
|
750
|
+
const expectedOrder = [
|
|
751
|
+
'Selectable chip',
|
|
752
|
+
'Remove Alpha',
|
|
753
|
+
'Remove Beta',
|
|
754
|
+
'Combo chip',
|
|
755
|
+
'Remove Combo',
|
|
756
|
+
];
|
|
757
|
+
|
|
758
|
+
for (const name of expectedOrder) {
|
|
759
|
+
await userEvent.tab();
|
|
760
|
+
await expect(canvas.getByRole('button', { name })).toHaveFocus();
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
);
|
|
764
|
+
|
|
765
|
+
await step(
|
|
766
|
+
'keyboard: Space activates the focused remove control',
|
|
767
|
+
async () => {
|
|
768
|
+
// Focus is on "Remove Combo" from the walk above; shift back to a chip
|
|
769
|
+
// whose removal is observable.
|
|
770
|
+
await userEvent.click(document.body);
|
|
771
|
+
canvas.getByRole('button', { name: 'Remove Alpha' }).focus();
|
|
772
|
+
await userEvent.keyboard(' ');
|
|
773
|
+
await expect(onRemove).toHaveBeenCalledWith('Alpha');
|
|
774
|
+
await waitFor(async () => {
|
|
775
|
+
await expect(canvas.queryByText('Alpha')).toBeNull();
|
|
776
|
+
});
|
|
777
|
+
},
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
await step(
|
|
781
|
+
'keyboard: Enter toggles the focused selectable chip',
|
|
782
|
+
async () => {
|
|
783
|
+
const chip = canvas.getByRole('button', { name: 'Selectable chip' });
|
|
784
|
+
chip.focus();
|
|
785
|
+
await expect(chip).toHaveFocus();
|
|
786
|
+
await userEvent.keyboard('{Enter}');
|
|
787
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'true');
|
|
788
|
+
await expect(onUpdateSelected).toHaveBeenLastCalledWith(true);
|
|
789
|
+
},
|
|
790
|
+
);
|
|
791
|
+
},
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Screen-reader semantics across all three variants, including the icon-only
|
|
796
|
+
* remove control's name (WCAG 4.1.2). Hidden test-only story.
|
|
797
|
+
*/
|
|
798
|
+
export const ScreenReader: Story = {
|
|
799
|
+
name: 'test - Screen Reader',
|
|
800
|
+
tags: ['!dev', '!autodocs'],
|
|
801
|
+
parameters: {
|
|
802
|
+
// Selection state changes during the play function.
|
|
803
|
+
chromatic: { disableSnapshot: true },
|
|
804
|
+
docs: {
|
|
805
|
+
description: {
|
|
806
|
+
story:
|
|
807
|
+
'Verifies the roles, names, and pressed state that assistive technology announces for each chip variant.',
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
},
|
|
811
|
+
render: renderTestChips,
|
|
812
|
+
play: async ({ canvasElement, step }) => {
|
|
813
|
+
// Scenario (UiChip): assistive tech gets an accurate picture of each
|
|
814
|
+
// variant — inert text, a toggle button, and a named remove control — and
|
|
815
|
+
// hears selection change as pressed state.
|
|
816
|
+
onUpdateSelected.mockClear();
|
|
817
|
+
const canvas = within(canvasElement);
|
|
818
|
+
|
|
819
|
+
await step(
|
|
820
|
+
'screen-reader: a static chip exposes no role and no name of its own',
|
|
821
|
+
async () => {
|
|
822
|
+
const chip = canvas.getByText('Static chip');
|
|
823
|
+
await expect(chip).toBeVisible();
|
|
824
|
+
await expect(chip).not.toHaveAttribute('role');
|
|
825
|
+
await expect(chip).not.toHaveAttribute('tabindex');
|
|
826
|
+
},
|
|
827
|
+
);
|
|
828
|
+
|
|
829
|
+
await step(
|
|
830
|
+
'screen-reader: a selectable chip is a named toggle button (WCAG 4.1.2)',
|
|
831
|
+
async () => {
|
|
832
|
+
const chip = canvas.getByRole('button', { name: 'Selectable chip' });
|
|
833
|
+
await expect(chip).toHaveAccessibleName('Selectable chip');
|
|
834
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'false');
|
|
835
|
+
},
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
await step(
|
|
839
|
+
'screen-reader: toggling updates the pressed state that is announced',
|
|
840
|
+
async () => {
|
|
841
|
+
const chip = canvas.getByRole('button', { name: 'Selectable chip' });
|
|
842
|
+
await userEvent.click(chip);
|
|
843
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'true');
|
|
844
|
+
},
|
|
845
|
+
);
|
|
846
|
+
|
|
847
|
+
await step(
|
|
848
|
+
'screen-reader: each icon-only remove control has a distinct name (WCAG 4.1.2)',
|
|
849
|
+
async () => {
|
|
850
|
+
for (const name of ['Remove Alpha', 'Remove Beta', 'Remove Combo']) {
|
|
851
|
+
const control = canvas.getByRole('button', { name });
|
|
852
|
+
await expect(control).toHaveAccessibleName(name);
|
|
853
|
+
// The label lives on the control, not on a visible text node.
|
|
854
|
+
await expect(control).toHaveAttribute('aria-label', name);
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
);
|
|
858
|
+
|
|
859
|
+
await step(
|
|
860
|
+
'screen-reader: a remove-only chip exposes exactly one control',
|
|
861
|
+
async () => {
|
|
862
|
+
await expect(
|
|
863
|
+
canvas.queryByRole('button', { name: 'Alpha' }),
|
|
864
|
+
).not.toBeInTheDocument();
|
|
865
|
+
await expect(
|
|
866
|
+
canvas.getByRole('button', { name: 'Remove Alpha' }),
|
|
867
|
+
).toBeVisible();
|
|
868
|
+
},
|
|
869
|
+
);
|
|
870
|
+
},
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
875
|
+
* try 400% reflow (WCAG 1.4.10); chips must stay readable and operable. Hidden
|
|
876
|
+
* test-only story.
|
|
877
|
+
*/
|
|
878
|
+
export const ZoomMagnification: Story = {
|
|
879
|
+
name: 'test - Zoom Magnification',
|
|
880
|
+
tags: ['!dev', '!autodocs'],
|
|
881
|
+
globals: { zoom: '200' },
|
|
882
|
+
parameters: {
|
|
883
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
884
|
+
// already covers magnified snapshots, so skip this one.
|
|
885
|
+
chromatic: { disableSnapshot: true },
|
|
886
|
+
docs: {
|
|
887
|
+
description: {
|
|
888
|
+
story:
|
|
889
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
},
|
|
893
|
+
render: renderTestChips,
|
|
894
|
+
play: async ({ canvasElement, step }) => {
|
|
895
|
+
// Scenario (UiChip): at 200% page zoom the labels stay readable, the chips
|
|
896
|
+
// stay inside the viewport, and both selection and removal still work.
|
|
897
|
+
onRemove.mockClear();
|
|
898
|
+
onUpdateSelected.mockClear();
|
|
899
|
+
const canvas = within(canvasElement);
|
|
900
|
+
|
|
901
|
+
await step(
|
|
902
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
903
|
+
async () => {
|
|
904
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
905
|
+
},
|
|
906
|
+
);
|
|
907
|
+
|
|
908
|
+
await step('zoom: chips stay visible and readable', async () => {
|
|
909
|
+
for (const label of ['Static chip', 'Selectable chip', 'Alpha']) {
|
|
910
|
+
await expect(canvas.getByText(label)).toBeVisible();
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const { left, right } = canvas
|
|
914
|
+
.getByRole('button', { name: 'Selectable chip' })
|
|
915
|
+
.getBoundingClientRect();
|
|
916
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
917
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
await step('zoom: selection remains operable when magnified', async () => {
|
|
921
|
+
const chip = canvas.getByRole('button', { name: 'Selectable chip' });
|
|
922
|
+
await userEvent.click(chip);
|
|
923
|
+
await expect(chip).toHaveAttribute('aria-pressed', 'true');
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
await step('zoom: removal remains operable when magnified', async () => {
|
|
927
|
+
await userEvent.click(
|
|
928
|
+
canvas.getByRole('button', { name: 'Remove Alpha' }),
|
|
929
|
+
);
|
|
930
|
+
await expect(onRemove).toHaveBeenCalledWith('Alpha');
|
|
931
|
+
await waitFor(async () => {
|
|
932
|
+
await expect(canvas.queryByText('Alpha')).toBeNull();
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
},
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
940
|
+
* toolbar. Chips wrap inside the viewport and every interactive target meets
|
|
941
|
+
* the minimum touch-target size (WCAG 2.5.8). Hidden test-only story.
|
|
942
|
+
*/
|
|
943
|
+
export const MobileBreakpoint: Story = {
|
|
944
|
+
name: 'test - Mobile Breakpoint',
|
|
945
|
+
tags: ['!dev', '!autodocs'],
|
|
946
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
947
|
+
parameters: {
|
|
948
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
949
|
+
chromatic: { disableSnapshot: true },
|
|
950
|
+
docs: {
|
|
951
|
+
description: {
|
|
952
|
+
story:
|
|
953
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
954
|
+
},
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
render: renderTestChips,
|
|
958
|
+
play: async ({ canvasElement, step }) => {
|
|
959
|
+
// Scenario (UiChip): at the 320px mobile breakpoint the group wraps rather
|
|
960
|
+
// than scrolling sideways, and every chip and remove control is big enough
|
|
961
|
+
// to tap.
|
|
962
|
+
const canvas = within(canvasElement);
|
|
963
|
+
|
|
964
|
+
await step(
|
|
965
|
+
'mobile: chips stay readable at the 320px breakpoint',
|
|
966
|
+
async () => {
|
|
967
|
+
await expect(canvas.getByText('Static chip')).toBeVisible();
|
|
968
|
+
await expect(
|
|
969
|
+
canvas.getByRole('button', { name: 'Selectable chip' }),
|
|
970
|
+
).toBeVisible();
|
|
971
|
+
},
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
await step(
|
|
975
|
+
'mobile: chips wrap inside the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
976
|
+
async () => {
|
|
977
|
+
for (const chip of canvasElement.querySelectorAll<HTMLElement>(
|
|
978
|
+
'[data-slot="chip"]',
|
|
979
|
+
)) {
|
|
980
|
+
const { left, right } = chip.getBoundingClientRect();
|
|
981
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
982
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
);
|
|
986
|
+
|
|
987
|
+
await step(
|
|
988
|
+
'mobile: every interactive target meets the minimum size (WCAG 2.5.8)',
|
|
989
|
+
async () => {
|
|
990
|
+
// The remove control is the tightest target: it is flush against the
|
|
991
|
+
// chip label, so the 2.5.8 spacing exception cannot rescue it and it
|
|
992
|
+
// has to measure 24px on its own.
|
|
993
|
+
const controls = canvas.getAllByRole('button');
|
|
994
|
+
await expect(controls.length).toBeGreaterThan(0);
|
|
995
|
+
|
|
996
|
+
for (const control of controls) {
|
|
997
|
+
const { width, height } = control.getBoundingClientRect();
|
|
998
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
999
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1000
|
+
}
|
|
1001
|
+
},
|
|
1002
|
+
);
|
|
1003
|
+
},
|
|
250
1004
|
};
|