@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,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { ref } from 'vue';
|
|
2
4
|
import UiLabel from './UiLabel.vue';
|
|
3
5
|
import { UiInput } from '../UiInput';
|
|
4
6
|
import { UiCheckbox } from '../UiCheckbox';
|
|
@@ -24,21 +26,29 @@ export default meta;
|
|
|
24
26
|
type Story = StoryObj<typeof UiLabel>;
|
|
25
27
|
|
|
26
28
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
27
|
-
import { UiLabel } from '@aleph-alpha/ui-library'
|
|
29
|
+
import { UiLabel, UiInput } from '@aleph-alpha/ui-library'
|
|
28
30
|
</script>
|
|
29
31
|
|
|
30
32
|
<template>
|
|
31
|
-
<UiLabel for="
|
|
33
|
+
<UiLabel for="name">Name</UiLabel>
|
|
34
|
+
<UiInput id="name" name="name" />
|
|
32
35
|
</template>`;
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
|
-
* Default label displaying text content.
|
|
36
|
-
*
|
|
38
|
+
* Default label displaying text content. The `for` attribute must point at the
|
|
39
|
+
* `id` of a real form element — that association is what names the control for
|
|
40
|
+
* assistive technology and makes clicking the label focus it. A `for` that
|
|
41
|
+
* resolves to nothing looks fine on screen but labels nothing.
|
|
37
42
|
*/
|
|
38
43
|
export const Default: Story = {
|
|
39
44
|
render: () => ({
|
|
40
|
-
components: { UiLabel },
|
|
41
|
-
template:
|
|
45
|
+
components: { UiLabel, UiInput },
|
|
46
|
+
template: `
|
|
47
|
+
<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
48
|
+
<UiLabel for="name">Name</UiLabel>
|
|
49
|
+
<UiInput id="name" name="name" />
|
|
50
|
+
</div>
|
|
51
|
+
`,
|
|
42
52
|
}),
|
|
43
53
|
parameters: {
|
|
44
54
|
docs: {
|
|
@@ -47,6 +57,35 @@ export const Default: Story = {
|
|
|
47
57
|
},
|
|
48
58
|
},
|
|
49
59
|
},
|
|
60
|
+
play: async ({ canvasElement, step }) => {
|
|
61
|
+
// Scenario (UiLabel): the label names the input it points at, which is the
|
|
62
|
+
// whole job of the component. Non-mutating — the click-to-focus flow lives
|
|
63
|
+
// in the test-only stories so this snapshot stays focus-free.
|
|
64
|
+
const canvas = within(canvasElement);
|
|
65
|
+
|
|
66
|
+
await step(
|
|
67
|
+
'screen-reader: the control is named by its label (WCAG 1.3.1, 4.1.2)',
|
|
68
|
+
async () => {
|
|
69
|
+
await expect(canvas.getByLabelText('Name')).toHaveAccessibleName(
|
|
70
|
+
'Name',
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
await step(
|
|
76
|
+
'interaction: the label resolves to a real control',
|
|
77
|
+
async () => {
|
|
78
|
+
// A `for` that points at nothing renders identically but labels
|
|
79
|
+
// nothing, so assert the association rather than the text.
|
|
80
|
+
const label = canvas.getByText('Name');
|
|
81
|
+
await expect(label).toHaveAttribute('for', 'name');
|
|
82
|
+
await expect(canvas.getByLabelText('Name')).toHaveAttribute(
|
|
83
|
+
'id',
|
|
84
|
+
'name',
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
},
|
|
50
89
|
};
|
|
51
90
|
|
|
52
91
|
const withInputTemplateSource = `<script setup lang="ts">
|
|
@@ -81,15 +120,44 @@ export const WithInput: Story = {
|
|
|
81
120
|
},
|
|
82
121
|
},
|
|
83
122
|
},
|
|
123
|
+
play: async ({ canvasElement, step }) => {
|
|
124
|
+
// Scenario (UiLabel + UiInput): the field has both a label and a
|
|
125
|
+
// placeholder, which is where the two most common naming mistakes show up.
|
|
126
|
+
// Non-mutating.
|
|
127
|
+
const canvas = within(canvasElement);
|
|
128
|
+
|
|
129
|
+
await step(
|
|
130
|
+
'screen-reader: the label supplies the accessible name (WCAG 1.3.1)',
|
|
131
|
+
async () => {
|
|
132
|
+
await expect(canvas.getByLabelText('Email')).toHaveAccessibleName(
|
|
133
|
+
'Email',
|
|
134
|
+
);
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
await step(
|
|
139
|
+
'screen-reader: the placeholder does not stand in as the name (WCAG 3.3.2)',
|
|
140
|
+
async () => {
|
|
141
|
+
// Without the label the name would silently fall back to the
|
|
142
|
+
// placeholder, which disappears as soon as the user types.
|
|
143
|
+
const input = canvas.getByLabelText('Email');
|
|
144
|
+
await expect(input).toHaveAttribute('placeholder', 'Enter your email');
|
|
145
|
+
await expect(input).not.toHaveAccessibleName('Enter your email');
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
},
|
|
84
149
|
};
|
|
85
150
|
|
|
86
151
|
const withCheckboxTemplateSource = `<script setup lang="ts">
|
|
87
152
|
import { UiLabel, UiCheckbox } from '@aleph-alpha/ui-library'
|
|
153
|
+
import { ref } from 'vue'
|
|
154
|
+
|
|
155
|
+
const accepted = ref(false)
|
|
88
156
|
</script>
|
|
89
157
|
|
|
90
158
|
<template>
|
|
91
159
|
<div class="flex items-center gap-x-2">
|
|
92
|
-
<UiCheckbox id="terms" name="terms" />
|
|
160
|
+
<UiCheckbox id="terms" name="terms" v-model="accepted" />
|
|
93
161
|
<UiLabel for="terms">Accept terms and conditions</UiLabel>
|
|
94
162
|
</div>
|
|
95
163
|
</template>`;
|
|
@@ -97,13 +165,19 @@ import { UiLabel, UiCheckbox } from '@aleph-alpha/ui-library'
|
|
|
97
165
|
/**
|
|
98
166
|
* Label paired with a checkbox for toggle options like terms acceptance.
|
|
99
167
|
* Position the label after the checkbox for standard form patterns.
|
|
168
|
+
* `UiCheckbox` needs a `v-model` to hold its state — without one it renders but
|
|
169
|
+
* never changes, so the label would focus a control that cannot be toggled.
|
|
100
170
|
*/
|
|
101
171
|
export const WithCheckbox: Story = {
|
|
102
172
|
render: () => ({
|
|
103
173
|
components: { UiLabel, UiCheckbox },
|
|
174
|
+
setup() {
|
|
175
|
+
const accepted = ref(false);
|
|
176
|
+
return { accepted };
|
|
177
|
+
},
|
|
104
178
|
template: `
|
|
105
179
|
<div class="flex items-center gap-x-2">
|
|
106
|
-
<UiCheckbox id="terms" name="terms" />
|
|
180
|
+
<UiCheckbox id="terms" name="terms" v-model="accepted" />
|
|
107
181
|
<UiLabel for="terms">Accept terms and conditions</UiLabel>
|
|
108
182
|
</div>
|
|
109
183
|
`,
|
|
@@ -115,6 +189,25 @@ export const WithCheckbox: Story = {
|
|
|
115
189
|
},
|
|
116
190
|
},
|
|
117
191
|
},
|
|
192
|
+
play: async ({ canvasElement, step }) => {
|
|
193
|
+
// Scenario (UiLabel + UiCheckbox): the label names a control that is not a
|
|
194
|
+
// native input, so the association has to be verified rather than assumed.
|
|
195
|
+
// Non-mutating; the toggle-by-label flow is in the test-only stories.
|
|
196
|
+
const canvas = within(canvasElement);
|
|
197
|
+
|
|
198
|
+
await step(
|
|
199
|
+
'screen-reader: the checkbox is named by its label (WCAG 1.3.1, 4.1.2)',
|
|
200
|
+
async () => {
|
|
201
|
+
const checkbox = canvas.getByRole('checkbox', {
|
|
202
|
+
name: 'Accept terms and conditions',
|
|
203
|
+
});
|
|
204
|
+
await expect(checkbox).toHaveAccessibleName(
|
|
205
|
+
'Accept terms and conditions',
|
|
206
|
+
);
|
|
207
|
+
await expect(checkbox).not.toBeChecked();
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
},
|
|
118
211
|
};
|
|
119
212
|
|
|
120
213
|
const disabledStateTemplateSource = `<script setup lang="ts">
|
|
@@ -122,21 +215,25 @@ import { UiLabel, UiInput } from '@aleph-alpha/ui-library'
|
|
|
122
215
|
</script>
|
|
123
216
|
|
|
124
217
|
<template>
|
|
125
|
-
|
|
218
|
+
<!-- The \`group\` class is required: the label mutes itself via
|
|
219
|
+
\`group-data-[disabled=true]\`, which only matches a \`.group\` ancestor. -->
|
|
220
|
+
<div class="group grid w-full max-w-sm items-center gap-1.5" data-disabled="true">
|
|
126
221
|
<UiLabel for="disabled-input">Disabled Field</UiLabel>
|
|
127
222
|
<UiInput id="disabled-input" name="disabled-input" disabled placeholder="Disabled" />
|
|
128
223
|
</div>
|
|
129
224
|
</template>`;
|
|
130
225
|
|
|
131
226
|
/**
|
|
132
|
-
* Label with a disabled input field. The label
|
|
133
|
-
*
|
|
227
|
+
* Label with a disabled input field. The label mutes itself when an ancestor
|
|
228
|
+
* carries both the `group` class and `data-disabled="true"` — `group` is what
|
|
229
|
+
* the `group-data-[disabled=true]` variant matches on, so leaving it off means
|
|
230
|
+
* the label silently keeps full-strength styling next to a disabled control.
|
|
134
231
|
*/
|
|
135
232
|
export const DisabledState: Story = {
|
|
136
233
|
render: () => ({
|
|
137
234
|
components: { UiLabel, UiInput },
|
|
138
235
|
template: `
|
|
139
|
-
<div class="grid w-full max-w-sm items-center gap-1.5" data-disabled="true">
|
|
236
|
+
<div class="group grid w-full max-w-sm items-center gap-1.5" data-disabled="true">
|
|
140
237
|
<UiLabel for="disabled-input">Disabled Field</UiLabel>
|
|
141
238
|
<UiInput id="disabled-input" name="disabled-input" disabled placeholder="Disabled" />
|
|
142
239
|
</div>
|
|
@@ -149,6 +246,33 @@ export const DisabledState: Story = {
|
|
|
149
246
|
},
|
|
150
247
|
},
|
|
151
248
|
},
|
|
249
|
+
play: async ({ canvasElement, step }) => {
|
|
250
|
+
// Scenario (UiLabel): a disabled field must read as disabled to assistive
|
|
251
|
+
// tech through the control, not through the label's dimmed appearance.
|
|
252
|
+
// Non-mutating.
|
|
253
|
+
const canvas = within(canvasElement);
|
|
254
|
+
|
|
255
|
+
await step(
|
|
256
|
+
'screen-reader: the disabled control is still named by its label',
|
|
257
|
+
async () => {
|
|
258
|
+
const input = canvas.getByLabelText('Disabled Field');
|
|
259
|
+
await expect(input).toHaveAccessibleName('Disabled Field');
|
|
260
|
+
await expect(input).toBeDisabled();
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
await step(
|
|
265
|
+
'interaction: the muted label styling actually applies (WCAG 1.4.1)',
|
|
266
|
+
async () => {
|
|
267
|
+
// Guards the `group` class on the wrapper: without it the variant
|
|
268
|
+
// never matches and the label looks enabled beside a disabled input.
|
|
269
|
+
const wrapper = canvas.getByText('Disabled Field')
|
|
270
|
+
.parentElement as HTMLElement;
|
|
271
|
+
await expect(wrapper).toHaveClass('group');
|
|
272
|
+
await expect(wrapper).toHaveAttribute('data-disabled', 'true');
|
|
273
|
+
},
|
|
274
|
+
);
|
|
275
|
+
},
|
|
152
276
|
};
|
|
153
277
|
|
|
154
278
|
const requiredFieldTemplateSource = `<script setup lang="ts">
|
|
@@ -159,15 +283,19 @@ import { UiLabel, UiInput } from '@aleph-alpha/ui-library'
|
|
|
159
283
|
<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
160
284
|
<UiLabel for="required-input">
|
|
161
285
|
Username
|
|
162
|
-
|
|
286
|
+
<!-- Decorative: \`required\` on the input is what announces the state,
|
|
287
|
+
so hide the asterisk instead of reading "Username star". -->
|
|
288
|
+
<span class="text-destructive" aria-hidden="true">*</span>
|
|
163
289
|
</UiLabel>
|
|
164
290
|
<UiInput id="required-input" name="required-input" required placeholder="Enter username" />
|
|
165
291
|
</div>
|
|
166
292
|
</template>`;
|
|
167
293
|
|
|
168
294
|
/**
|
|
169
|
-
* Label for a required field
|
|
170
|
-
*
|
|
295
|
+
* Label for a required field. The asterisk is a visual cue only — mark it
|
|
296
|
+
* `aria-hidden` and put `required` on the control, so the accessible name stays
|
|
297
|
+
* "Username" and the required state is announced by the control itself rather
|
|
298
|
+
* than read out as a stray "star".
|
|
171
299
|
*/
|
|
172
300
|
export const RequiredField: Story = {
|
|
173
301
|
render: () => ({
|
|
@@ -176,7 +304,7 @@ export const RequiredField: Story = {
|
|
|
176
304
|
<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
177
305
|
<UiLabel for="required-input">
|
|
178
306
|
Username
|
|
179
|
-
<span class="text-destructive">*</span>
|
|
307
|
+
<span class="text-destructive" aria-hidden="true">*</span>
|
|
180
308
|
</UiLabel>
|
|
181
309
|
<UiInput id="required-input" name="required-input" required placeholder="Enter username" />
|
|
182
310
|
</div>
|
|
@@ -189,4 +317,551 @@ export const RequiredField: Story = {
|
|
|
189
317
|
},
|
|
190
318
|
},
|
|
191
319
|
},
|
|
320
|
+
play: async ({ canvasElement, step }) => {
|
|
321
|
+
// Scenario (UiLabel): required has to survive without the red asterisk,
|
|
322
|
+
// since colour alone is not a cue and the glyph is hidden from assistive
|
|
323
|
+
// tech on purpose. Non-mutating.
|
|
324
|
+
const canvas = within(canvasElement);
|
|
325
|
+
|
|
326
|
+
await step(
|
|
327
|
+
'screen-reader: required state is announced by the control, not by colour (WCAG 1.4.1)',
|
|
328
|
+
async () => {
|
|
329
|
+
// Queried by accessible name rather than label text: the label reads
|
|
330
|
+
// "Username *", and only the computed name honours the asterisk's
|
|
331
|
+
// `aria-hidden`. Resolving this control by the name "Username" is
|
|
332
|
+
// itself proof that the asterisk is excluded.
|
|
333
|
+
await expect(
|
|
334
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
335
|
+
).toBeRequired();
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await step(
|
|
340
|
+
'screen-reader: the decorative asterisk stays out of the accessible name',
|
|
341
|
+
async () => {
|
|
342
|
+
await expect(
|
|
343
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
344
|
+
).toHaveAccessibleName('Username');
|
|
345
|
+
await expect(canvas.getByText('*')).toHaveAttribute(
|
|
346
|
+
'aria-hidden',
|
|
347
|
+
'true',
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
);
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Accessibility guidance for associating a label with its control, marking
|
|
356
|
+
* required fields, disabled styling, and contrast.
|
|
357
|
+
*/
|
|
358
|
+
export const Accessibility: Story = {
|
|
359
|
+
render: () => ({
|
|
360
|
+
components: { UiLabel, UiInput, UiCheckbox },
|
|
361
|
+
setup() {
|
|
362
|
+
const accepted = ref(false);
|
|
363
|
+
const accessibleAccepted = ref(false);
|
|
364
|
+
return { accepted, accessibleAccepted };
|
|
365
|
+
},
|
|
366
|
+
template: `
|
|
367
|
+
<section class="flex flex-col gap-6 p-4">
|
|
368
|
+
<div>
|
|
369
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
370
|
+
Accessibility
|
|
371
|
+
</h2>
|
|
372
|
+
</div>
|
|
373
|
+
|
|
374
|
+
<div class="flex flex-col gap-6">
|
|
375
|
+
<div class="flex flex-col gap-2">
|
|
376
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
377
|
+
Point <code>for</code> at a real control
|
|
378
|
+
</h3>
|
|
379
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
380
|
+
The <code>for</code> attribute must match the <code>id</code> of
|
|
381
|
+
an existing form element. That association is what gives the
|
|
382
|
+
control its accessible name and what makes clicking the label
|
|
383
|
+
focus it. A <code>for</code> that resolves to nothing looks
|
|
384
|
+
identical on screen while labelling nothing at all.
|
|
385
|
+
</p>
|
|
386
|
+
</div>
|
|
387
|
+
|
|
388
|
+
<div class="flex flex-col gap-2">
|
|
389
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
390
|
+
Mark required on the control
|
|
391
|
+
</h3>
|
|
392
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
393
|
+
Put <code>required</code> on the input so the state is announced,
|
|
394
|
+
and mark any asterisk <code>aria-hidden="true"</code>. A red
|
|
395
|
+
<code>*</code> on its own is colour-dependent (WCAG 1.4.1), and
|
|
396
|
+
an unhidden one turns the accessible name into
|
|
397
|
+
"Username star".
|
|
398
|
+
</p>
|
|
399
|
+
</div>
|
|
400
|
+
|
|
401
|
+
<div class="flex flex-col gap-2">
|
|
402
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
403
|
+
Don't put controls inside the label
|
|
404
|
+
</h3>
|
|
405
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
406
|
+
Keep the label to text. Nesting a button or link inside it
|
|
407
|
+
creates a control whose activation is ambiguous and can swallow
|
|
408
|
+
clicks meant for the field. Place related actions as siblings
|
|
409
|
+
instead.
|
|
410
|
+
</p>
|
|
411
|
+
</div>
|
|
412
|
+
|
|
413
|
+
<div class="flex flex-col gap-2">
|
|
414
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
415
|
+
Disabled needs the <code>group</code> class
|
|
416
|
+
</h3>
|
|
417
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
418
|
+
The label dims itself through
|
|
419
|
+
<code>group-data-[disabled=true]</code>, which only matches an
|
|
420
|
+
ancestor carrying the <code>group</code> class. Set
|
|
421
|
+
<code>group</code> alongside <code>data-disabled="true"</code>,
|
|
422
|
+
and always disable the control itself — the dimmed label is a
|
|
423
|
+
visual cue, not something assistive tech reports.
|
|
424
|
+
</p>
|
|
425
|
+
</div>
|
|
426
|
+
|
|
427
|
+
<div class="flex flex-col gap-2">
|
|
428
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
429
|
+
Enable accessibility theme
|
|
430
|
+
</h3>
|
|
431
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
432
|
+
When accessibility is required, enable our accessibility theme.
|
|
433
|
+
This increases contrast and makes sure there are no color
|
|
434
|
+
contrast issues.
|
|
435
|
+
</p>
|
|
436
|
+
</div>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
440
|
+
<div class="flex flex-col gap-3">
|
|
441
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
442
|
+
Default
|
|
443
|
+
</h3>
|
|
444
|
+
<div class="flex flex-col gap-4 border border-border-surface-default p-6">
|
|
445
|
+
<div class="grid items-center gap-1.5">
|
|
446
|
+
<UiLabel for="a11y-email">Email</UiLabel>
|
|
447
|
+
<UiInput id="a11y-email" name="a11y-email" type="email" />
|
|
448
|
+
</div>
|
|
449
|
+
<div class="flex items-center gap-x-2">
|
|
450
|
+
<UiCheckbox id="a11y-terms" name="a11y-terms" v-model="accepted" />
|
|
451
|
+
<UiLabel for="a11y-terms">Accept terms</UiLabel>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
|
|
456
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
457
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
458
|
+
Accessible
|
|
459
|
+
</h3>
|
|
460
|
+
<div class="flex flex-col gap-4 border border-border-surface-default p-6">
|
|
461
|
+
<div class="grid items-center gap-1.5">
|
|
462
|
+
<UiLabel for="a11y-email-accessible">Email</UiLabel>
|
|
463
|
+
<UiInput id="a11y-email-accessible" name="a11y-email-accessible" type="email" />
|
|
464
|
+
</div>
|
|
465
|
+
<div class="flex items-center gap-x-2">
|
|
466
|
+
<UiCheckbox
|
|
467
|
+
id="a11y-terms-accessible"
|
|
468
|
+
name="a11y-terms-accessible"
|
|
469
|
+
v-model="accessibleAccepted"
|
|
470
|
+
/>
|
|
471
|
+
<UiLabel for="a11y-terms-accessible">Accept terms</UiLabel>
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
</section>
|
|
477
|
+
`,
|
|
478
|
+
}),
|
|
479
|
+
tags: ['!autodocs'],
|
|
480
|
+
parameters: {
|
|
481
|
+
a11y: { test: 'off' },
|
|
482
|
+
chromatic: {
|
|
483
|
+
disableSnapshot: true,
|
|
484
|
+
},
|
|
485
|
+
docs: {
|
|
486
|
+
canvas: {
|
|
487
|
+
sourceState: 'none',
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/*
|
|
494
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
495
|
+
* Interaction & accessibility tests (play functions)
|
|
496
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
497
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
498
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
499
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
500
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
501
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
502
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2)
|
|
503
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
504
|
+
* • `mobile:` 320px reflow (WCAG 1.4.10)
|
|
505
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
506
|
+
* an `a11y:` prefix.
|
|
507
|
+
*
|
|
508
|
+
* `UiLabel` has no behaviour of its own: everything it does happens to the
|
|
509
|
+
* control it points at. So the shared render below pairs it with the two kinds
|
|
510
|
+
* of control it has to work with — a native `input`, and `UiCheckbox`, which
|
|
511
|
+
* renders a `button[role=checkbox]` rather than a native input and therefore
|
|
512
|
+
* cannot be assumed to honour label activation. A required field is included
|
|
513
|
+
* so the required-state assertions have somewhere to run.
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* The form the test stories drive: a text input, a checkbox that is not a
|
|
518
|
+
* native input, and a required field — each named by a `UiLabel`.
|
|
519
|
+
* @returns Vue component options for a story `render` function.
|
|
520
|
+
*/
|
|
521
|
+
function renderTestForm() {
|
|
522
|
+
return {
|
|
523
|
+
components: { UiLabel, UiInput, UiCheckbox },
|
|
524
|
+
setup() {
|
|
525
|
+
const accepted = ref(false);
|
|
526
|
+
return { accepted };
|
|
527
|
+
},
|
|
528
|
+
template: `
|
|
529
|
+
<div class="flex max-w-sm flex-col gap-4">
|
|
530
|
+
<div class="grid items-center gap-1.5">
|
|
531
|
+
<UiLabel for="test-email">Email</UiLabel>
|
|
532
|
+
<UiInput id="test-email" name="test-email" type="email" placeholder="Enter your email" />
|
|
533
|
+
</div>
|
|
534
|
+
|
|
535
|
+
<div class="flex items-center gap-x-2">
|
|
536
|
+
<UiCheckbox id="test-terms" name="test-terms" v-model="accepted" />
|
|
537
|
+
<UiLabel for="test-terms">Accept terms and conditions</UiLabel>
|
|
538
|
+
</div>
|
|
539
|
+
|
|
540
|
+
<div class="grid items-center gap-1.5">
|
|
541
|
+
<UiLabel for="test-username">
|
|
542
|
+
Username
|
|
543
|
+
<span class="text-destructive" aria-hidden="true">*</span>
|
|
544
|
+
</UiLabel>
|
|
545
|
+
<UiInput id="test-username" name="test-username" required placeholder="Enter username" />
|
|
546
|
+
</div>
|
|
547
|
+
</div>
|
|
548
|
+
`,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Clicking a label reaches its control — focusing a text input and toggling a
|
|
554
|
+
* checkbox that is not a native input. Hidden test-only story.
|
|
555
|
+
*/
|
|
556
|
+
export const LabelActivation: Story = {
|
|
557
|
+
name: 'test - Label Activation',
|
|
558
|
+
tags: ['!dev', '!autodocs'],
|
|
559
|
+
parameters: {
|
|
560
|
+
// Focus moves and the checkbox toggles during the play function.
|
|
561
|
+
chromatic: { disableSnapshot: true },
|
|
562
|
+
docs: {
|
|
563
|
+
description: {
|
|
564
|
+
story:
|
|
565
|
+
'Click each label to confirm it focuses or activates the control it points at.',
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
render: renderTestForm,
|
|
570
|
+
play: async ({ canvasElement, step }) => {
|
|
571
|
+
// Scenario (UiLabel): a pointer user clicks the label text rather than the
|
|
572
|
+
// control — the larger, easier target — and still reaches the field.
|
|
573
|
+
const canvas = within(canvasElement);
|
|
574
|
+
|
|
575
|
+
await step(
|
|
576
|
+
'interaction: clicking a label focuses its text input',
|
|
577
|
+
async () => {
|
|
578
|
+
await userEvent.click(canvas.getByText('Email'));
|
|
579
|
+
await expect(canvas.getByLabelText('Email')).toHaveFocus();
|
|
580
|
+
},
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
await step(
|
|
584
|
+
'interaction: clicking a label activates a non-native control',
|
|
585
|
+
async () => {
|
|
586
|
+
// `UiCheckbox` renders `button[role=checkbox]`, so label activation
|
|
587
|
+
// has to be verified rather than assumed from native behaviour.
|
|
588
|
+
const checkbox = canvas.getByRole('checkbox', {
|
|
589
|
+
name: 'Accept terms and conditions',
|
|
590
|
+
});
|
|
591
|
+
await expect(checkbox).not.toBeChecked();
|
|
592
|
+
|
|
593
|
+
await userEvent.click(canvas.getByText('Accept terms and conditions'));
|
|
594
|
+
await expect(checkbox).toBeChecked();
|
|
595
|
+
await expect(checkbox).toHaveFocus();
|
|
596
|
+
},
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
await step(
|
|
600
|
+
'interaction: clicking the label again toggles the control back',
|
|
601
|
+
async () => {
|
|
602
|
+
await userEvent.click(canvas.getByText('Accept terms and conditions'));
|
|
603
|
+
await expect(
|
|
604
|
+
canvas.getByRole('checkbox', {
|
|
605
|
+
name: 'Accept terms and conditions',
|
|
606
|
+
}),
|
|
607
|
+
).not.toBeChecked();
|
|
608
|
+
},
|
|
609
|
+
);
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Labels stay out of the tab sequence while every control they name remains
|
|
615
|
+
* reachable in order. Hidden test-only story.
|
|
616
|
+
*/
|
|
617
|
+
export const KeyboardNavigation: Story = {
|
|
618
|
+
name: 'test - Keyboard Navigation',
|
|
619
|
+
tags: ['!dev', '!autodocs'],
|
|
620
|
+
parameters: {
|
|
621
|
+
// Focus moves during the play function.
|
|
622
|
+
chromatic: { disableSnapshot: true },
|
|
623
|
+
docs: {
|
|
624
|
+
description: {
|
|
625
|
+
story:
|
|
626
|
+
'Press `Tab` to walk the form and confirm the labels add no stops of their own.',
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
render: renderTestForm,
|
|
631
|
+
play: async ({ canvasElement, step }) => {
|
|
632
|
+
// Scenario (UiLabel): associating a label must not alter the tab sequence.
|
|
633
|
+
// A keyboard user should reach the three controls in document order and
|
|
634
|
+
// never land on a label.
|
|
635
|
+
const canvas = within(canvasElement);
|
|
636
|
+
|
|
637
|
+
await step(
|
|
638
|
+
'keyboard: labels are not focusable and add no tab stops (WCAG 2.1.1)',
|
|
639
|
+
async () => {
|
|
640
|
+
for (const text of ['Email', 'Accept terms and conditions']) {
|
|
641
|
+
await expect(canvas.getByText(text)).not.toHaveAttribute('tabindex');
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
await step(
|
|
647
|
+
'keyboard: Tab reaches each labelled control in document order (WCAG 2.4.3)',
|
|
648
|
+
async () => {
|
|
649
|
+
await userEvent.tab();
|
|
650
|
+
await expect(canvas.getByLabelText('Email')).toHaveFocus();
|
|
651
|
+
|
|
652
|
+
await userEvent.tab();
|
|
653
|
+
await expect(
|
|
654
|
+
canvas.getByRole('checkbox', {
|
|
655
|
+
name: 'Accept terms and conditions',
|
|
656
|
+
}),
|
|
657
|
+
).toHaveFocus();
|
|
658
|
+
|
|
659
|
+
await userEvent.tab();
|
|
660
|
+
await expect(
|
|
661
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
662
|
+
).toHaveFocus();
|
|
663
|
+
},
|
|
664
|
+
);
|
|
665
|
+
|
|
666
|
+
await step(
|
|
667
|
+
'keyboard: the labelled control is still operable from the keyboard',
|
|
668
|
+
async () => {
|
|
669
|
+
const checkbox = canvas.getByRole('checkbox', {
|
|
670
|
+
name: 'Accept terms and conditions',
|
|
671
|
+
});
|
|
672
|
+
checkbox.focus();
|
|
673
|
+
await userEvent.keyboard(' ');
|
|
674
|
+
await expect(checkbox).toBeChecked();
|
|
675
|
+
},
|
|
676
|
+
);
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Screen-reader semantics: every control is named by its label, and required
|
|
682
|
+
* state comes from the control rather than the asterisk (WCAG 1.3.1, 4.1.2).
|
|
683
|
+
* Hidden test-only story.
|
|
684
|
+
*/
|
|
685
|
+
export const ScreenReader: Story = {
|
|
686
|
+
name: 'test - Screen Reader',
|
|
687
|
+
tags: ['!dev', '!autodocs'],
|
|
688
|
+
parameters: {
|
|
689
|
+
// Focus moves during the play function.
|
|
690
|
+
chromatic: { disableSnapshot: true },
|
|
691
|
+
docs: {
|
|
692
|
+
description: {
|
|
693
|
+
story:
|
|
694
|
+
'Verifies the accessible names and required state that assistive technology announces.',
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
render: renderTestForm,
|
|
699
|
+
play: async ({ canvasElement, step }) => {
|
|
700
|
+
// Scenario (UiLabel): assistive tech resolves each control's name from its
|
|
701
|
+
// label, including for a control that is not a native input, and hears
|
|
702
|
+
// required state without seeing the red asterisk.
|
|
703
|
+
const canvas = within(canvasElement);
|
|
704
|
+
|
|
705
|
+
await step(
|
|
706
|
+
'screen-reader: each control is named by its label (WCAG 1.3.1, 4.1.2)',
|
|
707
|
+
async () => {
|
|
708
|
+
await expect(canvas.getByLabelText('Email')).toHaveAccessibleName(
|
|
709
|
+
'Email',
|
|
710
|
+
);
|
|
711
|
+
await expect(
|
|
712
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
713
|
+
).toHaveAccessibleName('Username');
|
|
714
|
+
},
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
await step(
|
|
718
|
+
'screen-reader: a non-native control is named by its label too',
|
|
719
|
+
async () => {
|
|
720
|
+
await expect(
|
|
721
|
+
canvas.getByRole('checkbox', {
|
|
722
|
+
name: 'Accept terms and conditions',
|
|
723
|
+
}),
|
|
724
|
+
).toHaveAccessibleName('Accept terms and conditions');
|
|
725
|
+
},
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
await step(
|
|
729
|
+
'screen-reader: required state is announced without colour (WCAG 1.4.1)',
|
|
730
|
+
async () => {
|
|
731
|
+
await expect(
|
|
732
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
733
|
+
).toBeRequired();
|
|
734
|
+
await expect(canvas.getByLabelText('Email')).not.toBeRequired();
|
|
735
|
+
},
|
|
736
|
+
);
|
|
737
|
+
|
|
738
|
+
await step(
|
|
739
|
+
'screen-reader: the decorative asterisk is excluded from the name',
|
|
740
|
+
async () => {
|
|
741
|
+
await expect(canvas.getByText('*')).toHaveAttribute(
|
|
742
|
+
'aria-hidden',
|
|
743
|
+
'true',
|
|
744
|
+
);
|
|
745
|
+
await expect(
|
|
746
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
747
|
+
).toHaveAccessibleName('Username');
|
|
748
|
+
},
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
755
|
+
* try 400% reflow (WCAG 1.4.10); labels must stay readable and keep working.
|
|
756
|
+
* Hidden test-only story.
|
|
757
|
+
*/
|
|
758
|
+
export const ZoomMagnification: Story = {
|
|
759
|
+
name: 'test - Zoom Magnification',
|
|
760
|
+
tags: ['!dev', '!autodocs'],
|
|
761
|
+
globals: { zoom: '200' },
|
|
762
|
+
parameters: {
|
|
763
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
764
|
+
// already covers magnified snapshots, so skip this one.
|
|
765
|
+
chromatic: { disableSnapshot: true },
|
|
766
|
+
docs: {
|
|
767
|
+
description: {
|
|
768
|
+
story:
|
|
769
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
},
|
|
773
|
+
render: renderTestForm,
|
|
774
|
+
play: async ({ canvasElement, step }) => {
|
|
775
|
+
// Scenario (UiLabel): at 200% page zoom the label text stays on screen and
|
|
776
|
+
// still reaches its control when clicked.
|
|
777
|
+
const canvas = within(canvasElement);
|
|
778
|
+
|
|
779
|
+
await step(
|
|
780
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
781
|
+
async () => {
|
|
782
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
783
|
+
},
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
await step('zoom: labels stay visible and readable', async () => {
|
|
787
|
+
for (const text of ['Email', 'Accept terms and conditions', 'Username']) {
|
|
788
|
+
const label = canvas.getByText(text);
|
|
789
|
+
await expect(label).toBeVisible();
|
|
790
|
+
|
|
791
|
+
const { left, right } = label.getBoundingClientRect();
|
|
792
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
793
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
await step(
|
|
798
|
+
'zoom: label association still works when magnified',
|
|
799
|
+
async () => {
|
|
800
|
+
await userEvent.click(canvas.getByText('Email'));
|
|
801
|
+
await expect(canvas.getByLabelText('Email')).toHaveFocus();
|
|
802
|
+
},
|
|
803
|
+
);
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
809
|
+
* toolbar. Labels and controls stay inside the viewport and keep working.
|
|
810
|
+
* Hidden test-only story.
|
|
811
|
+
*/
|
|
812
|
+
export const MobileBreakpoint: Story = {
|
|
813
|
+
name: 'test - Mobile Breakpoint',
|
|
814
|
+
tags: ['!dev', '!autodocs'],
|
|
815
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
816
|
+
parameters: {
|
|
817
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
818
|
+
chromatic: { disableSnapshot: true },
|
|
819
|
+
docs: {
|
|
820
|
+
description: {
|
|
821
|
+
story:
|
|
822
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
823
|
+
},
|
|
824
|
+
},
|
|
825
|
+
},
|
|
826
|
+
render: renderTestForm,
|
|
827
|
+
play: async ({ canvasElement, step }) => {
|
|
828
|
+
// Scenario (UiLabel): at the 320px mobile breakpoint labels and their
|
|
829
|
+
// controls reflow inside the viewport and the association still works.
|
|
830
|
+
const canvas = within(canvasElement);
|
|
831
|
+
|
|
832
|
+
await step(
|
|
833
|
+
'mobile: labels and controls fit the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
834
|
+
async () => {
|
|
835
|
+
const elements = [
|
|
836
|
+
canvas.getByText('Email'),
|
|
837
|
+
canvas.getByLabelText('Email'),
|
|
838
|
+
canvas.getByText('Accept terms and conditions'),
|
|
839
|
+
canvas.getByRole('textbox', { name: 'Username' }),
|
|
840
|
+
];
|
|
841
|
+
|
|
842
|
+
for (const element of elements) {
|
|
843
|
+
await expect(element).toBeVisible();
|
|
844
|
+
const { left, right } = element.getBoundingClientRect();
|
|
845
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
846
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
847
|
+
}
|
|
848
|
+
},
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
await step(
|
|
852
|
+
'mobile: tapping the label still reaches its control',
|
|
853
|
+
async () => {
|
|
854
|
+
const label = canvas.getByText('Accept terms and conditions');
|
|
855
|
+
const checkbox = canvas.getByRole('checkbox', {
|
|
856
|
+
name: 'Accept terms and conditions',
|
|
857
|
+
});
|
|
858
|
+
await userEvent.click(label);
|
|
859
|
+
await expect(checkbox).toBeChecked();
|
|
860
|
+
const row = checkbox.parentElement as HTMLElement;
|
|
861
|
+
const { width, height } = row.getBoundingClientRect();
|
|
862
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
863
|
+
await expect(height).toBeGreaterThanOrEqual(16);
|
|
864
|
+
},
|
|
865
|
+
);
|
|
866
|
+
},
|
|
192
867
|
};
|