@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, userEvent, waitFor, within } from 'storybook/test';
|
|
2
3
|
import { ref, computed, watch } from 'vue';
|
|
3
4
|
import { useFilter } from 'reka-ui';
|
|
4
5
|
import UiTagsInput from './UiTagsInput.vue';
|
|
@@ -34,6 +35,16 @@ const meta: Meta<typeof UiTagsInput> = {
|
|
|
34
35
|
control: 'boolean',
|
|
35
36
|
description: 'Disable the tags input',
|
|
36
37
|
},
|
|
38
|
+
addedLabel: {
|
|
39
|
+
control: 'text',
|
|
40
|
+
description:
|
|
41
|
+
'Word appended to a tag value when it is added, announced by the live region',
|
|
42
|
+
},
|
|
43
|
+
removedLabel: {
|
|
44
|
+
control: 'text',
|
|
45
|
+
description:
|
|
46
|
+
'Word appended to a tag value when it is removed, announced by the live region',
|
|
47
|
+
},
|
|
37
48
|
},
|
|
38
49
|
args: {
|
|
39
50
|
disabled: false,
|
|
@@ -44,6 +55,21 @@ export default meta;
|
|
|
44
55
|
|
|
45
56
|
type Story = StoryObj<typeof UiTagsInput>;
|
|
46
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Reads the tags currently rendered, in visual order.
|
|
60
|
+
*
|
|
61
|
+
* Tags are `div`s with no role, deliberately: ARIA prohibits naming a generic
|
|
62
|
+
* element, and a `list` role would be invalid wrapped around the text input.
|
|
63
|
+
* So they are located by `data-slot` rather than by role.
|
|
64
|
+
* @param canvasElement The story's root element.
|
|
65
|
+
* @returns The visible text of each tag.
|
|
66
|
+
*/
|
|
67
|
+
function getTagNames(canvasElement: HTMLElement): string[] {
|
|
68
|
+
return [
|
|
69
|
+
...canvasElement.querySelectorAll('[data-slot="tags-input-item"]'),
|
|
70
|
+
].map((tag) => tag.textContent?.trim() ?? '');
|
|
71
|
+
}
|
|
72
|
+
|
|
47
73
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
48
74
|
import { ref } from 'vue'
|
|
49
75
|
import {
|
|
@@ -102,6 +128,29 @@ export const Default: Story = {
|
|
|
102
128
|
},
|
|
103
129
|
},
|
|
104
130
|
},
|
|
131
|
+
play: async ({ canvasElement, step }) => {
|
|
132
|
+
// Scenario (tag + remove control): what a screen reader encounters when
|
|
133
|
+
// reading an existing set of tags. Non-mutating.
|
|
134
|
+
const canvas = within(canvasElement);
|
|
135
|
+
|
|
136
|
+
await step('screen-reader: each tag displays its value', async () => {
|
|
137
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple', 'Banana']);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
await step(
|
|
141
|
+
'screen-reader: each remove control names the tag it removes (WCAG 4.1.2)',
|
|
142
|
+
async () => {
|
|
143
|
+
// reka names this button after the tag text alone, which reads as a
|
|
144
|
+
// second "Apple" with no hint that it deletes. The wrapper replaces
|
|
145
|
+
// that with an explicit name.
|
|
146
|
+
for (const name of ['Remove Apple', 'Remove Banana']) {
|
|
147
|
+
await expect(
|
|
148
|
+
canvas.getByRole('button', { name }),
|
|
149
|
+
).toBeInTheDocument();
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
},
|
|
105
154
|
};
|
|
106
155
|
|
|
107
156
|
const emptyTemplateSource = `<script setup lang="ts">
|
|
@@ -162,6 +211,25 @@ export const Empty: Story = {
|
|
|
162
211
|
},
|
|
163
212
|
},
|
|
164
213
|
},
|
|
214
|
+
play: async ({ canvasElement, step }) => {
|
|
215
|
+
// Scenario (input field, empty): nothing to remove yet, and the live
|
|
216
|
+
// region must start silent so it only ever speaks on a real change.
|
|
217
|
+
// Non-mutating.
|
|
218
|
+
const canvas = within(canvasElement);
|
|
219
|
+
|
|
220
|
+
await step('screen-reader: the field is an empty textbox', async () => {
|
|
221
|
+
await expect(canvas.getByRole('textbox')).toBeEnabled();
|
|
222
|
+
await expect(getTagNames(canvasElement)).toEqual([]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await step(
|
|
226
|
+
'screen-reader: the live region is silent until something changes (WCAG 4.1.3)',
|
|
227
|
+
async () => {
|
|
228
|
+
// A live region with content on mount would be announced on load.
|
|
229
|
+
await expect(canvas.getByRole('status')).toHaveTextContent('');
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
},
|
|
165
233
|
};
|
|
166
234
|
|
|
167
235
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
@@ -195,7 +263,7 @@ export const Disabled: Story = {
|
|
|
195
263
|
args: {
|
|
196
264
|
disabled: true,
|
|
197
265
|
},
|
|
198
|
-
render: () => ({
|
|
266
|
+
render: (args) => ({
|
|
199
267
|
components: {
|
|
200
268
|
UiTagsInput,
|
|
201
269
|
UiTagsInputInput,
|
|
@@ -205,10 +273,10 @@ export const Disabled: Story = {
|
|
|
205
273
|
},
|
|
206
274
|
setup() {
|
|
207
275
|
const modelValue = ref(['Vue', 'React', 'Angular']);
|
|
208
|
-
return { modelValue };
|
|
276
|
+
return { args, modelValue };
|
|
209
277
|
},
|
|
210
278
|
template: `
|
|
211
|
-
<UiTagsInput v-model="modelValue" class="w-[300px]
|
|
279
|
+
<UiTagsInput v-model="modelValue" class="w-[300px]" :disabled="args.disabled">
|
|
212
280
|
<UiTagsInputItem v-for="item in modelValue" :key="item" :value="item">
|
|
213
281
|
<UiTagsInputItemText />
|
|
214
282
|
<UiTagsInputItemDelete />
|
|
@@ -221,6 +289,10 @@ export const Disabled: Story = {
|
|
|
221
289
|
parameters: {
|
|
222
290
|
a11y: {
|
|
223
291
|
config: {
|
|
292
|
+
// Disabled tags are dimmed to 50% and so fail the contrast ratio.
|
|
293
|
+
// WCAG 1.4.3 exempts inactive controls, but axe cannot tell that a
|
|
294
|
+
// `div[data-disabled]` is inactive, so the rule is switched off here
|
|
295
|
+
// rather than reported as a violation we would have to ignore.
|
|
224
296
|
rules: [{ id: 'color-contrast', enabled: false }],
|
|
225
297
|
},
|
|
226
298
|
},
|
|
@@ -230,6 +302,44 @@ export const Disabled: Story = {
|
|
|
230
302
|
},
|
|
231
303
|
},
|
|
232
304
|
},
|
|
305
|
+
play: async ({ canvasElement, step }) => {
|
|
306
|
+
// Scenario (input field, disabled): the field must refuse edits from both
|
|
307
|
+
// pointer and keyboard while its tags stay readable. Non-mutating — every
|
|
308
|
+
// attempted edit is expected to be a no-op.
|
|
309
|
+
const canvas = within(canvasElement);
|
|
310
|
+
const input = canvas.getByRole('textbox');
|
|
311
|
+
|
|
312
|
+
await step('screen-reader: the field is exposed as disabled', async () => {
|
|
313
|
+
await expect(input).toBeDisabled();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
await step('interaction: a disabled field cannot be edited', async () => {
|
|
317
|
+
await userEvent.click(input);
|
|
318
|
+
await expect(input).not.toHaveFocus();
|
|
319
|
+
|
|
320
|
+
// Typed into the document rather than the field, so nothing is added.
|
|
321
|
+
await userEvent.keyboard('Svelte{Enter}');
|
|
322
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
323
|
+
'Vue',
|
|
324
|
+
'React',
|
|
325
|
+
'Angular',
|
|
326
|
+
]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
await step(
|
|
330
|
+
'interaction: a disabled field does not remove tags either',
|
|
331
|
+
async () => {
|
|
332
|
+
await userEvent.click(
|
|
333
|
+
canvas.getByRole('button', { name: 'Remove Vue' }),
|
|
334
|
+
);
|
|
335
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
336
|
+
'Vue',
|
|
337
|
+
'React',
|
|
338
|
+
'Angular',
|
|
339
|
+
]);
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
},
|
|
233
343
|
};
|
|
234
344
|
|
|
235
345
|
const maxTagsTemplateSource = `<script setup lang="ts">
|
|
@@ -290,6 +400,35 @@ export const MaxTags: Story = {
|
|
|
290
400
|
},
|
|
291
401
|
},
|
|
292
402
|
},
|
|
403
|
+
play: async ({ canvasElement, step }) => {
|
|
404
|
+
// Scenario (input field with a limit): `max` is enforced silently, so the
|
|
405
|
+
// only thing asserted here is that the field and its tags stay correctly
|
|
406
|
+
// named while the limit applies. Non-mutating.
|
|
407
|
+
const canvas = within(canvasElement);
|
|
408
|
+
|
|
409
|
+
await step(
|
|
410
|
+
'screen-reader: tags and remove controls are named below the limit',
|
|
411
|
+
async () => {
|
|
412
|
+
await expect(getTagNames(canvasElement)).toEqual(['Tag 1', 'Tag 2']);
|
|
413
|
+
await expect(
|
|
414
|
+
canvas.getByRole('button', { name: 'Remove Tag 1' }),
|
|
415
|
+
).toBeInTheDocument();
|
|
416
|
+
},
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
await step(
|
|
420
|
+
'interaction: the limit is not exposed as a disabled field',
|
|
421
|
+
async () => {
|
|
422
|
+
// reka never disables the field at the limit — it rejects the add and
|
|
423
|
+
// emits `invalid`. Enforcement itself is covered by the test-only Max
|
|
424
|
+
// Tags story, which has to mutate the model to reach the limit.
|
|
425
|
+
await expect(canvas.getByRole('textbox')).toBeEnabled();
|
|
426
|
+
await expect(canvas.getByRole('textbox')).not.toHaveAttribute(
|
|
427
|
+
'readonly',
|
|
428
|
+
);
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
},
|
|
293
432
|
};
|
|
294
433
|
|
|
295
434
|
const emailsTemplateSource = `<script setup lang="ts">
|
|
@@ -350,6 +489,23 @@ export const EmailInput: Story = {
|
|
|
350
489
|
},
|
|
351
490
|
},
|
|
352
491
|
},
|
|
492
|
+
play: async ({ canvasElement, step }) => {
|
|
493
|
+
// Scenario (remove control): tag values that are not single words still
|
|
494
|
+
// produce an unambiguous name for their remove control. Non-mutating.
|
|
495
|
+
const canvas = within(canvasElement);
|
|
496
|
+
|
|
497
|
+
await step(
|
|
498
|
+
'screen-reader: remove controls name the full email address',
|
|
499
|
+
async () => {
|
|
500
|
+
await expect(
|
|
501
|
+
canvas.getByRole('button', { name: 'Remove john@example.com' }),
|
|
502
|
+
).toBeInTheDocument();
|
|
503
|
+
await expect(
|
|
504
|
+
canvas.getByRole('button', { name: 'Remove jane@example.com' }),
|
|
505
|
+
).toBeInTheDocument();
|
|
506
|
+
},
|
|
507
|
+
);
|
|
508
|
+
},
|
|
353
509
|
};
|
|
354
510
|
|
|
355
511
|
const withListboxTemplateSource = `<script setup lang="ts">
|
|
@@ -420,7 +576,7 @@ watch(searchTerm, (value) => {
|
|
|
420
576
|
</UiListboxFilter>
|
|
421
577
|
|
|
422
578
|
<UiPopoverTrigger as-child>
|
|
423
|
-
<UiButton size="icon-sm" variant="ghost" class="order-last self-start ml-auto">
|
|
579
|
+
<UiButton size="icon-sm" variant="ghost" class="order-last self-start ml-auto" aria-label="Open framework suggestions">
|
|
424
580
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
425
581
|
<path d="m6 9 6 6 6-6"/>
|
|
426
582
|
</svg>
|
|
@@ -564,4 +720,694 @@ export const WithListbox: Story = {
|
|
|
564
720
|
},
|
|
565
721
|
},
|
|
566
722
|
},
|
|
723
|
+
play: async ({ canvasElement, step }) => {
|
|
724
|
+
// Scenario (tags input composed with a popover listbox): the extra
|
|
725
|
+
// suggestions trigger sits inside the field, so it must not be the only
|
|
726
|
+
// unnamed control in the row. Non-mutating — opening the popover would
|
|
727
|
+
// move focus.
|
|
728
|
+
const canvas = within(canvasElement);
|
|
729
|
+
|
|
730
|
+
await step(
|
|
731
|
+
'screen-reader: every control in the composed field is named',
|
|
732
|
+
async () => {
|
|
733
|
+
await expect(getTagNames(canvasElement)).toEqual(['Nuxt', 'Remix']);
|
|
734
|
+
await expect(
|
|
735
|
+
canvas.getByRole('button', { name: 'Remove Nuxt' }),
|
|
736
|
+
).toBeInTheDocument();
|
|
737
|
+
await expect(
|
|
738
|
+
canvas.getByRole('button', { name: 'Open framework suggestions' }),
|
|
739
|
+
).toBeInTheDocument();
|
|
740
|
+
},
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
await step(
|
|
744
|
+
'keyboard: the suggestions trigger is a real tab stop',
|
|
745
|
+
async () => {
|
|
746
|
+
// Asserted by attribute rather than by tabbing, so this story keeps a
|
|
747
|
+
// focus-free Chromatic snapshot. The absence of the attribute is what
|
|
748
|
+
// matters: reka gives the remove controls `tabindex="-1"`, and this
|
|
749
|
+
// trigger must not inherit that treatment.
|
|
750
|
+
await expect(
|
|
751
|
+
canvas.getByRole('button', { name: 'Open framework suggestions' }),
|
|
752
|
+
).not.toHaveAttribute('tabindex');
|
|
753
|
+
},
|
|
754
|
+
);
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Accessibility guidance for labelling the field, naming remove controls,
|
|
760
|
+
* announcing changes, keyboard operation, and contrast.
|
|
761
|
+
*/
|
|
762
|
+
export const Accessibility: Story = {
|
|
763
|
+
render: () => ({
|
|
764
|
+
components: {
|
|
765
|
+
UiTagsInput,
|
|
766
|
+
UiTagsInputInput,
|
|
767
|
+
UiTagsInputItem,
|
|
768
|
+
UiTagsInputItemText,
|
|
769
|
+
UiTagsInputItemDelete,
|
|
770
|
+
},
|
|
771
|
+
setup() {
|
|
772
|
+
const tags = ref(['Apple', 'Banana']);
|
|
773
|
+
const accessibleTags = ref(['Apple', 'Banana']);
|
|
774
|
+
return { tags, accessibleTags };
|
|
775
|
+
},
|
|
776
|
+
template: `
|
|
777
|
+
<section class="flex flex-col gap-6 p-4">
|
|
778
|
+
<div>
|
|
779
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
780
|
+
Accessibility
|
|
781
|
+
</h2>
|
|
782
|
+
</div>
|
|
783
|
+
|
|
784
|
+
<div class="flex flex-col gap-6">
|
|
785
|
+
<div class="flex flex-col gap-2">
|
|
786
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
787
|
+
Give the field a real label
|
|
788
|
+
</h3>
|
|
789
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
790
|
+
The placeholder is not a label. Associate a
|
|
791
|
+
<code>UiLabel</code> with the inner input (or pass an
|
|
792
|
+
<code>aria-label</code>) so the field keeps its name once the
|
|
793
|
+
user starts typing and the placeholder disappears (WCAG 3.3.2).
|
|
794
|
+
</p>
|
|
795
|
+
</div>
|
|
796
|
+
|
|
797
|
+
<div class="flex flex-col gap-2">
|
|
798
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
799
|
+
Remove controls name their tag
|
|
800
|
+
</h3>
|
|
801
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
802
|
+
Each delete button is announced as
|
|
803
|
+
<code>Remove <tag></code>, so it is distinguishable from
|
|
804
|
+
the tag beside it and from every other remove control. Pass
|
|
805
|
+
<code>label</code> to translate or reword it.
|
|
806
|
+
</p>
|
|
807
|
+
</div>
|
|
808
|
+
|
|
809
|
+
<div class="flex flex-col gap-2">
|
|
810
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
811
|
+
Additions and removals are announced
|
|
812
|
+
</h3>
|
|
813
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
814
|
+
Adding or removing a tag changes the DOM without moving focus,
|
|
815
|
+
which a screen reader would otherwise pass over in silence. The
|
|
816
|
+
component announces the change through a polite live region
|
|
817
|
+
(WCAG 4.1.3). Use <code>added-label</code> and
|
|
818
|
+
<code>removed-label</code> to translate the wording.
|
|
819
|
+
</p>
|
|
820
|
+
</div>
|
|
821
|
+
|
|
822
|
+
<div class="flex flex-col gap-2">
|
|
823
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
824
|
+
Tags are exposed as text, not as list items
|
|
825
|
+
</h3>
|
|
826
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
827
|
+
Each tag is a generic element, so its value reaches assistive
|
|
828
|
+
technology as plain text. A <code>list</code> role is not an
|
|
829
|
+
option here because the text input shares the container and
|
|
830
|
+
would be an invalid child. axe reports one needs-review result
|
|
831
|
+
on the tag (<code>aria-prohibited-attr</code>) for an
|
|
832
|
+
<code>aria-labelledby</code> that browsers ignore; it is
|
|
833
|
+
reviewed and expected, not an outstanding failure.
|
|
834
|
+
</p>
|
|
835
|
+
</div>
|
|
836
|
+
|
|
837
|
+
<div class="flex flex-col gap-2">
|
|
838
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
839
|
+
Keyboard model
|
|
840
|
+
</h3>
|
|
841
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
842
|
+
Only the text field is a tab stop; tags are reached with the
|
|
843
|
+
arrow keys and removed with <kbd>Delete</kbd> or
|
|
844
|
+
<kbd>Backspace</kbd>. Because tag selection moves reka's internal
|
|
845
|
+
index rather than DOM focus, never rely on a visible focus ring
|
|
846
|
+
alone to tell the user which tag is selected.
|
|
847
|
+
</p>
|
|
848
|
+
</div>
|
|
849
|
+
|
|
850
|
+
<div class="flex flex-col gap-2">
|
|
851
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
852
|
+
Enable accessibility theme
|
|
853
|
+
</h3>
|
|
854
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
855
|
+
When accessibility is required, enable our accessibility theme.
|
|
856
|
+
This increases contrast and makes sure there are no color
|
|
857
|
+
contrast issues.
|
|
858
|
+
</p>
|
|
859
|
+
</div>
|
|
860
|
+
</div>
|
|
861
|
+
|
|
862
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
863
|
+
<div class="flex flex-col gap-3">
|
|
864
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
865
|
+
Default
|
|
866
|
+
</h3>
|
|
867
|
+
<div class="flex flex-col gap-4 border border-border-surface-default p-6">
|
|
868
|
+
<UiTagsInput v-model="tags">
|
|
869
|
+
<UiTagsInputItem v-for="item in tags" :key="item" :value="item">
|
|
870
|
+
<UiTagsInputItemText />
|
|
871
|
+
<UiTagsInputItemDelete />
|
|
872
|
+
</UiTagsInputItem>
|
|
873
|
+
<UiTagsInputInput aria-label="Fruits" placeholder="Fruits..." />
|
|
874
|
+
</UiTagsInput>
|
|
875
|
+
</div>
|
|
876
|
+
</div>
|
|
877
|
+
|
|
878
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
879
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
880
|
+
Accessible
|
|
881
|
+
</h3>
|
|
882
|
+
<div class="flex flex-col gap-4 border border-border-surface-default p-6">
|
|
883
|
+
<UiTagsInput v-model="accessibleTags">
|
|
884
|
+
<UiTagsInputItem v-for="item in accessibleTags" :key="item" :value="item">
|
|
885
|
+
<UiTagsInputItemText />
|
|
886
|
+
<UiTagsInputItemDelete />
|
|
887
|
+
</UiTagsInputItem>
|
|
888
|
+
<UiTagsInputInput aria-label="Fruits" placeholder="Fruits..." />
|
|
889
|
+
</UiTagsInput>
|
|
890
|
+
</div>
|
|
891
|
+
</div>
|
|
892
|
+
</div>
|
|
893
|
+
</section>
|
|
894
|
+
`,
|
|
895
|
+
}),
|
|
896
|
+
tags: ['!autodocs'],
|
|
897
|
+
parameters: {
|
|
898
|
+
a11y: { test: 'off' },
|
|
899
|
+
chromatic: {
|
|
900
|
+
disableSnapshot: true,
|
|
901
|
+
},
|
|
902
|
+
docs: {
|
|
903
|
+
canvas: {
|
|
904
|
+
sourceState: 'none',
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
},
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
/*
|
|
911
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
912
|
+
* Interaction & accessibility tests (play functions)
|
|
913
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
914
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
915
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
916
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
917
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
918
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
919
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2, 4.1.3)
|
|
920
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
921
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
922
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
923
|
+
* an `a11y:` prefix.
|
|
924
|
+
*
|
|
925
|
+
* The shared render below labels the field, which the visible stories leave to
|
|
926
|
+
* a placeholder. That is deliberate: these tests assert the accessible name of
|
|
927
|
+
* the textbox, and a placeholder-derived name is exactly what the Accessibility
|
|
928
|
+
* story warns against relying on.
|
|
929
|
+
*/
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* The tags input the test stories drive: two starting tags and a labelled
|
|
933
|
+
* field, wide enough that the tags and the input share one row.
|
|
934
|
+
* @returns Vue component options for a story `render` function.
|
|
935
|
+
*/
|
|
936
|
+
function renderTestTagsInput() {
|
|
937
|
+
return {
|
|
938
|
+
components: {
|
|
939
|
+
UiTagsInput,
|
|
940
|
+
UiTagsInputInput,
|
|
941
|
+
UiTagsInputItem,
|
|
942
|
+
UiTagsInputItemText,
|
|
943
|
+
UiTagsInputItemDelete,
|
|
944
|
+
},
|
|
945
|
+
setup() {
|
|
946
|
+
const tags = ref(['Apple', 'Banana']);
|
|
947
|
+
return { tags };
|
|
948
|
+
},
|
|
949
|
+
template: `
|
|
950
|
+
<div class="max-w-sm">
|
|
951
|
+
<label for="test-tags" class="mb-1.5 block label-14-medium">Fruits</label>
|
|
952
|
+
<UiTagsInput v-model="tags">
|
|
953
|
+
<UiTagsInputItem v-for="item in tags" :key="item" :value="item">
|
|
954
|
+
<UiTagsInputItemText />
|
|
955
|
+
<UiTagsInputItemDelete />
|
|
956
|
+
</UiTagsInputItem>
|
|
957
|
+
<UiTagsInputInput id="test-tags" placeholder="Add a fruit..." />
|
|
958
|
+
</UiTagsInput>
|
|
959
|
+
</div>
|
|
960
|
+
`,
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Typing adds a tag and the remove control deletes one. Hidden test-only story.
|
|
966
|
+
*/
|
|
967
|
+
export const TagInteraction: Story = {
|
|
968
|
+
name: 'test - Tag Interaction',
|
|
969
|
+
tags: ['!dev', '!autodocs'],
|
|
970
|
+
parameters: {
|
|
971
|
+
// Tags are added and removed during the play function.
|
|
972
|
+
chromatic: { disableSnapshot: true },
|
|
973
|
+
docs: {
|
|
974
|
+
description: {
|
|
975
|
+
story:
|
|
976
|
+
'Type a value and press Enter to add a tag, then use a remove control to delete one.',
|
|
977
|
+
},
|
|
978
|
+
},
|
|
979
|
+
},
|
|
980
|
+
render: renderTestTagsInput,
|
|
981
|
+
play: async ({ canvasElement, step }) => {
|
|
982
|
+
// Scenario (input field + remove control): the core add/remove loop a
|
|
983
|
+
// pointer user performs, including that removal targets the right tag.
|
|
984
|
+
const canvas = within(canvasElement);
|
|
985
|
+
const field = canvas.getByRole('textbox', { name: 'Fruits' });
|
|
986
|
+
|
|
987
|
+
await step('interaction: typing a value adds a tag', async () => {
|
|
988
|
+
await userEvent.click(field);
|
|
989
|
+
await userEvent.type(field, 'Cherry{Enter}');
|
|
990
|
+
|
|
991
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
992
|
+
'Apple',
|
|
993
|
+
'Banana',
|
|
994
|
+
'Cherry',
|
|
995
|
+
]);
|
|
996
|
+
// The field clears so the next value can be typed straight away.
|
|
997
|
+
await expect(field).toHaveValue('');
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
await step(
|
|
1001
|
+
'interaction: the remove control deletes only its own tag',
|
|
1002
|
+
async () => {
|
|
1003
|
+
await userEvent.click(
|
|
1004
|
+
canvas.getByRole('button', { name: 'Remove Banana' }),
|
|
1005
|
+
);
|
|
1006
|
+
|
|
1007
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple', 'Cherry']);
|
|
1008
|
+
},
|
|
1009
|
+
);
|
|
1010
|
+
|
|
1011
|
+
await step('interaction: the last tag can be removed', async () => {
|
|
1012
|
+
await userEvent.click(
|
|
1013
|
+
canvas.getByRole('button', { name: 'Remove Apple' }),
|
|
1014
|
+
);
|
|
1015
|
+
await userEvent.click(
|
|
1016
|
+
canvas.getByRole('button', { name: 'Remove Cherry' }),
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
await expect(getTagNames(canvasElement)).toEqual([]);
|
|
1020
|
+
});
|
|
1021
|
+
},
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* The field is reachable with Tab, and tags can be added and removed entirely
|
|
1026
|
+
* from the keyboard. Hidden test-only story.
|
|
1027
|
+
*/
|
|
1028
|
+
export const KeyboardNavigation: Story = {
|
|
1029
|
+
name: 'test - Keyboard Navigation',
|
|
1030
|
+
tags: ['!dev', '!autodocs'],
|
|
1031
|
+
parameters: {
|
|
1032
|
+
// Focus moves and tags change during the play function.
|
|
1033
|
+
chromatic: { disableSnapshot: true },
|
|
1034
|
+
docs: {
|
|
1035
|
+
description: {
|
|
1036
|
+
story:
|
|
1037
|
+
'Tab to the field, type to add, then use the arrow keys plus Delete or Backspace to remove.',
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
render: renderTestTagsInput,
|
|
1042
|
+
play: async ({ canvasElement, step }) => {
|
|
1043
|
+
// Scenario (input field + remove control, keyboard only): reka gives the
|
|
1044
|
+
// remove buttons `tabindex="-1"` on purpose, so removal has to be reachable
|
|
1045
|
+
// some other way or the control is keyboard-inoperable (WCAG 2.1.1).
|
|
1046
|
+
const canvas = within(canvasElement);
|
|
1047
|
+
const field = canvas.getByRole('textbox', { name: 'Fruits' });
|
|
1048
|
+
|
|
1049
|
+
await step('keyboard: Tab reaches the field (WCAG 2.4.3)', async () => {
|
|
1050
|
+
await userEvent.tab();
|
|
1051
|
+
await expect(field).toHaveFocus();
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
await step(
|
|
1055
|
+
'keyboard: the remove controls are deliberately not tab stops',
|
|
1056
|
+
async () => {
|
|
1057
|
+
// Guards the design: tabbing past the field must leave the component
|
|
1058
|
+
// entirely rather than walking one dead stop per tag.
|
|
1059
|
+
for (const name of ['Remove Apple', 'Remove Banana']) {
|
|
1060
|
+
await expect(canvas.getByRole('button', { name })).toHaveAttribute(
|
|
1061
|
+
'tabindex',
|
|
1062
|
+
'-1',
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
await userEvent.tab();
|
|
1067
|
+
await expect(field).not.toHaveFocus();
|
|
1068
|
+
},
|
|
1069
|
+
);
|
|
1070
|
+
|
|
1071
|
+
await step('keyboard: a tag can be added from the keyboard', async () => {
|
|
1072
|
+
field.focus();
|
|
1073
|
+
await userEvent.keyboard('Cherry{Enter}');
|
|
1074
|
+
|
|
1075
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
1076
|
+
'Apple',
|
|
1077
|
+
'Banana',
|
|
1078
|
+
'Cherry',
|
|
1079
|
+
]);
|
|
1080
|
+
});
|
|
1081
|
+
|
|
1082
|
+
await step(
|
|
1083
|
+
'keyboard: arrow keys select a tag and Delete removes it (WCAG 2.1.1)',
|
|
1084
|
+
async () => {
|
|
1085
|
+
await userEvent.keyboard('{ArrowLeft}');
|
|
1086
|
+
await userEvent.keyboard('{Delete}');
|
|
1087
|
+
|
|
1088
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple', 'Banana']);
|
|
1089
|
+
},
|
|
1090
|
+
);
|
|
1091
|
+
|
|
1092
|
+
await step(
|
|
1093
|
+
'keyboard: Backspace selects the last tag, then removes it',
|
|
1094
|
+
async () => {
|
|
1095
|
+
// Blurring clears reka's tag selection, which the step above leaves
|
|
1096
|
+
// pointing at a neighbour of the tag it deleted. Without this, the
|
|
1097
|
+
// first Backspace below would delete instead of select, and the step
|
|
1098
|
+
// would silently depend on the order of the ones before it.
|
|
1099
|
+
field.blur();
|
|
1100
|
+
field.focus();
|
|
1101
|
+
|
|
1102
|
+
// Two presses by design: the first only selects the last tag, so a
|
|
1103
|
+
// stray Backspace in an empty field cannot destroy a tag outright.
|
|
1104
|
+
await userEvent.keyboard('{Backspace}');
|
|
1105
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple', 'Banana']);
|
|
1106
|
+
|
|
1107
|
+
await userEvent.keyboard('{Backspace}');
|
|
1108
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple']);
|
|
1109
|
+
|
|
1110
|
+
// Selection moves to the neighbour, so the field empties from here.
|
|
1111
|
+
await userEvent.keyboard('{Backspace}');
|
|
1112
|
+
await expect(getTagNames(canvasElement)).toEqual([]);
|
|
1113
|
+
},
|
|
1114
|
+
);
|
|
1115
|
+
},
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Screen-reader semantics: the field and remove controls are named, and every
|
|
1120
|
+
* addition and removal is announced (WCAG 4.1.2, 4.1.3). Hidden test-only
|
|
1121
|
+
* story.
|
|
1122
|
+
*/
|
|
1123
|
+
export const ScreenReader: Story = {
|
|
1124
|
+
name: 'test - Screen Reader',
|
|
1125
|
+
tags: ['!dev', '!autodocs'],
|
|
1126
|
+
parameters: {
|
|
1127
|
+
// Tags are added and removed during the play function.
|
|
1128
|
+
chromatic: { disableSnapshot: true },
|
|
1129
|
+
docs: {
|
|
1130
|
+
description: {
|
|
1131
|
+
story:
|
|
1132
|
+
'Verifies the names assistive technology reads and the live-region announcements.',
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
},
|
|
1136
|
+
render: renderTestTagsInput,
|
|
1137
|
+
play: async ({ canvasElement, step }) => {
|
|
1138
|
+
// Scenario (all three subcomponents): what a screen reader user hears.
|
|
1139
|
+
// Adding and removing tags moves nothing and clears the field silently, so
|
|
1140
|
+
// without a live region the user gets no confirmation at all.
|
|
1141
|
+
const canvas = within(canvasElement);
|
|
1142
|
+
const field = canvas.getByRole('textbox', { name: 'Fruits' });
|
|
1143
|
+
|
|
1144
|
+
await step(
|
|
1145
|
+
'screen-reader: the field is a textbox named by its label, not its placeholder',
|
|
1146
|
+
async () => {
|
|
1147
|
+
await expect(field).toHaveAccessibleName('Fruits');
|
|
1148
|
+
await expect(field).toHaveAttribute('placeholder', 'Add a fruit...');
|
|
1149
|
+
},
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
await step('screen-reader: each tag displays its value', async () => {
|
|
1153
|
+
await expect(getTagNames(canvasElement)).toEqual(['Apple', 'Banana']);
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
await step(
|
|
1157
|
+
'screen-reader: remove controls are buttons with distinct names (WCAG 4.1.2)',
|
|
1158
|
+
async () => {
|
|
1159
|
+
// An icon-only button with no name, or one named after the tag alone,
|
|
1160
|
+
// is indistinguishable from its neighbour in a list of controls.
|
|
1161
|
+
for (const name of ['Remove Apple', 'Remove Banana']) {
|
|
1162
|
+
const button = canvas.getByRole('button', { name });
|
|
1163
|
+
await expect(button).toHaveAccessibleName(name);
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
);
|
|
1167
|
+
|
|
1168
|
+
await step(
|
|
1169
|
+
'screen-reader: adding a tag is announced (WCAG 4.1.3 Status Messages)',
|
|
1170
|
+
async () => {
|
|
1171
|
+
const status = canvas.getByRole('status');
|
|
1172
|
+
await expect(status).toHaveAttribute('aria-live', 'polite');
|
|
1173
|
+
|
|
1174
|
+
field.focus();
|
|
1175
|
+
await userEvent.keyboard('Cherry{Enter}');
|
|
1176
|
+
|
|
1177
|
+
await waitFor(async () => {
|
|
1178
|
+
await expect(status).toHaveTextContent('Cherry added');
|
|
1179
|
+
});
|
|
1180
|
+
},
|
|
1181
|
+
);
|
|
1182
|
+
|
|
1183
|
+
await step('screen-reader: removing a tag is announced', async () => {
|
|
1184
|
+
await userEvent.click(
|
|
1185
|
+
canvas.getByRole('button', { name: 'Remove Apple' }),
|
|
1186
|
+
);
|
|
1187
|
+
|
|
1188
|
+
await waitFor(async () => {
|
|
1189
|
+
await expect(canvas.getByRole('status')).toHaveTextContent(
|
|
1190
|
+
'Apple removed',
|
|
1191
|
+
);
|
|
1192
|
+
});
|
|
1193
|
+
});
|
|
1194
|
+
},
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1199
|
+
* try 400% reflow (WCAG 1.4.10); the field and tags must stay usable. Hidden
|
|
1200
|
+
* test-only story.
|
|
1201
|
+
*/
|
|
1202
|
+
export const ZoomMagnification: Story = {
|
|
1203
|
+
name: 'test - Zoom Magnification',
|
|
1204
|
+
tags: ['!dev', '!autodocs'],
|
|
1205
|
+
globals: { zoom: '200' },
|
|
1206
|
+
parameters: {
|
|
1207
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
1208
|
+
// already covers magnified snapshots, so skip this one.
|
|
1209
|
+
chromatic: { disableSnapshot: true },
|
|
1210
|
+
docs: {
|
|
1211
|
+
description: {
|
|
1212
|
+
story:
|
|
1213
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1214
|
+
},
|
|
1215
|
+
},
|
|
1216
|
+
},
|
|
1217
|
+
render: renderTestTagsInput,
|
|
1218
|
+
play: async ({ canvasElement, step }) => {
|
|
1219
|
+
// Scenario (input field + tags): magnified text must not push the tags or
|
|
1220
|
+
// their remove controls out of the viewport, and adding must still work.
|
|
1221
|
+
const canvas = within(canvasElement);
|
|
1222
|
+
|
|
1223
|
+
await step(
|
|
1224
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1225
|
+
async () => {
|
|
1226
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1227
|
+
},
|
|
1228
|
+
);
|
|
1229
|
+
|
|
1230
|
+
await step('zoom: tags and remove controls stay on screen', async () => {
|
|
1231
|
+
const elements = [
|
|
1232
|
+
canvas.getByRole('textbox', { name: 'Fruits' }),
|
|
1233
|
+
canvas.getByRole('button', { name: 'Remove Apple' }),
|
|
1234
|
+
canvas.getByRole('button', { name: 'Remove Banana' }),
|
|
1235
|
+
];
|
|
1236
|
+
|
|
1237
|
+
for (const element of elements) {
|
|
1238
|
+
await expect(element).toBeVisible();
|
|
1239
|
+
|
|
1240
|
+
const { left, right } = element.getBoundingClientRect();
|
|
1241
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
1242
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
await step('zoom: the field is still operable when magnified', async () => {
|
|
1247
|
+
const field = canvas.getByRole('textbox', { name: 'Fruits' });
|
|
1248
|
+
await userEvent.click(field);
|
|
1249
|
+
await userEvent.type(field, 'Cherry{Enter}');
|
|
1250
|
+
|
|
1251
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
1252
|
+
'Apple',
|
|
1253
|
+
'Banana',
|
|
1254
|
+
'Cherry',
|
|
1255
|
+
]);
|
|
1256
|
+
});
|
|
1257
|
+
},
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1262
|
+
* toolbar. Tags wrap inside the viewport and remove controls stay tappable.
|
|
1263
|
+
* Hidden test-only story.
|
|
1264
|
+
*/
|
|
1265
|
+
export const MobileBreakpoint: Story = {
|
|
1266
|
+
name: 'test - Mobile Breakpoint',
|
|
1267
|
+
tags: ['!dev', '!autodocs'],
|
|
1268
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1269
|
+
parameters: {
|
|
1270
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
1271
|
+
chromatic: { disableSnapshot: true },
|
|
1272
|
+
docs: {
|
|
1273
|
+
description: {
|
|
1274
|
+
story:
|
|
1275
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1276
|
+
},
|
|
1277
|
+
},
|
|
1278
|
+
},
|
|
1279
|
+
render: renderTestTagsInput,
|
|
1280
|
+
play: async ({ canvasElement, step }) => {
|
|
1281
|
+
// Scenario (tag + remove control on touch): the remove buttons are the
|
|
1282
|
+
// smallest targets in the component and sit flush against the tag text and
|
|
1283
|
+
// the input, so the WCAG 2.5.8 spacing exception does not rescue them.
|
|
1284
|
+
const canvas = within(canvasElement);
|
|
1285
|
+
|
|
1286
|
+
await step(
|
|
1287
|
+
'mobile: the field and tags fit the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
1288
|
+
async () => {
|
|
1289
|
+
const elements = [
|
|
1290
|
+
canvas.getByRole('textbox', { name: 'Fruits' }),
|
|
1291
|
+
canvas.getByRole('button', { name: 'Remove Apple' }),
|
|
1292
|
+
canvas.getByRole('button', { name: 'Remove Banana' }),
|
|
1293
|
+
];
|
|
1294
|
+
|
|
1295
|
+
for (const element of elements) {
|
|
1296
|
+
await expect(element).toBeVisible();
|
|
1297
|
+
const { left, right } = element.getBoundingClientRect();
|
|
1298
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
1299
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
1300
|
+
}
|
|
1301
|
+
},
|
|
1302
|
+
);
|
|
1303
|
+
|
|
1304
|
+
await step(
|
|
1305
|
+
'mobile: remove controls meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1306
|
+
async () => {
|
|
1307
|
+
for (const name of ['Remove Apple', 'Remove Banana']) {
|
|
1308
|
+
const { width, height } = canvas
|
|
1309
|
+
.getByRole('button', { name })
|
|
1310
|
+
.getBoundingClientRect();
|
|
1311
|
+
|
|
1312
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1313
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
);
|
|
1317
|
+
|
|
1318
|
+
await step('mobile: tapping a remove control deletes its tag', async () => {
|
|
1319
|
+
await userEvent.click(
|
|
1320
|
+
canvas.getByRole('button', { name: 'Remove Apple' }),
|
|
1321
|
+
);
|
|
1322
|
+
|
|
1323
|
+
await expect(getTagNames(canvasElement)).toEqual(['Banana']);
|
|
1324
|
+
});
|
|
1325
|
+
},
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* The `max` limit is enforced on add and rejects silently. Hidden test-only
|
|
1330
|
+
* story.
|
|
1331
|
+
*/
|
|
1332
|
+
export const MaxTagsLimit: Story = {
|
|
1333
|
+
name: 'test - Max Tags',
|
|
1334
|
+
tags: ['!dev', '!autodocs'],
|
|
1335
|
+
parameters: {
|
|
1336
|
+
// Tags are added during the play function.
|
|
1337
|
+
chromatic: { disableSnapshot: true },
|
|
1338
|
+
docs: {
|
|
1339
|
+
description: {
|
|
1340
|
+
story:
|
|
1341
|
+
'Adds tags up to the limit of three, then attempts one more to check the limit holds.',
|
|
1342
|
+
},
|
|
1343
|
+
},
|
|
1344
|
+
},
|
|
1345
|
+
render: () => ({
|
|
1346
|
+
components: {
|
|
1347
|
+
UiTagsInput,
|
|
1348
|
+
UiTagsInputInput,
|
|
1349
|
+
UiTagsInputItem,
|
|
1350
|
+
UiTagsInputItemText,
|
|
1351
|
+
UiTagsInputItemDelete,
|
|
1352
|
+
},
|
|
1353
|
+
setup() {
|
|
1354
|
+
const tags = ref(['Tag 1', 'Tag 2']);
|
|
1355
|
+
return { tags };
|
|
1356
|
+
},
|
|
1357
|
+
template: `
|
|
1358
|
+
<div class="max-w-sm">
|
|
1359
|
+
<label for="max-tags" class="mb-1.5 block label-14-medium">Tags</label>
|
|
1360
|
+
<UiTagsInput v-model="tags" :max="3">
|
|
1361
|
+
<UiTagsInputItem v-for="item in tags" :key="item" :value="item">
|
|
1362
|
+
<UiTagsInputItemText />
|
|
1363
|
+
<UiTagsInputItemDelete />
|
|
1364
|
+
</UiTagsInputItem>
|
|
1365
|
+
<UiTagsInputInput id="max-tags" placeholder="Max 3 tags..." />
|
|
1366
|
+
</UiTagsInput>
|
|
1367
|
+
</div>
|
|
1368
|
+
`,
|
|
1369
|
+
}),
|
|
1370
|
+
play: async ({ canvasElement, step }) => {
|
|
1371
|
+
// Scenario (input field with a limit): reaching `max` must stop the add
|
|
1372
|
+
// without disabling the field or discarding what the user typed.
|
|
1373
|
+
const canvas = within(canvasElement);
|
|
1374
|
+
const field = canvas.getByRole('textbox', { name: 'Tags' });
|
|
1375
|
+
|
|
1376
|
+
await step('interaction: the last slot can still be filled', async () => {
|
|
1377
|
+
await userEvent.type(field, 'Tag 3{Enter}');
|
|
1378
|
+
|
|
1379
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
1380
|
+
'Tag 1',
|
|
1381
|
+
'Tag 2',
|
|
1382
|
+
'Tag 3',
|
|
1383
|
+
]);
|
|
1384
|
+
await expect(field).toHaveValue('');
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
await step(
|
|
1388
|
+
'interaction: a tag past the limit is rejected, not added',
|
|
1389
|
+
async () => {
|
|
1390
|
+
await userEvent.type(field, 'Tag 4{Enter}');
|
|
1391
|
+
|
|
1392
|
+
await expect(getTagNames(canvasElement)).toEqual([
|
|
1393
|
+
'Tag 1',
|
|
1394
|
+
'Tag 2',
|
|
1395
|
+
'Tag 3',
|
|
1396
|
+
]);
|
|
1397
|
+
// reka keeps the rejected text in the field, so the user can shorten
|
|
1398
|
+
// the list and submit it again instead of retyping.
|
|
1399
|
+
await expect(field).toHaveValue('Tag 4');
|
|
1400
|
+
},
|
|
1401
|
+
);
|
|
1402
|
+
|
|
1403
|
+
await step(
|
|
1404
|
+
'screen-reader: the field stays operable at the limit (WCAG 4.1.2)',
|
|
1405
|
+
async () => {
|
|
1406
|
+
// The limit is not a disabled state: `max` only makes `onAddValue`
|
|
1407
|
+
// fail, so the field must keep reporting itself as editable.
|
|
1408
|
+
await expect(field).toBeEnabled();
|
|
1409
|
+
await expect(field).toHaveFocus();
|
|
1410
|
+
},
|
|
1411
|
+
);
|
|
1412
|
+
},
|
|
567
1413
|
};
|