@aleph-alpha/ui-library 5.11.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/README.md +2 -2
- 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 +20 -11
- package/package.json +5 -2
- 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,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import {
|
|
3
|
+
expect,
|
|
4
|
+
fireEvent,
|
|
5
|
+
fn,
|
|
6
|
+
userEvent,
|
|
7
|
+
waitFor,
|
|
8
|
+
within,
|
|
9
|
+
} from 'storybook/test';
|
|
2
10
|
import { ref, watch } from 'vue';
|
|
3
11
|
import { UiSlider } from '.';
|
|
4
12
|
|
|
@@ -57,6 +65,12 @@ const meta: Meta<typeof UiSlider> = {
|
|
|
57
65
|
export default meta;
|
|
58
66
|
type Story = StoryObj<typeof UiSlider>;
|
|
59
67
|
|
|
68
|
+
// `UiSlider` re-emits `update:modelValue` and `valueCommit` from the vendor
|
|
69
|
+
// slider and declares no handler props, so play functions bind these
|
|
70
|
+
// module-level spies in the template and `mockClear()` them first.
|
|
71
|
+
const onUpdateModelValue = fn();
|
|
72
|
+
const onValueCommit = fn();
|
|
73
|
+
|
|
60
74
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
61
75
|
import { ref } from 'vue'
|
|
62
76
|
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
@@ -108,6 +122,37 @@ export const Default: Story = {
|
|
|
108
122
|
parameters: {
|
|
109
123
|
docs: { source: { code: defaultTemplateSource } },
|
|
110
124
|
},
|
|
125
|
+
play: async ({ canvasElement, step }) => {
|
|
126
|
+
// Scenario (UiSlider): assistive tech finds one named handle that reports
|
|
127
|
+
// where it sits in the range. Nothing here moves the value, so the
|
|
128
|
+
// Chromatic snapshot stays valid.
|
|
129
|
+
const canvas = within(canvasElement);
|
|
130
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
131
|
+
|
|
132
|
+
await step(
|
|
133
|
+
'screen-reader: the handle exposes a slider role with an accessible name (WCAG 4.1.2)',
|
|
134
|
+
async () => {
|
|
135
|
+
await expect(handle).toHaveAccessibleName('Value');
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
await step(
|
|
140
|
+
'screen-reader: announces its current, minimum, and maximum values',
|
|
141
|
+
async () => {
|
|
142
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
143
|
+
await expect(handle).toHaveAttribute('aria-valuemin', '0');
|
|
144
|
+
await expect(handle).toHaveAttribute('aria-valuemax', '100');
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await step(
|
|
149
|
+
'interaction: an enabled handle is exposed as operable',
|
|
150
|
+
async () => {
|
|
151
|
+
await expect(handle).toHaveAttribute('tabindex', '0');
|
|
152
|
+
await expect(handle).not.toHaveAttribute('data-disabled');
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
},
|
|
111
156
|
};
|
|
112
157
|
|
|
113
158
|
const rangeTemplateSource = `<script setup lang="ts">
|
|
@@ -146,6 +191,34 @@ export const Range: Story = {
|
|
|
146
191
|
controls: { disable: true },
|
|
147
192
|
docs: { source: { code: rangeTemplateSource } },
|
|
148
193
|
},
|
|
194
|
+
play: async ({ canvasElement, step }) => {
|
|
195
|
+
// Scenario (UiSlider): a range renders one handle per value, and each handle
|
|
196
|
+
// is named and reported separately. Non-mutating, so the snapshot holds.
|
|
197
|
+
const canvas = within(canvasElement);
|
|
198
|
+
|
|
199
|
+
await step(
|
|
200
|
+
'interaction: renders one handle per value in the model',
|
|
201
|
+
async () => {
|
|
202
|
+
await expect(canvas.getAllByRole('slider')).toHaveLength(2);
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
await step(
|
|
207
|
+
'screen-reader: each handle has its own accessible name and current value (WCAG 4.1.2)',
|
|
208
|
+
async () => {
|
|
209
|
+
const lower = canvas.getByRole('slider', { name: 'Value 1' });
|
|
210
|
+
const upper = canvas.getByRole('slider', { name: 'Value 2' });
|
|
211
|
+
|
|
212
|
+
await expect(lower).toHaveAttribute('aria-valuenow', '25');
|
|
213
|
+
await expect(upper).toHaveAttribute('aria-valuenow', '75');
|
|
214
|
+
|
|
215
|
+
for (const handle of [lower, upper]) {
|
|
216
|
+
await expect(handle).toHaveAttribute('aria-valuemin', '0');
|
|
217
|
+
await expect(handle).toHaveAttribute('aria-valuemax', '100');
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
},
|
|
149
222
|
};
|
|
150
223
|
|
|
151
224
|
const verticalTemplateSource = `<script setup lang="ts">
|
|
@@ -188,6 +261,20 @@ export const Vertical: Story = {
|
|
|
188
261
|
controls: { disable: true },
|
|
189
262
|
docs: { source: { code: verticalTemplateSource } },
|
|
190
263
|
},
|
|
264
|
+
play: async ({ canvasElement, step }) => {
|
|
265
|
+
// Scenario (UiSlider): a vertical slider must announce its orientation so
|
|
266
|
+
// assistive tech offers the right arrow keys.
|
|
267
|
+
const canvas = within(canvasElement);
|
|
268
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
269
|
+
|
|
270
|
+
await step(
|
|
271
|
+
'screen-reader: announces the vertical orientation (WCAG 4.1.2)',
|
|
272
|
+
async () => {
|
|
273
|
+
await expect(handle).toHaveAttribute('aria-orientation', 'vertical');
|
|
274
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
275
|
+
},
|
|
276
|
+
);
|
|
277
|
+
},
|
|
191
278
|
};
|
|
192
279
|
|
|
193
280
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
@@ -226,4 +313,633 @@ export const Disabled: Story = {
|
|
|
226
313
|
controls: { disable: true },
|
|
227
314
|
docs: { source: { code: disabledTemplateSource } },
|
|
228
315
|
},
|
|
316
|
+
play: async ({ canvasElement, step }) => {
|
|
317
|
+
// Scenario (UiSlider): a disabled slider reports its state, is skipped by
|
|
318
|
+
// Tab, and refuses to move even when a step key reaches it.
|
|
319
|
+
const canvas = within(canvasElement);
|
|
320
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
321
|
+
|
|
322
|
+
await step(
|
|
323
|
+
'interaction: exposes the disabled state (WCAG 4.1.2)',
|
|
324
|
+
async () => {
|
|
325
|
+
await expect(handle).toHaveAttribute('data-disabled');
|
|
326
|
+
await expect(canvas.getByText('Value: 50')).toBeInTheDocument();
|
|
327
|
+
},
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
await step(
|
|
331
|
+
'keyboard: removed from the tab order — not reachable via Tab (WCAG 2.1.1)',
|
|
332
|
+
async () => {
|
|
333
|
+
await expect(handle).not.toHaveAttribute('tabindex');
|
|
334
|
+
await userEvent.tab();
|
|
335
|
+
await expect(handle).not.toHaveFocus();
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await step('interaction: a disabled slider does not change', async () => {
|
|
340
|
+
// The handle can't be focused, so dispatch the step key on the slider
|
|
341
|
+
// itself — that is the listener a focused handle would bubble to. A
|
|
342
|
+
// pointer drag is covered by the enabled stories.
|
|
343
|
+
await fireEvent.keyDown(handle, { key: 'ArrowRight' });
|
|
344
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
345
|
+
await expect(canvas.getByText('Value: 50')).toBeInTheDocument();
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Accessibility guidance for labelling the slider, exposing its value as text,
|
|
352
|
+
* and keeping it operable from the keyboard.
|
|
353
|
+
*/
|
|
354
|
+
export const Accessibility: Story = {
|
|
355
|
+
render: () => ({
|
|
356
|
+
components: { UiSlider },
|
|
357
|
+
setup() {
|
|
358
|
+
const defaultValue = ref([60]);
|
|
359
|
+
const accessibleValue = ref([60]);
|
|
360
|
+
return { defaultValue, accessibleValue };
|
|
361
|
+
},
|
|
362
|
+
template: `
|
|
363
|
+
<section class="flex flex-col gap-6 p-4">
|
|
364
|
+
<div>
|
|
365
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
366
|
+
Accessibility
|
|
367
|
+
</h2>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
<div class="flex flex-col gap-6">
|
|
371
|
+
<div class="flex flex-col gap-2">
|
|
372
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
373
|
+
Label what the slider controls
|
|
374
|
+
</h3>
|
|
375
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
376
|
+
Each handle is announced as a slider named <code>Value</code>
|
|
377
|
+
(<code>Value 1</code> / <code>Value 2</code> for a range), which
|
|
378
|
+
says nothing about what is being adjusted. Put a visible heading
|
|
379
|
+
or <code>label</code> next to the slider so the surrounding
|
|
380
|
+
context supplies the meaning.
|
|
381
|
+
</p>
|
|
382
|
+
</div>
|
|
383
|
+
|
|
384
|
+
<div class="flex flex-col gap-2">
|
|
385
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
386
|
+
Show the current value as text
|
|
387
|
+
</h3>
|
|
388
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
389
|
+
Handle position alone is not perceivable for everyone. Render the
|
|
390
|
+
value next to the slider so it can be read, magnified, and
|
|
391
|
+
translated — the same number assistive technology gets from
|
|
392
|
+
<code>aria-valuenow</code>.
|
|
393
|
+
</p>
|
|
394
|
+
</div>
|
|
395
|
+
|
|
396
|
+
<div class="flex flex-col gap-2">
|
|
397
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
398
|
+
Keep it keyboard operable
|
|
399
|
+
</h3>
|
|
400
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
401
|
+
Every handle is a Tab stop and moves with the arrow keys.
|
|
402
|
+
<code>Home</code> and <code>End</code> jump to the minimum and
|
|
403
|
+
maximum, and <code>Page Up</code> / <code>Page Down</code> (or
|
|
404
|
+
<code>Shift</code> + arrow) move in larger jumps — so a long
|
|
405
|
+
range never needs hundreds of key presses.
|
|
406
|
+
</p>
|
|
407
|
+
</div>
|
|
408
|
+
|
|
409
|
+
<div class="flex flex-col gap-2">
|
|
410
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
411
|
+
Give small handles room
|
|
412
|
+
</h3>
|
|
413
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
414
|
+
The handle is smaller than the 24px minimum target size, so it
|
|
415
|
+
relies on the WCAG 2.5.8 spacing exception: keep other controls
|
|
416
|
+
at least 24px away, and don't crowd several sliders together.
|
|
417
|
+
</p>
|
|
418
|
+
</div>
|
|
419
|
+
|
|
420
|
+
<div class="flex flex-col gap-2">
|
|
421
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
422
|
+
Enable accessibility theme
|
|
423
|
+
</h3>
|
|
424
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
425
|
+
When accessibility is required, enable our accessibility theme.
|
|
426
|
+
This increases contrast and makes sure there are no color
|
|
427
|
+
contrast issues.
|
|
428
|
+
</p>
|
|
429
|
+
</div>
|
|
430
|
+
</div>
|
|
431
|
+
|
|
432
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
433
|
+
<div class="flex flex-col gap-3">
|
|
434
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
435
|
+
Default
|
|
436
|
+
</h3>
|
|
437
|
+
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
438
|
+
<p class="label-14-medium text-content-on-surface-primary">Volume</p>
|
|
439
|
+
<div class="my-3">
|
|
440
|
+
<UiSlider v-model="defaultValue" />
|
|
441
|
+
</div>
|
|
442
|
+
<p class="body-14-regular text-content-on-surface-muted">Value: {{ defaultValue[0] }}</p>
|
|
443
|
+
</div>
|
|
444
|
+
</div>
|
|
445
|
+
|
|
446
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
447
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
448
|
+
Accessible
|
|
449
|
+
</h3>
|
|
450
|
+
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
451
|
+
<p class="label-14-medium text-content-on-surface-primary">Volume</p>
|
|
452
|
+
<div class="my-3">
|
|
453
|
+
<UiSlider v-model="accessibleValue" />
|
|
454
|
+
</div>
|
|
455
|
+
<p class="body-14-regular text-content-on-surface-muted">Value: {{ accessibleValue[0] }}</p>
|
|
456
|
+
</div>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
459
|
+
</section>
|
|
460
|
+
`,
|
|
461
|
+
}),
|
|
462
|
+
tags: ['!autodocs'],
|
|
463
|
+
parameters: {
|
|
464
|
+
a11y: { test: 'off' },
|
|
465
|
+
chromatic: {
|
|
466
|
+
disableSnapshot: true,
|
|
467
|
+
},
|
|
468
|
+
docs: {
|
|
469
|
+
canvas: {
|
|
470
|
+
sourceState: 'none',
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/*
|
|
477
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
478
|
+
* Interaction & accessibility tests (play functions)
|
|
479
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
480
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
481
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
482
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
483
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
484
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
485
|
+
* • `screen-reader:` names, roles and values (WCAG 4.1.2)
|
|
486
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
487
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
488
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
489
|
+
* an `a11y:` prefix.
|
|
490
|
+
*
|
|
491
|
+
* Handles are moved with the keyboard rather than a pointer drag: reka-ui's
|
|
492
|
+
* slider calls `setPointerCapture()` on `pointerdown`, which needs a real
|
|
493
|
+
* browser pointer that `userEvent`'s synthetic events can't provide. Arrow,
|
|
494
|
+
* Home, and End keys drive the same `updateValues()` path a drag does, so range,
|
|
495
|
+
* step, and commit behaviour is still covered end to end. Payload guards that
|
|
496
|
+
* need the vendor slider stubbed stay in Vitest under `__tests__/`.
|
|
497
|
+
*/
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Controlled single-thumb slider driven by the test-only stories. The value
|
|
501
|
+
* only moves because `UiSlider` re-emits `update:modelValue` and the story
|
|
502
|
+
* feeds it straight back in, so every play also exercises the wrapper's
|
|
503
|
+
* controlled round-trip and its `valueCommit` re-emit.
|
|
504
|
+
* @param step Stepping interval for the slider under test.
|
|
505
|
+
* @returns Vue component options for a story `render` function.
|
|
506
|
+
*/
|
|
507
|
+
function renderControlledSlider(step = 5) {
|
|
508
|
+
return {
|
|
509
|
+
components: { UiSlider },
|
|
510
|
+
setup() {
|
|
511
|
+
const value = ref([50]);
|
|
512
|
+
const update = (next: number[]) => {
|
|
513
|
+
value.value = next;
|
|
514
|
+
onUpdateModelValue(next);
|
|
515
|
+
};
|
|
516
|
+
return { value, update, step, onValueCommit };
|
|
517
|
+
},
|
|
518
|
+
template: `
|
|
519
|
+
<div class="w-full max-w-72">
|
|
520
|
+
<p class="label-14-medium text-content-on-surface-primary">Volume</p>
|
|
521
|
+
<div class="my-3">
|
|
522
|
+
<UiSlider
|
|
523
|
+
:model-value="value"
|
|
524
|
+
:min="0"
|
|
525
|
+
:max="100"
|
|
526
|
+
:step="step"
|
|
527
|
+
@update:model-value="update"
|
|
528
|
+
@value-commit="onValueCommit"
|
|
529
|
+
/>
|
|
530
|
+
</div>
|
|
531
|
+
<p class="body-14-regular text-content-on-surface-muted">Value: {{ value[0] }}</p>
|
|
532
|
+
</div>
|
|
533
|
+
`,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Reads the value a handle currently reports to assistive technology.
|
|
539
|
+
* @param handle A `role="slider"` handle element.
|
|
540
|
+
* @returns The numeric `aria-valuenow`.
|
|
541
|
+
*/
|
|
542
|
+
function valueNow(handle: HTMLElement): number {
|
|
543
|
+
return Number(handle.getAttribute('aria-valuenow'));
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Every handle is a Tab stop and moves with the arrow keys, with `Home` and
|
|
548
|
+
* `End` jumping to the ends of the range. Hidden test-only story.
|
|
549
|
+
*/
|
|
550
|
+
export const KeyboardNavigation: Story = {
|
|
551
|
+
name: 'test - Keyboard Navigation',
|
|
552
|
+
tags: ['!dev', '!autodocs'],
|
|
553
|
+
parameters: {
|
|
554
|
+
// Focus moves and the value changes during the play function.
|
|
555
|
+
chromatic: { disableSnapshot: true },
|
|
556
|
+
docs: {
|
|
557
|
+
description: {
|
|
558
|
+
story:
|
|
559
|
+
'Press `Tab` to focus the handle, then the arrow keys to adjust it and `Home` / `End` to jump to the minimum and maximum.',
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
render: () => renderControlledSlider(5),
|
|
564
|
+
play: async ({ canvasElement, step }) => {
|
|
565
|
+
// Scenario (UiSlider): a keyboard user tabs to the handle, nudges it a step
|
|
566
|
+
// at a time, jumps to both ends of the range, and can't push it past them.
|
|
567
|
+
onUpdateModelValue.mockClear();
|
|
568
|
+
onValueCommit.mockClear();
|
|
569
|
+
const canvas = within(canvasElement);
|
|
570
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
571
|
+
|
|
572
|
+
await step(
|
|
573
|
+
'keyboard: the handle is reachable via Tab (WCAG 2.1.1)',
|
|
574
|
+
async () => {
|
|
575
|
+
await userEvent.tab();
|
|
576
|
+
await expect(handle).toHaveFocus();
|
|
577
|
+
},
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
await step(
|
|
581
|
+
'keyboard: the arrow keys move the handle by one step',
|
|
582
|
+
async () => {
|
|
583
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
584
|
+
await waitFor(async () => {
|
|
585
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '55');
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
await userEvent.keyboard('{ArrowLeft}');
|
|
589
|
+
await waitFor(async () => {
|
|
590
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
await step(
|
|
596
|
+
'keyboard: End and Home jump to the maximum and minimum (WCAG 2.1.1)',
|
|
597
|
+
async () => {
|
|
598
|
+
await userEvent.keyboard('{End}');
|
|
599
|
+
await waitFor(async () => {
|
|
600
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '100');
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
await userEvent.keyboard('{Home}');
|
|
604
|
+
await waitFor(async () => {
|
|
605
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '0');
|
|
606
|
+
});
|
|
607
|
+
},
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
await step(
|
|
611
|
+
'interaction: the value never leaves the allowed range',
|
|
612
|
+
async () => {
|
|
613
|
+
await userEvent.keyboard('{ArrowLeft}');
|
|
614
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '0');
|
|
615
|
+
await expect(valueNow(handle)).toBeGreaterThanOrEqual(0);
|
|
616
|
+
await expect(valueNow(handle)).toBeLessThanOrEqual(100);
|
|
617
|
+
},
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
await step(
|
|
621
|
+
'interaction: each move is fed back through the controlled value and committed',
|
|
622
|
+
async () => {
|
|
623
|
+
await expect(canvas.getByText('Value: 0')).toBeInTheDocument();
|
|
624
|
+
await expect(onUpdateModelValue).toHaveBeenCalledWith([55]);
|
|
625
|
+
await expect(onUpdateModelValue).toHaveBeenLastCalledWith([0]);
|
|
626
|
+
// The blocked ArrowLeft at the minimum must not commit anything.
|
|
627
|
+
await expect(onValueCommit).toHaveBeenCalledTimes(4);
|
|
628
|
+
await expect(onValueCommit).toHaveBeenLastCalledWith([0]);
|
|
629
|
+
},
|
|
630
|
+
);
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* A range slider keeps one Tab stop per handle and enforces the minimum gap
|
|
636
|
+
* between them, so the lower handle can never cross the upper one. Hidden
|
|
637
|
+
* test-only story.
|
|
638
|
+
*/
|
|
639
|
+
export const KeyboardRangeNavigation: Story = {
|
|
640
|
+
name: 'test - Keyboard Range Navigation',
|
|
641
|
+
tags: ['!dev', '!autodocs'],
|
|
642
|
+
parameters: {
|
|
643
|
+
// Focus moves and the value changes during the play function.
|
|
644
|
+
chromatic: { disableSnapshot: true },
|
|
645
|
+
docs: {
|
|
646
|
+
description: {
|
|
647
|
+
story:
|
|
648
|
+
'Tab between the two handles, then hold `Shift` with an arrow key to move in larger jumps.',
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
render: () => ({
|
|
653
|
+
components: { UiSlider },
|
|
654
|
+
setup() {
|
|
655
|
+
const range = ref([25, 75]);
|
|
656
|
+
const update = (next: number[]) => {
|
|
657
|
+
range.value = next;
|
|
658
|
+
onUpdateModelValue(next);
|
|
659
|
+
};
|
|
660
|
+
return { range, update };
|
|
661
|
+
},
|
|
662
|
+
template: `
|
|
663
|
+
<div class="w-full max-w-72">
|
|
664
|
+
<p class="label-14-medium text-content-on-surface-primary">Price range</p>
|
|
665
|
+
<div class="my-3">
|
|
666
|
+
<UiSlider
|
|
667
|
+
:model-value="range"
|
|
668
|
+
:min="0"
|
|
669
|
+
:max="100"
|
|
670
|
+
:step="1"
|
|
671
|
+
:min-steps-between-thumbs="5"
|
|
672
|
+
@update:model-value="update"
|
|
673
|
+
/>
|
|
674
|
+
</div>
|
|
675
|
+
<p class="body-14-regular text-content-on-surface-muted">Range: {{ range[0] }} – {{ range[1] }}</p>
|
|
676
|
+
</div>
|
|
677
|
+
`,
|
|
678
|
+
}),
|
|
679
|
+
play: async ({ canvasElement, step }) => {
|
|
680
|
+
// Scenario (UiSlider): a keyboard user tabs across both handles and pushes
|
|
681
|
+
// the lower one upwards until the minimum gap stops it.
|
|
682
|
+
onUpdateModelValue.mockClear();
|
|
683
|
+
const canvas = within(canvasElement);
|
|
684
|
+
const lower = canvas.getByRole('slider', { name: 'Value 1' });
|
|
685
|
+
const upper = canvas.getByRole('slider', { name: 'Value 2' });
|
|
686
|
+
|
|
687
|
+
await step(
|
|
688
|
+
'keyboard: Tab reaches each handle in order (WCAG 2.4.3)',
|
|
689
|
+
async () => {
|
|
690
|
+
await userEvent.tab();
|
|
691
|
+
await expect(lower).toHaveFocus();
|
|
692
|
+
await userEvent.tab();
|
|
693
|
+
await expect(upper).toHaveFocus();
|
|
694
|
+
},
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
await step(
|
|
698
|
+
'keyboard: Shift + arrow moves the focused handle in a larger jump',
|
|
699
|
+
async () => {
|
|
700
|
+
await userEvent.keyboard('{Shift>}{ArrowRight}{/Shift}');
|
|
701
|
+
await waitFor(async () => {
|
|
702
|
+
await expect(upper).toHaveAttribute('aria-valuenow', '85');
|
|
703
|
+
});
|
|
704
|
+
},
|
|
705
|
+
);
|
|
706
|
+
|
|
707
|
+
await step(
|
|
708
|
+
'interaction: the lower handle cannot cross the upper one',
|
|
709
|
+
async () => {
|
|
710
|
+
lower.focus();
|
|
711
|
+
for (let press = 0; press < 12; press += 1) {
|
|
712
|
+
await userEvent.keyboard('{Shift>}{ArrowRight}{/Shift}');
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
await waitFor(async () => {
|
|
716
|
+
await expect(valueNow(lower)).toBeLessThan(valueNow(upper));
|
|
717
|
+
});
|
|
718
|
+
// `minStepsBetweenThumbs` is 5 at a step of 1, so the gap must hold.
|
|
719
|
+
await expect(valueNow(upper) - valueNow(lower)).toBeGreaterThanOrEqual(
|
|
720
|
+
5,
|
|
721
|
+
);
|
|
722
|
+
},
|
|
723
|
+
);
|
|
724
|
+
|
|
725
|
+
await step(
|
|
726
|
+
'interaction: every emitted pair stays inside the allowed range',
|
|
727
|
+
async () => {
|
|
728
|
+
const emitted = onUpdateModelValue.mock.calls.map(
|
|
729
|
+
([next]) => next as number[],
|
|
730
|
+
);
|
|
731
|
+
await expect(emitted.length).toBeGreaterThan(0);
|
|
732
|
+
|
|
733
|
+
for (const next of emitted) {
|
|
734
|
+
await expect(next).toHaveLength(2);
|
|
735
|
+
for (const value of next) {
|
|
736
|
+
await expect(value).toBeGreaterThanOrEqual(0);
|
|
737
|
+
await expect(value).toBeLessThanOrEqual(100);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
);
|
|
742
|
+
},
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Screen-reader semantics: every handle exposes the slider role, its own name,
|
|
747
|
+
* and the current, minimum, and maximum values it sits between — updated as it
|
|
748
|
+
* moves. Hidden test-only story.
|
|
749
|
+
*/
|
|
750
|
+
export const ScreenReader: Story = {
|
|
751
|
+
name: 'test - Screen Reader',
|
|
752
|
+
tags: ['!dev', '!autodocs'],
|
|
753
|
+
parameters: {
|
|
754
|
+
// Focus moves and the value changes during the play function.
|
|
755
|
+
chromatic: { disableSnapshot: true },
|
|
756
|
+
docs: {
|
|
757
|
+
description: {
|
|
758
|
+
story:
|
|
759
|
+
'Verifies the role, name, and value range that assistive technology announces for each handle.',
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
render: () => renderControlledSlider(5),
|
|
764
|
+
play: async ({ canvasElement, step }) => {
|
|
765
|
+
// Scenario (UiSlider): assistive tech reads the handle as a slider named
|
|
766
|
+
// "Value", hears where it sits in the range, and hears the new value after
|
|
767
|
+
// every key press.
|
|
768
|
+
onUpdateModelValue.mockClear();
|
|
769
|
+
onValueCommit.mockClear();
|
|
770
|
+
const canvas = within(canvasElement);
|
|
771
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
772
|
+
|
|
773
|
+
await step(
|
|
774
|
+
'screen-reader: the handle exposes a slider role with an accessible name (WCAG 4.1.2)',
|
|
775
|
+
async () => {
|
|
776
|
+
await expect(handle).toHaveAccessibleName('Value');
|
|
777
|
+
await expect(handle).toHaveAttribute('aria-orientation', 'horizontal');
|
|
778
|
+
},
|
|
779
|
+
);
|
|
780
|
+
|
|
781
|
+
await step(
|
|
782
|
+
'screen-reader: announces its current, minimum, and maximum values',
|
|
783
|
+
async () => {
|
|
784
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
785
|
+
await expect(handle).toHaveAttribute('aria-valuemin', '0');
|
|
786
|
+
await expect(handle).toHaveAttribute('aria-valuemax', '100');
|
|
787
|
+
},
|
|
788
|
+
);
|
|
789
|
+
|
|
790
|
+
await step(
|
|
791
|
+
'screen-reader: aria-valuenow follows the value as the handle moves',
|
|
792
|
+
async () => {
|
|
793
|
+
await userEvent.tab();
|
|
794
|
+
await expect(handle).toHaveFocus();
|
|
795
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
796
|
+
|
|
797
|
+
await waitFor(async () => {
|
|
798
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '55');
|
|
799
|
+
});
|
|
800
|
+
},
|
|
801
|
+
);
|
|
802
|
+
|
|
803
|
+
await step(
|
|
804
|
+
'screen-reader: the visible readout matches the announced value',
|
|
805
|
+
async () => {
|
|
806
|
+
await expect(canvas.getByText('Value: 55')).toBeInTheDocument();
|
|
807
|
+
},
|
|
808
|
+
);
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
814
|
+
* try 400% reflow (WCAG 1.4.10); the slider must stay visible and operable.
|
|
815
|
+
* Hidden test-only story.
|
|
816
|
+
*/
|
|
817
|
+
export const ZoomMagnification: Story = {
|
|
818
|
+
name: 'test - Zoom Magnification',
|
|
819
|
+
tags: ['!dev', '!autodocs'],
|
|
820
|
+
globals: { zoom: '200' },
|
|
821
|
+
parameters: {
|
|
822
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
823
|
+
// already covers magnified snapshots, so skip this one.
|
|
824
|
+
chromatic: { disableSnapshot: true },
|
|
825
|
+
docs: {
|
|
826
|
+
description: {
|
|
827
|
+
story:
|
|
828
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
},
|
|
832
|
+
render: () => renderControlledSlider(5),
|
|
833
|
+
play: async ({ canvasElement, step }) => {
|
|
834
|
+
// Scenario (UiSlider): at 200% page zoom the slider stays on screen, keeps
|
|
835
|
+
// its accessible name, and still responds to the arrow keys.
|
|
836
|
+
onUpdateModelValue.mockClear();
|
|
837
|
+
onValueCommit.mockClear();
|
|
838
|
+
const canvas = within(canvasElement);
|
|
839
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
840
|
+
|
|
841
|
+
await step(
|
|
842
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
843
|
+
async () => {
|
|
844
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
845
|
+
},
|
|
846
|
+
);
|
|
847
|
+
|
|
848
|
+
await step(
|
|
849
|
+
'zoom: the slider stays visible with its accessible name',
|
|
850
|
+
async () => {
|
|
851
|
+
await expect(handle).toBeVisible();
|
|
852
|
+
await expect(handle).toHaveAccessibleName('Value');
|
|
853
|
+
|
|
854
|
+
const { left, right } = handle.getBoundingClientRect();
|
|
855
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
856
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth);
|
|
857
|
+
},
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
await step('zoom: remains operable when magnified', async () => {
|
|
861
|
+
await userEvent.tab();
|
|
862
|
+
await expect(handle).toHaveFocus();
|
|
863
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
864
|
+
|
|
865
|
+
await waitFor(async () => {
|
|
866
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '55');
|
|
867
|
+
});
|
|
868
|
+
await expect(canvas.getByText('Value: 55')).toBeInTheDocument();
|
|
869
|
+
});
|
|
870
|
+
},
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
875
|
+
* toolbar. Stays operable, fits without sideways scrolling, and documents the
|
|
876
|
+
* handle's target size. Hidden test-only story.
|
|
877
|
+
*/
|
|
878
|
+
export const MobileBreakpoint: Story = {
|
|
879
|
+
name: 'test - Mobile Breakpoint',
|
|
880
|
+
tags: ['!dev', '!autodocs'],
|
|
881
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
882
|
+
parameters: {
|
|
883
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
884
|
+
chromatic: { disableSnapshot: true },
|
|
885
|
+
docs: {
|
|
886
|
+
description: {
|
|
887
|
+
story:
|
|
888
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
render: () => renderControlledSlider(5),
|
|
893
|
+
play: async ({ canvasElement, step }) => {
|
|
894
|
+
// Scenario (UiSlider): at the 320px mobile breakpoint the slider fits the
|
|
895
|
+
// viewport, stays operable, and its handle has room around it for touch.
|
|
896
|
+
onUpdateModelValue.mockClear();
|
|
897
|
+
onValueCommit.mockClear();
|
|
898
|
+
const canvas = within(canvasElement);
|
|
899
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
900
|
+
const track = canvasElement.querySelector(
|
|
901
|
+
'[data-slot="slider-track"]',
|
|
902
|
+
) as HTMLElement;
|
|
903
|
+
|
|
904
|
+
await step(
|
|
905
|
+
'mobile: fits the 320px breakpoint without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
906
|
+
async () => {
|
|
907
|
+
await expect(handle).toBeVisible();
|
|
908
|
+
|
|
909
|
+
const { left, right } = track.getBoundingClientRect();
|
|
910
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
911
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth);
|
|
912
|
+
},
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
await step(
|
|
916
|
+
'mobile: stays operable at the 320px breakpoint — Tab focuses the handle and arrows adjust it',
|
|
917
|
+
async () => {
|
|
918
|
+
await userEvent.tab();
|
|
919
|
+
await expect(handle).toHaveFocus();
|
|
920
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
921
|
+
|
|
922
|
+
await waitFor(async () => {
|
|
923
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '55');
|
|
924
|
+
});
|
|
925
|
+
},
|
|
926
|
+
);
|
|
927
|
+
|
|
928
|
+
await step(
|
|
929
|
+
'mobile: the handle target is usable for touch (WCAG 2.5.8)',
|
|
930
|
+
async () => {
|
|
931
|
+
const { width, height } = handle.getBoundingClientRect();
|
|
932
|
+
// The visible handle is 16px, under the 24px minimum, so it relies on
|
|
933
|
+
// the 2.5.8 spacing exception: it is the only target here, so a 24px
|
|
934
|
+
// circle centred on it can't overlap another one. The full-width track
|
|
935
|
+
// it sits on is draggable, which widens the effective target.
|
|
936
|
+
await expect(width).toBeGreaterThanOrEqual(16);
|
|
937
|
+
await expect(height).toBeGreaterThanOrEqual(16);
|
|
938
|
+
await expect(canvas.getAllByRole('slider')).toHaveLength(1);
|
|
939
|
+
await expect(
|
|
940
|
+
track.getBoundingClientRect().width,
|
|
941
|
+
).toBeGreaterThanOrEqual(24);
|
|
942
|
+
},
|
|
943
|
+
);
|
|
944
|
+
},
|
|
229
945
|
};
|