@aleph-alpha/ui-library 5.6.0 → 5.8.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 +4 -0
- package/config.d.ts +5 -1
- package/config.js +23 -1
- package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
- package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
- package/dist/system/components/UiField/types.d.ts +2 -1
- package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
- package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
- package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
- package/dist/system/components/core/listbox/context.d.ts +21 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +10062 -9711
- package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
- package/dist/system/story-sidebar-icons.json +6 -0
- package/package.json +5 -5
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +1 -1
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
- package/src/components/UiBreadcrumb/index.ts +8 -0
- package/src/components/UiBreadcrumb/types.ts +28 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
- package/src/components/UiField/UiField.stories.ts +1 -1
- package/src/components/UiField/types.ts +2 -1
- package/src/components/UiListbox/UiListbox.stories.ts +1283 -30
- package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
- package/src/components/UiSelect/UiSelect.stories.ts +1 -1
- package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
- package/src/components/UiToggle/UiToggle.stories.ts +961 -130
- package/src/components/UiToggle/UiToggle.vue +8 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
- package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
- package/src/components/UiToggleGroup/types.ts +0 -5
- package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
- package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
- package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
- package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
- package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/src/components/core/breadcrumb/index.ts +7 -0
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +3 -2
- package/src/components/core/field/FieldTitle.vue +1 -1
- package/src/components/core/listbox/Listbox.vue +14 -2
- package/src/components/core/listbox/ListboxContent.vue +61 -3
- package/src/components/core/listbox/ListboxItem.vue +6 -1
- package/src/components/core/listbox/context.ts +34 -0
- package/src/components/core/toggle/Toggle.vue +15 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
- package/src/components/core/toggle-group/index.ts +5 -2
- package/src/components/index.ts +1 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
- package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
2
3
|
import { UiRadioGroup, UiRadioGroupItem } from './index';
|
|
4
|
+
import {
|
|
5
|
+
UiField,
|
|
6
|
+
UiFieldContent,
|
|
7
|
+
UiFieldDescription,
|
|
8
|
+
UiFieldGroup,
|
|
9
|
+
UiFieldLabel,
|
|
10
|
+
UiFieldLegend,
|
|
11
|
+
UiFieldSet,
|
|
12
|
+
UiFieldTitle,
|
|
13
|
+
} from '../UiField';
|
|
3
14
|
import { ref, watch } from 'vue';
|
|
4
15
|
|
|
5
16
|
/**
|
|
@@ -102,6 +113,48 @@ export const Default: Story = {
|
|
|
102
113
|
},
|
|
103
114
|
},
|
|
104
115
|
},
|
|
116
|
+
play: async ({ canvasElement, step }) => {
|
|
117
|
+
// Scenario (UiRadioGroup): the resting vertical group — assistive tech
|
|
118
|
+
// reads a radiogroup containing named radios, exactly one of which reports
|
|
119
|
+
// itself as checked. Non-mutating so the primary snapshot stays stable.
|
|
120
|
+
const canvas = within(canvasElement);
|
|
121
|
+
|
|
122
|
+
await step(
|
|
123
|
+
'screen-reader: the group exposes a radiogroup containing named radios (WCAG 1.3.1 / 4.1.2)',
|
|
124
|
+
async () => {
|
|
125
|
+
const group = canvas.getByRole('radiogroup');
|
|
126
|
+
const radios = within(group).getAllByRole('radio');
|
|
127
|
+
await expect(radios).toHaveLength(3);
|
|
128
|
+
await expect(radios[0]).toHaveAccessibleName('Default');
|
|
129
|
+
await expect(radios[1]).toHaveAccessibleName('Comfortable');
|
|
130
|
+
await expect(radios[2]).toHaveAccessibleName('Compact');
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
await step(
|
|
135
|
+
'screen-reader: exactly one option announces itself as selected (WCAG 4.1.2)',
|
|
136
|
+
async () => {
|
|
137
|
+
const checked = canvas
|
|
138
|
+
.getAllByRole('radio')
|
|
139
|
+
.filter((radio) => radio.getAttribute('aria-checked') === 'true');
|
|
140
|
+
await expect(checked).toHaveLength(1);
|
|
141
|
+
await expect(checked[0]).toHaveAccessibleName('Comfortable');
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
await step(
|
|
146
|
+
'interaction: options stack in a vertical layout (WCAG 1.3.2 Meaningful Sequence)',
|
|
147
|
+
async () => {
|
|
148
|
+
const group = canvas.getByRole('radiogroup');
|
|
149
|
+
await expect(group).toHaveAttribute('data-orientation', 'vertical');
|
|
150
|
+
const [first, , last] = within(group).getAllByRole('radio');
|
|
151
|
+
// Stacked rows: each option starts below the previous one.
|
|
152
|
+
await expect(last.getBoundingClientRect().top).toBeGreaterThan(
|
|
153
|
+
first.getBoundingClientRect().top,
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
},
|
|
105
158
|
};
|
|
106
159
|
|
|
107
160
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
@@ -162,6 +215,34 @@ export const Disabled: Story = {
|
|
|
162
215
|
},
|
|
163
216
|
},
|
|
164
217
|
},
|
|
218
|
+
play: async ({ canvasElement, step }) => {
|
|
219
|
+
// Scenario (UiRadioGroupItem): a single disabled option stays visible and
|
|
220
|
+
// announced, but refuses activation. The forced click is a no-op, so the
|
|
221
|
+
// snapshot still shows the resting state.
|
|
222
|
+
const canvas = within(canvasElement);
|
|
223
|
+
const comfortable = canvas.getByRole('radio', { name: 'Comfortable' });
|
|
224
|
+
|
|
225
|
+
await step(
|
|
226
|
+
'screen-reader: the disabled option announces its disabled state (WCAG 4.1.2)',
|
|
227
|
+
async () => {
|
|
228
|
+
await expect(comfortable).toBeVisible();
|
|
229
|
+
await expect(comfortable).toBeDisabled();
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
await step(
|
|
234
|
+
'interaction: a disabled option cannot be selected (WCAG 4.1.2)',
|
|
235
|
+
async () => {
|
|
236
|
+
// Disabled items render with pointer-events: none, so bypass the check
|
|
237
|
+
// and assert the click is still a no-op.
|
|
238
|
+
await userEvent.click(comfortable, { pointerEventsCheck: 0 });
|
|
239
|
+
await expect(comfortable).toHaveAttribute('aria-checked', 'false');
|
|
240
|
+
await expect(
|
|
241
|
+
canvas.getByRole('radio', { name: 'Default' }),
|
|
242
|
+
).toBeChecked();
|
|
243
|
+
},
|
|
244
|
+
);
|
|
245
|
+
},
|
|
165
246
|
};
|
|
166
247
|
|
|
167
248
|
const horizontalTemplateSource = `<script setup lang="ts">
|
|
@@ -233,6 +314,33 @@ export const HorizontalOrientation: Story = {
|
|
|
233
314
|
},
|
|
234
315
|
},
|
|
235
316
|
},
|
|
317
|
+
play: async ({ canvasElement, step }) => {
|
|
318
|
+
// Scenario (UiRadioGroup): the horizontal layout lays every option on a
|
|
319
|
+
// single row and reports that orientation to assistive tech, which is what
|
|
320
|
+
// tells a screen reader to expect Left/Right arrow navigation.
|
|
321
|
+
const canvas = within(canvasElement);
|
|
322
|
+
const group = canvas.getByRole('radiogroup');
|
|
323
|
+
|
|
324
|
+
await step(
|
|
325
|
+
'interaction: options share a single row in the horizontal layout',
|
|
326
|
+
async () => {
|
|
327
|
+
const [first, , last] = within(group).getAllByRole('radio');
|
|
328
|
+
await expect(last.getBoundingClientRect().top).toBe(
|
|
329
|
+
first.getBoundingClientRect().top,
|
|
330
|
+
);
|
|
331
|
+
await expect(last.getBoundingClientRect().left).toBeGreaterThan(
|
|
332
|
+
first.getBoundingClientRect().left,
|
|
333
|
+
);
|
|
334
|
+
},
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
await step(
|
|
338
|
+
'screen-reader: the group announces its horizontal orientation (WCAG 1.3.1)',
|
|
339
|
+
async () => {
|
|
340
|
+
await expect(group).toHaveAttribute('data-orientation', 'horizontal');
|
|
341
|
+
},
|
|
342
|
+
);
|
|
343
|
+
},
|
|
236
344
|
};
|
|
237
345
|
|
|
238
346
|
const asChildTemplateSource = `<script setup lang="ts">
|
|
@@ -292,4 +400,891 @@ export const AsChild: Story = {
|
|
|
292
400
|
},
|
|
293
401
|
},
|
|
294
402
|
},
|
|
403
|
+
play: async ({ canvasElement, step }) => {
|
|
404
|
+
// Scenario (UiRadioGroup as-child): the group merges onto the slotted
|
|
405
|
+
// <fieldset>, so the <legend> becomes the radiogroup's accessible name
|
|
406
|
+
// instead of leaving the option set unlabelled.
|
|
407
|
+
const canvas = within(canvasElement);
|
|
408
|
+
|
|
409
|
+
await step(
|
|
410
|
+
'screen-reader: the labelled container names the radiogroup (WCAG 1.3.1 / 4.1.2)',
|
|
411
|
+
async () => {
|
|
412
|
+
const group = canvas.getByRole('radiogroup', {
|
|
413
|
+
name: 'Select an option',
|
|
414
|
+
});
|
|
415
|
+
await expect(group.tagName).toBe('FIELDSET');
|
|
416
|
+
await expect(within(group).getAllByRole('radio')).toHaveLength(2);
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const withFieldTemplateSource = `<script setup lang="ts">
|
|
423
|
+
import { ref } from 'vue'
|
|
424
|
+
import {
|
|
425
|
+
UiField,
|
|
426
|
+
UiFieldContent,
|
|
427
|
+
UiFieldDescription,
|
|
428
|
+
UiFieldGroup,
|
|
429
|
+
UiFieldLabel,
|
|
430
|
+
UiFieldLegend,
|
|
431
|
+
UiFieldSet,
|
|
432
|
+
UiFieldTitle,
|
|
433
|
+
UiRadioGroup,
|
|
434
|
+
UiRadioGroupItem,
|
|
435
|
+
} from '@aleph-alpha/ui-library'
|
|
436
|
+
|
|
437
|
+
const environmentEnd = ref('kubernetes')
|
|
438
|
+
const environmentStart = ref('kubernetes')
|
|
439
|
+
</script>
|
|
440
|
+
|
|
441
|
+
<template>
|
|
442
|
+
<div class="grid w-full max-w-3xl gap-6 md:grid-cols-2">
|
|
443
|
+
<!-- Control at the end: text first, radio trailing. -->
|
|
444
|
+
<UiFieldGroup>
|
|
445
|
+
<UiFieldSet>
|
|
446
|
+
<UiFieldLegend variant="label">Compute Environment</UiFieldLegend>
|
|
447
|
+
<UiFieldDescription>
|
|
448
|
+
Select the compute environment for your cluster.
|
|
449
|
+
</UiFieldDescription>
|
|
450
|
+
|
|
451
|
+
<UiRadioGroup v-model="environmentEnd" name="compute-environment-end">
|
|
452
|
+
<UiFieldLabel for="end-kubernetes">
|
|
453
|
+
<UiField orientation="horizontal">
|
|
454
|
+
<UiFieldContent>
|
|
455
|
+
<UiFieldTitle>Kubernetes</UiFieldTitle>
|
|
456
|
+
<UiFieldDescription>
|
|
457
|
+
Run GPU workloads on a K8s configured cluster.
|
|
458
|
+
</UiFieldDescription>
|
|
459
|
+
</UiFieldContent>
|
|
460
|
+
<UiRadioGroupItem id="end-kubernetes" value="kubernetes" />
|
|
461
|
+
</UiField>
|
|
462
|
+
</UiFieldLabel>
|
|
463
|
+
|
|
464
|
+
<UiFieldLabel for="end-vm">
|
|
465
|
+
<UiField orientation="horizontal">
|
|
466
|
+
<UiFieldContent>
|
|
467
|
+
<UiFieldTitle>Virtual Machine</UiFieldTitle>
|
|
468
|
+
<UiFieldDescription>
|
|
469
|
+
Access a VM configured cluster to run GPU workloads.
|
|
470
|
+
</UiFieldDescription>
|
|
471
|
+
</UiFieldContent>
|
|
472
|
+
<UiRadioGroupItem id="end-vm" value="vm" />
|
|
473
|
+
</UiField>
|
|
474
|
+
</UiFieldLabel>
|
|
475
|
+
</UiRadioGroup>
|
|
476
|
+
</UiFieldSet>
|
|
477
|
+
</UiFieldGroup>
|
|
478
|
+
|
|
479
|
+
<!-- Control at the start: radio leading, text after. -->
|
|
480
|
+
<UiFieldGroup>
|
|
481
|
+
<UiFieldSet>
|
|
482
|
+
<UiFieldLegend variant="label">Compute Environment</UiFieldLegend>
|
|
483
|
+
<UiFieldDescription>
|
|
484
|
+
Select the compute environment for your cluster.
|
|
485
|
+
</UiFieldDescription>
|
|
486
|
+
|
|
487
|
+
<UiRadioGroup v-model="environmentStart" name="compute-environment-start">
|
|
488
|
+
<UiFieldLabel for="start-kubernetes">
|
|
489
|
+
<UiField orientation="horizontal">
|
|
490
|
+
<UiRadioGroupItem id="start-kubernetes" value="kubernetes" />
|
|
491
|
+
<UiFieldContent>
|
|
492
|
+
<UiFieldTitle>Kubernetes</UiFieldTitle>
|
|
493
|
+
<UiFieldDescription>
|
|
494
|
+
Run GPU workloads on a K8s configured cluster.
|
|
495
|
+
</UiFieldDescription>
|
|
496
|
+
</UiFieldContent>
|
|
497
|
+
</UiField>
|
|
498
|
+
</UiFieldLabel>
|
|
499
|
+
|
|
500
|
+
<UiFieldLabel for="start-vm">
|
|
501
|
+
<UiField orientation="horizontal">
|
|
502
|
+
<UiRadioGroupItem id="start-vm" value="vm" />
|
|
503
|
+
<UiFieldContent>
|
|
504
|
+
<UiFieldTitle>Virtual Machine</UiFieldTitle>
|
|
505
|
+
<UiFieldDescription>
|
|
506
|
+
Access a VM configured cluster to run GPU workloads.
|
|
507
|
+
</UiFieldDescription>
|
|
508
|
+
</UiFieldContent>
|
|
509
|
+
</UiField>
|
|
510
|
+
</UiFieldLabel>
|
|
511
|
+
</UiRadioGroup>
|
|
512
|
+
</UiFieldSet>
|
|
513
|
+
</UiFieldGroup>
|
|
514
|
+
</div>
|
|
515
|
+
</template>`;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Radio group composed with `UiField` as selectable cards, in both control placements.
|
|
519
|
+
* Wrapping a horizontal `UiField` in a `UiFieldLabel` turns the whole row into a
|
|
520
|
+
* bordered, clickable option that highlights when its radio is checked. Put the
|
|
521
|
+
* `UiRadioGroupItem` after `UiFieldContent` to trail the text, or before it to lead.
|
|
522
|
+
* Use this when each option needs a title plus supporting copy, instead of a bare label.
|
|
523
|
+
*/
|
|
524
|
+
export const WithField: Story = {
|
|
525
|
+
render: () => ({
|
|
526
|
+
components: {
|
|
527
|
+
UiField,
|
|
528
|
+
UiFieldContent,
|
|
529
|
+
UiFieldDescription,
|
|
530
|
+
UiFieldGroup,
|
|
531
|
+
UiFieldLabel,
|
|
532
|
+
UiFieldLegend,
|
|
533
|
+
UiFieldSet,
|
|
534
|
+
UiFieldTitle,
|
|
535
|
+
UiRadioGroup,
|
|
536
|
+
UiRadioGroupItem,
|
|
537
|
+
},
|
|
538
|
+
setup() {
|
|
539
|
+
const environmentEnd = ref('kubernetes');
|
|
540
|
+
const environmentStart = ref('kubernetes');
|
|
541
|
+
return { environmentEnd, environmentStart };
|
|
542
|
+
},
|
|
543
|
+
template: `
|
|
544
|
+
<div class="grid w-full max-w-3xl gap-6 md:grid-cols-2">
|
|
545
|
+
<UiFieldGroup>
|
|
546
|
+
<UiFieldSet>
|
|
547
|
+
<UiFieldLegend variant="label">Compute Environment (control at end)</UiFieldLegend>
|
|
548
|
+
<UiFieldDescription>
|
|
549
|
+
Select the compute environment for your cluster.
|
|
550
|
+
</UiFieldDescription>
|
|
551
|
+
|
|
552
|
+
<UiRadioGroup v-model="environmentEnd" name="compute-environment-end">
|
|
553
|
+
<UiFieldLabel for="end-kubernetes">
|
|
554
|
+
<UiField orientation="horizontal">
|
|
555
|
+
<UiFieldContent>
|
|
556
|
+
<UiFieldTitle>Kubernetes</UiFieldTitle>
|
|
557
|
+
<UiFieldDescription>
|
|
558
|
+
Run GPU workloads on a K8s configured cluster.
|
|
559
|
+
</UiFieldDescription>
|
|
560
|
+
</UiFieldContent>
|
|
561
|
+
<UiRadioGroupItem id="end-kubernetes" value="kubernetes" />
|
|
562
|
+
</UiField>
|
|
563
|
+
</UiFieldLabel>
|
|
564
|
+
|
|
565
|
+
<UiFieldLabel for="end-vm">
|
|
566
|
+
<UiField orientation="horizontal">
|
|
567
|
+
<UiFieldContent>
|
|
568
|
+
<UiFieldTitle>Virtual Machine</UiFieldTitle>
|
|
569
|
+
<UiFieldDescription>
|
|
570
|
+
Access a VM configured cluster to run GPU workloads.
|
|
571
|
+
</UiFieldDescription>
|
|
572
|
+
</UiFieldContent>
|
|
573
|
+
<UiRadioGroupItem id="end-vm" value="vm" />
|
|
574
|
+
</UiField>
|
|
575
|
+
</UiFieldLabel>
|
|
576
|
+
</UiRadioGroup>
|
|
577
|
+
</UiFieldSet>
|
|
578
|
+
</UiFieldGroup>
|
|
579
|
+
|
|
580
|
+
<UiFieldGroup>
|
|
581
|
+
<UiFieldSet>
|
|
582
|
+
<UiFieldLegend variant="label">Compute Environment (control at start)</UiFieldLegend>
|
|
583
|
+
<UiFieldDescription>
|
|
584
|
+
Select the compute environment for your cluster.
|
|
585
|
+
</UiFieldDescription>
|
|
586
|
+
|
|
587
|
+
<UiRadioGroup v-model="environmentStart" name="compute-environment-start">
|
|
588
|
+
<UiFieldLabel for="start-kubernetes">
|
|
589
|
+
<UiField orientation="horizontal">
|
|
590
|
+
<UiRadioGroupItem id="start-kubernetes" value="kubernetes" />
|
|
591
|
+
<UiFieldContent>
|
|
592
|
+
<UiFieldTitle>Kubernetes</UiFieldTitle>
|
|
593
|
+
<UiFieldDescription>
|
|
594
|
+
Run GPU workloads on a K8s configured cluster.
|
|
595
|
+
</UiFieldDescription>
|
|
596
|
+
</UiFieldContent>
|
|
597
|
+
</UiField>
|
|
598
|
+
</UiFieldLabel>
|
|
599
|
+
|
|
600
|
+
<UiFieldLabel for="start-vm">
|
|
601
|
+
<UiField orientation="horizontal">
|
|
602
|
+
<UiRadioGroupItem id="start-vm" value="vm" />
|
|
603
|
+
<UiFieldContent>
|
|
604
|
+
<UiFieldTitle>Virtual Machine</UiFieldTitle>
|
|
605
|
+
<UiFieldDescription>
|
|
606
|
+
Access a VM configured cluster to run GPU workloads.
|
|
607
|
+
</UiFieldDescription>
|
|
608
|
+
</UiFieldContent>
|
|
609
|
+
</UiField>
|
|
610
|
+
</UiFieldLabel>
|
|
611
|
+
</UiRadioGroup>
|
|
612
|
+
</UiFieldSet>
|
|
613
|
+
</UiFieldGroup>
|
|
614
|
+
</div>
|
|
615
|
+
`,
|
|
616
|
+
}),
|
|
617
|
+
parameters: {
|
|
618
|
+
controls: { disable: true },
|
|
619
|
+
docs: {
|
|
620
|
+
source: {
|
|
621
|
+
code: withFieldTemplateSource,
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
play: async ({ canvasElement, step }) => {
|
|
626
|
+
// Scenario: each card is a label wired to its radio, so the title and
|
|
627
|
+
// description become the radio's accessible name regardless of whether the
|
|
628
|
+
// control leads or trails. Non-mutating so the primary snapshot stays stable.
|
|
629
|
+
const canvas = within(canvasElement);
|
|
630
|
+
|
|
631
|
+
await step(
|
|
632
|
+
'screen-reader: each fieldset is a group named by its legend (WCAG 1.3.1)',
|
|
633
|
+
async () => {
|
|
634
|
+
const groups = canvas.getAllByRole('group', {
|
|
635
|
+
name: /Compute Environment/,
|
|
636
|
+
});
|
|
637
|
+
await expect(groups).toHaveLength(2);
|
|
638
|
+
},
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
await step(
|
|
642
|
+
'screen-reader: card labels name their radios in both placements (WCAG 1.3.1 / 4.1.2)',
|
|
643
|
+
async () => {
|
|
644
|
+
const kubernetes = canvas.getAllByRole('radio', { name: /Kubernetes/ });
|
|
645
|
+
const vm = canvas.getAllByRole('radio', { name: /Virtual Machine/ });
|
|
646
|
+
await expect(kubernetes).toHaveLength(2);
|
|
647
|
+
await expect(vm).toHaveLength(2);
|
|
648
|
+
for (const radio of kubernetes) await expect(radio).toBeChecked();
|
|
649
|
+
for (const radio of vm) await expect(radio).not.toBeChecked();
|
|
650
|
+
},
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
await step(
|
|
654
|
+
'interaction: the selected card is distinguished by more than colour alone (WCAG 1.4.1)',
|
|
655
|
+
async () => {
|
|
656
|
+
// The card highlight is driven by `data-state`, which the label styles
|
|
657
|
+
// key off — so the selected state is exposed in the DOM, not only in
|
|
658
|
+
// the rendered colour.
|
|
659
|
+
for (const radio of canvas.getAllByRole('radio', {
|
|
660
|
+
name: /Kubernetes/,
|
|
661
|
+
})) {
|
|
662
|
+
await expect(radio).toHaveAttribute('data-state', 'checked');
|
|
663
|
+
}
|
|
664
|
+
for (const radio of canvas.getAllByRole('radio', {
|
|
665
|
+
name: /Virtual Machine/,
|
|
666
|
+
})) {
|
|
667
|
+
await expect(radio).toHaveAttribute('data-state', 'unchecked');
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
);
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Accessibility guidance for radio groups: a named group, labels wired to every
|
|
676
|
+
* option, and disabled options that stay visible — shown side by side in the
|
|
677
|
+
* default and accessible themes.
|
|
678
|
+
*/
|
|
679
|
+
export const Accessibility: Story = {
|
|
680
|
+
tags: ['!autodocs'],
|
|
681
|
+
parameters: {
|
|
682
|
+
a11y: { test: 'off' },
|
|
683
|
+
chromatic: { disableSnapshot: true },
|
|
684
|
+
docs: {
|
|
685
|
+
canvas: {
|
|
686
|
+
sourceState: 'none',
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
render: () => ({
|
|
691
|
+
components: { UiRadioGroup, UiRadioGroupItem },
|
|
692
|
+
setup() {
|
|
693
|
+
const defaultValue = ref('comfortable');
|
|
694
|
+
const accessibleValue = ref('comfortable');
|
|
695
|
+
return { defaultValue, accessibleValue };
|
|
696
|
+
},
|
|
697
|
+
template: `
|
|
698
|
+
<section class="flex flex-col gap-6 p-4">
|
|
699
|
+
<div>
|
|
700
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
701
|
+
Accessibility
|
|
702
|
+
</h2>
|
|
703
|
+
</div>
|
|
704
|
+
|
|
705
|
+
<div class="flex flex-col gap-6">
|
|
706
|
+
<div class="flex flex-col gap-2">
|
|
707
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
708
|
+
Give the group a name
|
|
709
|
+
</h3>
|
|
710
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
711
|
+
A radio group only makes sense as a set. Wrap it in a
|
|
712
|
+
<code>fieldset</code> with a <code>legend</code> (via
|
|
713
|
+
<code>as-child</code>), or set <code>aria-label</code>, so the
|
|
714
|
+
question is announced before the options.
|
|
715
|
+
</p>
|
|
716
|
+
</div>
|
|
717
|
+
|
|
718
|
+
<div class="flex flex-col gap-2">
|
|
719
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
720
|
+
Label every option
|
|
721
|
+
</h3>
|
|
722
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
723
|
+
Pair each <code>UiRadioGroupItem</code> with a
|
|
724
|
+
<code>label</code> whose <code>for</code> matches the item
|
|
725
|
+
<code>id</code>. The label becomes the option's accessible name
|
|
726
|
+
and makes the text itself clickable.
|
|
727
|
+
</p>
|
|
728
|
+
</div>
|
|
729
|
+
|
|
730
|
+
<div class="flex flex-col gap-2">
|
|
731
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
732
|
+
Keep disabled options visible
|
|
733
|
+
</h3>
|
|
734
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
735
|
+
A disabled option stays in the group so users see the full set of
|
|
736
|
+
choices. Arrow-key navigation skips it, and it announces its
|
|
737
|
+
disabled state rather than disappearing.
|
|
738
|
+
</p>
|
|
739
|
+
</div>
|
|
740
|
+
|
|
741
|
+
<div class="flex flex-col gap-2">
|
|
742
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
743
|
+
Enable accessibility theme
|
|
744
|
+
</h3>
|
|
745
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
746
|
+
When accessibility is required, enable our accessibility theme.
|
|
747
|
+
This increases contrast and makes sure there are no color
|
|
748
|
+
contrast issues.
|
|
749
|
+
</p>
|
|
750
|
+
</div>
|
|
751
|
+
</div>
|
|
752
|
+
|
|
753
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
754
|
+
<div class="flex flex-col gap-3">
|
|
755
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
756
|
+
Default
|
|
757
|
+
</h3>
|
|
758
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
759
|
+
<UiRadioGroup v-model="defaultValue" name="spacing-default" as-child>
|
|
760
|
+
<fieldset>
|
|
761
|
+
<legend class="mb-3 label-14-medium">Spacing</legend>
|
|
762
|
+
<div class="grid gap-3">
|
|
763
|
+
<div class="flex items-center gap-x-2">
|
|
764
|
+
<UiRadioGroupItem id="a11y-default-1" value="default" />
|
|
765
|
+
<label for="a11y-default-1" class="label-14-medium">Default</label>
|
|
766
|
+
</div>
|
|
767
|
+
<div class="flex items-center gap-x-2">
|
|
768
|
+
<UiRadioGroupItem id="a11y-default-2" value="comfortable" />
|
|
769
|
+
<label for="a11y-default-2" class="label-14-medium">Comfortable</label>
|
|
770
|
+
</div>
|
|
771
|
+
<div class="flex items-center gap-x-2">
|
|
772
|
+
<UiRadioGroupItem id="a11y-default-3" value="compact" disabled />
|
|
773
|
+
<label for="a11y-default-3" class="label-14-medium text-content-on-surface-muted">Compact (unavailable)</label>
|
|
774
|
+
</div>
|
|
775
|
+
</div>
|
|
776
|
+
</fieldset>
|
|
777
|
+
</UiRadioGroup>
|
|
778
|
+
</div>
|
|
779
|
+
</div>
|
|
780
|
+
|
|
781
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
782
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
783
|
+
Accessible
|
|
784
|
+
</h3>
|
|
785
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
786
|
+
<UiRadioGroup v-model="accessibleValue" name="spacing-accessible" as-child>
|
|
787
|
+
<fieldset>
|
|
788
|
+
<legend class="mb-3 label-14-medium">Spacing</legend>
|
|
789
|
+
<div class="grid gap-3">
|
|
790
|
+
<div class="flex items-center gap-x-2">
|
|
791
|
+
<UiRadioGroupItem id="a11y-accessible-1" value="default" />
|
|
792
|
+
<label for="a11y-accessible-1" class="label-14-medium">Default</label>
|
|
793
|
+
</div>
|
|
794
|
+
<div class="flex items-center gap-x-2">
|
|
795
|
+
<UiRadioGroupItem id="a11y-accessible-2" value="comfortable" />
|
|
796
|
+
<label for="a11y-accessible-2" class="label-14-medium">Comfortable</label>
|
|
797
|
+
</div>
|
|
798
|
+
<div class="flex items-center gap-x-2">
|
|
799
|
+
<UiRadioGroupItem id="a11y-accessible-3" value="compact" disabled />
|
|
800
|
+
<label for="a11y-accessible-3" class="label-14-medium text-content-on-surface-muted">Compact (unavailable)</label>
|
|
801
|
+
</div>
|
|
802
|
+
</div>
|
|
803
|
+
</fieldset>
|
|
804
|
+
</UiRadioGroup>
|
|
805
|
+
</div>
|
|
806
|
+
</div>
|
|
807
|
+
</div>
|
|
808
|
+
</section>
|
|
809
|
+
`,
|
|
810
|
+
}),
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
// Test-only stories drive the test-runner (interactive/a11y checks) but are
|
|
814
|
+
// hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
|
|
815
|
+
// tags. They keep the implicit `test` tag, so they still run in CI and appear
|
|
816
|
+
// in the automated report under their `test - …` name. `name`/`tags` must be
|
|
817
|
+
// literal properties so Storybook's static CSF indexer can read them.
|
|
818
|
+
|
|
819
|
+
// Shared render for the single-group scenarios: a named group whose middle
|
|
820
|
+
// option is disabled, so one fixture covers naming, selected/disabled states,
|
|
821
|
+
// and arrow-key skipping.
|
|
822
|
+
function renderTestRadioGroup() {
|
|
823
|
+
return {
|
|
824
|
+
components: { UiRadioGroup, UiRadioGroupItem },
|
|
825
|
+
setup() {
|
|
826
|
+
const spacing = ref('default');
|
|
827
|
+
return { spacing };
|
|
828
|
+
},
|
|
829
|
+
template: `
|
|
830
|
+
<UiRadioGroup v-model="spacing" name="spacing" aria-label="Spacing">
|
|
831
|
+
<div class="flex items-center gap-x-2">
|
|
832
|
+
<UiRadioGroupItem id="t-default" value="default" />
|
|
833
|
+
<label for="t-default" class="label-14-medium">Default</label>
|
|
834
|
+
</div>
|
|
835
|
+
<div class="flex items-center gap-x-2">
|
|
836
|
+
<UiRadioGroupItem id="t-comfortable" value="comfortable" disabled />
|
|
837
|
+
<label for="t-comfortable" class="label-14-medium text-content-on-surface-muted">Comfortable</label>
|
|
838
|
+
</div>
|
|
839
|
+
<div class="flex items-center gap-x-2">
|
|
840
|
+
<UiRadioGroupItem id="t-compact" value="compact" />
|
|
841
|
+
<label for="t-compact" class="label-14-medium">Compact</label>
|
|
842
|
+
</div>
|
|
843
|
+
</UiRadioGroup>
|
|
844
|
+
`,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// Shared render for the guard scenarios: the standard group, a group disabled
|
|
849
|
+
// as a whole, and a group with looping turned off — the three states whose
|
|
850
|
+
// behaviour has to be proven rather than shown.
|
|
851
|
+
function renderGuardedRadioGroups() {
|
|
852
|
+
return {
|
|
853
|
+
components: { UiRadioGroup, UiRadioGroupItem },
|
|
854
|
+
setup() {
|
|
855
|
+
const spacing = ref('default');
|
|
856
|
+
const density = ref('cosy');
|
|
857
|
+
const size = ref('small');
|
|
858
|
+
return { spacing, density, size };
|
|
859
|
+
},
|
|
860
|
+
template: `
|
|
861
|
+
<div class="flex flex-col gap-6">
|
|
862
|
+
<UiRadioGroup v-model="spacing" name="spacing" aria-label="Spacing">
|
|
863
|
+
<div class="flex items-center gap-x-2">
|
|
864
|
+
<UiRadioGroupItem id="g-default" value="default" />
|
|
865
|
+
<label for="g-default" class="label-14-medium">Default</label>
|
|
866
|
+
</div>
|
|
867
|
+
<div class="flex items-center gap-x-2">
|
|
868
|
+
<UiRadioGroupItem id="g-comfortable" value="comfortable" disabled />
|
|
869
|
+
<label for="g-comfortable" class="label-14-medium text-content-on-surface-muted">Comfortable</label>
|
|
870
|
+
</div>
|
|
871
|
+
<div class="flex items-center gap-x-2">
|
|
872
|
+
<UiRadioGroupItem id="g-compact" value="compact" />
|
|
873
|
+
<label for="g-compact" class="label-14-medium">Compact</label>
|
|
874
|
+
</div>
|
|
875
|
+
</UiRadioGroup>
|
|
876
|
+
|
|
877
|
+
<UiRadioGroup v-model="density" name="density" aria-label="Density" disabled>
|
|
878
|
+
<div class="flex items-center gap-x-2">
|
|
879
|
+
<UiRadioGroupItem id="g-cosy" value="cosy" />
|
|
880
|
+
<label for="g-cosy" class="label-14-medium text-content-on-surface-muted">Cosy</label>
|
|
881
|
+
</div>
|
|
882
|
+
<div class="flex items-center gap-x-2">
|
|
883
|
+
<UiRadioGroupItem id="g-roomy" value="roomy" />
|
|
884
|
+
<label for="g-roomy" class="label-14-medium text-content-on-surface-muted">Roomy</label>
|
|
885
|
+
</div>
|
|
886
|
+
</UiRadioGroup>
|
|
887
|
+
|
|
888
|
+
<UiRadioGroup v-model="size" name="size" aria-label="Size" :loop="false">
|
|
889
|
+
<div class="flex items-center gap-x-2">
|
|
890
|
+
<UiRadioGroupItem id="g-small" value="small" />
|
|
891
|
+
<label for="g-small" class="label-14-medium">Small</label>
|
|
892
|
+
</div>
|
|
893
|
+
<div class="flex items-center gap-x-2">
|
|
894
|
+
<UiRadioGroupItem id="g-medium" value="medium" />
|
|
895
|
+
<label for="g-medium" class="label-14-medium">Medium</label>
|
|
896
|
+
</div>
|
|
897
|
+
<div class="flex items-center gap-x-2">
|
|
898
|
+
<UiRadioGroupItem id="g-large" value="large" />
|
|
899
|
+
<label for="g-large" class="label-14-medium">Large</label>
|
|
900
|
+
</div>
|
|
901
|
+
</UiRadioGroup>
|
|
902
|
+
</div>
|
|
903
|
+
`,
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Selection behaviour: choosing an option moves the selection, exactly one
|
|
909
|
+
* option is ever checked, and both a disabled option and a fully disabled
|
|
910
|
+
* group refuse activation.
|
|
911
|
+
*/
|
|
912
|
+
export const SelectionBehavior: Story = {
|
|
913
|
+
name: 'test - Selection Behavior',
|
|
914
|
+
tags: ['!dev', '!autodocs'],
|
|
915
|
+
parameters: {
|
|
916
|
+
// The play changes the selection; skip the visual snapshot.
|
|
917
|
+
chromatic: { disableSnapshot: true },
|
|
918
|
+
docs: {
|
|
919
|
+
description: {
|
|
920
|
+
story:
|
|
921
|
+
'Move the selection between options and confirm the disabled guards hold.',
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
render: renderGuardedRadioGroups,
|
|
926
|
+
play: async ({ canvasElement, step }) => {
|
|
927
|
+
// Scenario (UiRadioGroup + UiRadioGroupItem): a pointer user picks an
|
|
928
|
+
// option, moves the selection again, and finds that neither the disabled
|
|
929
|
+
// option nor the disabled group can be activated.
|
|
930
|
+
const canvas = within(canvasElement);
|
|
931
|
+
const spacing = canvas.getByRole('radiogroup', { name: 'Spacing' });
|
|
932
|
+
const density = canvas.getByRole('radiogroup', { name: 'Density' });
|
|
933
|
+
const compact = within(spacing).getByRole('radio', { name: 'Compact' });
|
|
934
|
+
const defaultOption = within(spacing).getByRole('radio', {
|
|
935
|
+
name: 'Default',
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
await step(
|
|
939
|
+
'interaction: choosing an option selects it and clears the previous one',
|
|
940
|
+
async () => {
|
|
941
|
+
await expect(defaultOption).toBeChecked();
|
|
942
|
+
await userEvent.click(compact);
|
|
943
|
+
await expect(compact).toBeChecked();
|
|
944
|
+
await expect(defaultOption).not.toBeChecked();
|
|
945
|
+
},
|
|
946
|
+
);
|
|
947
|
+
|
|
948
|
+
await step(
|
|
949
|
+
'interaction: exactly one option is checked after moving the selection',
|
|
950
|
+
async () => {
|
|
951
|
+
await userEvent.click(defaultOption);
|
|
952
|
+
const checked = within(spacing)
|
|
953
|
+
.getAllByRole('radio')
|
|
954
|
+
.filter((radio) => radio.getAttribute('aria-checked') === 'true');
|
|
955
|
+
await expect(checked).toHaveLength(1);
|
|
956
|
+
await expect(checked[0]).toHaveAccessibleName('Default');
|
|
957
|
+
},
|
|
958
|
+
);
|
|
959
|
+
|
|
960
|
+
await step(
|
|
961
|
+
'interaction: an individual disabled option cannot be selected (WCAG 4.1.2)',
|
|
962
|
+
async () => {
|
|
963
|
+
const comfortable = within(spacing).getByRole('radio', {
|
|
964
|
+
name: 'Comfortable',
|
|
965
|
+
});
|
|
966
|
+
await expect(comfortable).toBeDisabled();
|
|
967
|
+
// Disabled items render with pointer-events: none, so bypass the check
|
|
968
|
+
// and assert the click is still a no-op.
|
|
969
|
+
await userEvent.click(comfortable, { pointerEventsCheck: 0 });
|
|
970
|
+
await expect(comfortable).not.toBeChecked();
|
|
971
|
+
await expect(defaultOption).toBeChecked();
|
|
972
|
+
},
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
await step(
|
|
976
|
+
'interaction: a group disabled as a whole cannot be selected',
|
|
977
|
+
async () => {
|
|
978
|
+
const roomy = within(density).getByRole('radio', { name: 'Roomy' });
|
|
979
|
+
const cosy = within(density).getByRole('radio', { name: 'Cosy' });
|
|
980
|
+
await expect(roomy).toBeDisabled();
|
|
981
|
+
await userEvent.click(roomy, { pointerEventsCheck: 0 });
|
|
982
|
+
await expect(roomy).not.toBeChecked();
|
|
983
|
+
await expect(cosy).toBeChecked();
|
|
984
|
+
},
|
|
985
|
+
);
|
|
986
|
+
},
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
// Arrow keys move focus and take the selection with them. reka-ui checks the
|
|
990
|
+
// newly focused option from a deferred callback that bails out once the arrow
|
|
991
|
+
// key is released, so the key has to stay down until the selection lands, as it
|
|
992
|
+
// does under a real key press. Tapping the key releases it first, leaving the
|
|
993
|
+
// option focused but never checked.
|
|
994
|
+
async function arrowToOption(
|
|
995
|
+
key: 'ArrowUp' | 'ArrowDown',
|
|
996
|
+
option: HTMLElement,
|
|
997
|
+
) {
|
|
998
|
+
await userEvent.keyboard(`{${key}>}`);
|
|
999
|
+
await expect(option).toHaveFocus();
|
|
1000
|
+
await waitFor(async () => {
|
|
1001
|
+
await expect(option).toBeChecked();
|
|
1002
|
+
});
|
|
1003
|
+
await userEvent.keyboard(`{/${key}}`);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* `UiRadioGroup` is fully keyboard operable: `Tab` reaches the group as a single
|
|
1008
|
+
* stop, arrow keys move and confirm the selection while skipping disabled
|
|
1009
|
+
* options, navigation loops by default, and `Tab` leaves for the next group.
|
|
1010
|
+
*/
|
|
1011
|
+
export const KeyboardNavigation: Story = {
|
|
1012
|
+
name: 'test - Keyboard Navigation',
|
|
1013
|
+
tags: ['!dev', '!autodocs'],
|
|
1014
|
+
parameters: {
|
|
1015
|
+
// Focus moves during the play function; skip the visual snapshot.
|
|
1016
|
+
chromatic: { disableSnapshot: true },
|
|
1017
|
+
docs: {
|
|
1018
|
+
description: {
|
|
1019
|
+
story:
|
|
1020
|
+
'Press `Tab` to reach the group, then arrow keys to move the selection between options.',
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1024
|
+
render: renderGuardedRadioGroups,
|
|
1025
|
+
play: async ({ canvasElement, step }) => {
|
|
1026
|
+
// Scenario (UiRadioGroup): a keyboard user tabs into the group, arrows
|
|
1027
|
+
// through the enabled options (which both moves focus and selects), wraps
|
|
1028
|
+
// around the ends, and tabs onward to the next group.
|
|
1029
|
+
const canvas = within(canvasElement);
|
|
1030
|
+
const spacing = canvas.getByRole('radiogroup', { name: 'Spacing' });
|
|
1031
|
+
const size = canvas.getByRole('radiogroup', { name: 'Size' });
|
|
1032
|
+
const defaultOption = within(spacing).getByRole('radio', {
|
|
1033
|
+
name: 'Default',
|
|
1034
|
+
});
|
|
1035
|
+
const compact = within(spacing).getByRole('radio', { name: 'Compact' });
|
|
1036
|
+
|
|
1037
|
+
await step(
|
|
1038
|
+
'keyboard: Tab reaches the group and lands on the selected option (WCAG 2.1.1 Keyboard)',
|
|
1039
|
+
async () => {
|
|
1040
|
+
await userEvent.tab();
|
|
1041
|
+
await expect(defaultOption).toHaveFocus();
|
|
1042
|
+
},
|
|
1043
|
+
);
|
|
1044
|
+
|
|
1045
|
+
await step(
|
|
1046
|
+
'keyboard: ArrowDown moves to the next enabled option and selects it, skipping disabled ones',
|
|
1047
|
+
async () => {
|
|
1048
|
+
// "Comfortable" sits between the two but is disabled, so it is skipped.
|
|
1049
|
+
await arrowToOption('ArrowDown', compact);
|
|
1050
|
+
},
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
await step(
|
|
1054
|
+
'keyboard: ArrowUp moves back to the previous enabled option',
|
|
1055
|
+
async () => {
|
|
1056
|
+
await arrowToOption('ArrowUp', defaultOption);
|
|
1057
|
+
},
|
|
1058
|
+
);
|
|
1059
|
+
|
|
1060
|
+
await step(
|
|
1061
|
+
'keyboard: arrow navigation loops around the ends of the group',
|
|
1062
|
+
async () => {
|
|
1063
|
+
// Backwards from the first option wraps to the last one.
|
|
1064
|
+
await userEvent.keyboard('{ArrowUp}');
|
|
1065
|
+
await expect(compact).toHaveFocus();
|
|
1066
|
+
// Forwards from the last option wraps back to the first.
|
|
1067
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
1068
|
+
await expect(defaultOption).toHaveFocus();
|
|
1069
|
+
},
|
|
1070
|
+
);
|
|
1071
|
+
|
|
1072
|
+
await step(
|
|
1073
|
+
'keyboard: Tab leaves the group as a single stop and follows DOM order (WCAG 2.4.3 Focus Order)',
|
|
1074
|
+
async () => {
|
|
1075
|
+
// The whole group is one tab stop, and the fully disabled group in
|
|
1076
|
+
// between is skipped entirely.
|
|
1077
|
+
await userEvent.tab();
|
|
1078
|
+
await expect(
|
|
1079
|
+
within(size).getByRole('radio', { name: 'Small' }),
|
|
1080
|
+
).toHaveFocus();
|
|
1081
|
+
},
|
|
1082
|
+
);
|
|
1083
|
+
|
|
1084
|
+
await step(
|
|
1085
|
+
'keyboard: navigation stops at the last option when looping is disabled',
|
|
1086
|
+
async () => {
|
|
1087
|
+
const large = within(size).getByRole('radio', { name: 'Large' });
|
|
1088
|
+
await userEvent.keyboard('{ArrowDown}{ArrowDown}');
|
|
1089
|
+
await expect(large).toHaveFocus();
|
|
1090
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
1091
|
+
await expect(large).toHaveFocus();
|
|
1092
|
+
},
|
|
1093
|
+
);
|
|
1094
|
+
},
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Screen-reader semantics: the group exposes a named radiogroup, every option
|
|
1099
|
+
* exposes a radio role with its label as the accessible name, and the
|
|
1100
|
+
* selected and disabled states are announced and kept in sync.
|
|
1101
|
+
*/
|
|
1102
|
+
export const ScreenReader: Story = {
|
|
1103
|
+
name: 'test - Screen Reader',
|
|
1104
|
+
tags: ['!dev', '!autodocs'],
|
|
1105
|
+
parameters: {
|
|
1106
|
+
// The play changes the selection; skip the visual snapshot.
|
|
1107
|
+
chromatic: { disableSnapshot: true },
|
|
1108
|
+
docs: {
|
|
1109
|
+
description: {
|
|
1110
|
+
story:
|
|
1111
|
+
'Verifies the roles, names, and states that assistive technology announces.',
|
|
1112
|
+
},
|
|
1113
|
+
},
|
|
1114
|
+
},
|
|
1115
|
+
render: renderTestRadioGroup,
|
|
1116
|
+
play: async ({ canvasElement, step }) => {
|
|
1117
|
+
// Scenario (UiRadioGroup + UiRadioGroupItem): assistive tech reads the set
|
|
1118
|
+
// as a named radiogroup, hears each option's label as its name, and is told
|
|
1119
|
+
// which option is selected and which is unavailable.
|
|
1120
|
+
const canvas = within(canvasElement);
|
|
1121
|
+
const group = canvas.getByRole('radiogroup', { name: 'Spacing' });
|
|
1122
|
+
const defaultOption = within(group).getByRole('radio', { name: 'Default' });
|
|
1123
|
+
const compact = within(group).getByRole('radio', { name: 'Compact' });
|
|
1124
|
+
|
|
1125
|
+
await step(
|
|
1126
|
+
'screen-reader: the set exposes a radiogroup role and an accessible name (WCAG 1.3.1 / 4.1.2)',
|
|
1127
|
+
async () => {
|
|
1128
|
+
await expect(group).toHaveAccessibleName('Spacing');
|
|
1129
|
+
},
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1132
|
+
await step(
|
|
1133
|
+
'screen-reader: every option exposes a radio role named by its label (WCAG 4.1.2)',
|
|
1134
|
+
async () => {
|
|
1135
|
+
const radios = within(group).getAllByRole('radio');
|
|
1136
|
+
await expect(radios).toHaveLength(3);
|
|
1137
|
+
await expect(radios[0]).toHaveAccessibleName('Default');
|
|
1138
|
+
await expect(radios[1]).toHaveAccessibleName('Comfortable');
|
|
1139
|
+
await expect(radios[2]).toHaveAccessibleName('Compact');
|
|
1140
|
+
},
|
|
1141
|
+
);
|
|
1142
|
+
|
|
1143
|
+
await step(
|
|
1144
|
+
'screen-reader: the selected option announces aria-checked and the others do not (WCAG 4.1.2)',
|
|
1145
|
+
async () => {
|
|
1146
|
+
await expect(defaultOption).toHaveAttribute('aria-checked', 'true');
|
|
1147
|
+
await expect(compact).toHaveAttribute('aria-checked', 'false');
|
|
1148
|
+
},
|
|
1149
|
+
);
|
|
1150
|
+
|
|
1151
|
+
await step(
|
|
1152
|
+
'screen-reader: the disabled option announces its disabled state (WCAG 4.1.2)',
|
|
1153
|
+
async () => {
|
|
1154
|
+
await expect(
|
|
1155
|
+
within(group).getByRole('radio', { name: 'Comfortable' }),
|
|
1156
|
+
).toBeDisabled();
|
|
1157
|
+
},
|
|
1158
|
+
);
|
|
1159
|
+
|
|
1160
|
+
await step(
|
|
1161
|
+
'screen-reader: the announced state follows the selection (WCAG 4.1.2)',
|
|
1162
|
+
async () => {
|
|
1163
|
+
await userEvent.click(compact);
|
|
1164
|
+
await expect(compact).toHaveAttribute('aria-checked', 'true');
|
|
1165
|
+
await expect(defaultOption).toHaveAttribute('aria-checked', 'false');
|
|
1166
|
+
},
|
|
1167
|
+
);
|
|
1168
|
+
},
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1173
|
+
* try 400% reflow (WCAG 1.4.10); every option must stay visible, readable, and
|
|
1174
|
+
* operable.
|
|
1175
|
+
*/
|
|
1176
|
+
export const ZoomMagnification: Story = {
|
|
1177
|
+
name: 'test - Zoom Magnification',
|
|
1178
|
+
tags: ['!dev', '!autodocs'],
|
|
1179
|
+
globals: { zoom: '200' },
|
|
1180
|
+
parameters: {
|
|
1181
|
+
// The accessible-reflow Chromatic mode already covers magnified snapshots.
|
|
1182
|
+
chromatic: { disableSnapshot: true },
|
|
1183
|
+
docs: {
|
|
1184
|
+
description: {
|
|
1185
|
+
story:
|
|
1186
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
},
|
|
1190
|
+
render: renderTestRadioGroup,
|
|
1191
|
+
play: async ({ canvasElement, step }) => {
|
|
1192
|
+
// Scenario (UiRadioGroup): at 200% page zoom every option stays on screen
|
|
1193
|
+
// with its label, and the group still accepts a selection.
|
|
1194
|
+
const canvas = within(canvasElement);
|
|
1195
|
+
const group = canvas.getByRole('radiogroup', { name: 'Spacing' });
|
|
1196
|
+
|
|
1197
|
+
await step(
|
|
1198
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1199
|
+
async () => {
|
|
1200
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1201
|
+
},
|
|
1202
|
+
);
|
|
1203
|
+
|
|
1204
|
+
await step(
|
|
1205
|
+
'zoom: every option stays visible with a readable label when magnified',
|
|
1206
|
+
async () => {
|
|
1207
|
+
for (const radio of within(group).getAllByRole('radio')) {
|
|
1208
|
+
await expect(radio).toBeVisible();
|
|
1209
|
+
await expect(radio).toHaveAccessibleName();
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
await step('zoom: the group remains operable when magnified', async () => {
|
|
1215
|
+
const compact = within(group).getByRole('radio', { name: 'Compact' });
|
|
1216
|
+
await userEvent.click(compact);
|
|
1217
|
+
await expect(compact).toBeChecked();
|
|
1218
|
+
});
|
|
1219
|
+
},
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1224
|
+
* toolbar. Every option stays operable and meets the minimum touch-target size
|
|
1225
|
+
* (WCAG 2.5.8).
|
|
1226
|
+
*/
|
|
1227
|
+
export const MobileBreakpoint: Story = {
|
|
1228
|
+
name: 'test - Mobile Breakpoint',
|
|
1229
|
+
tags: ['!dev', '!autodocs'],
|
|
1230
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1231
|
+
parameters: {
|
|
1232
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
1233
|
+
chromatic: { disableSnapshot: true },
|
|
1234
|
+
docs: {
|
|
1235
|
+
description: {
|
|
1236
|
+
story:
|
|
1237
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1238
|
+
},
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
render: renderTestRadioGroup,
|
|
1242
|
+
play: async ({ canvasElement, step }) => {
|
|
1243
|
+
// Scenario (UiRadioGroup): at the 320px mobile breakpoint the group stays
|
|
1244
|
+
// usable, every option is big enough to tap, and a tap still selects.
|
|
1245
|
+
const canvas = within(canvasElement);
|
|
1246
|
+
const group = canvas.getByRole('radiogroup', { name: 'Spacing' });
|
|
1247
|
+
|
|
1248
|
+
await step(
|
|
1249
|
+
'mobile: every option stays visible at the 320px breakpoint (WCAG 1.4.10 Reflow)',
|
|
1250
|
+
async () => {
|
|
1251
|
+
for (const radio of within(group).getAllByRole('radio')) {
|
|
1252
|
+
await expect(radio).toBeVisible();
|
|
1253
|
+
}
|
|
1254
|
+
},
|
|
1255
|
+
);
|
|
1256
|
+
|
|
1257
|
+
await step(
|
|
1258
|
+
'mobile: options meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1259
|
+
async () => {
|
|
1260
|
+
const rows = within(group)
|
|
1261
|
+
.getAllByRole('radio')
|
|
1262
|
+
// The hit area is the whole option row: the control plus its label.
|
|
1263
|
+
.map((radio) =>
|
|
1264
|
+
(radio.parentElement as HTMLElement).getBoundingClientRect(),
|
|
1265
|
+
);
|
|
1266
|
+
|
|
1267
|
+
for (const row of rows) {
|
|
1268
|
+
await expect(row.width).toBeGreaterThanOrEqual(24);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// The rows themselves are shorter than 24px, so the control relies on
|
|
1272
|
+
// the 2.5.8 spacing exception: neighbouring options must sit at least
|
|
1273
|
+
// 24px apart so their target circles never overlap.
|
|
1274
|
+
for (let index = 1; index < rows.length; index += 1) {
|
|
1275
|
+
const gap = rows[index].top - rows[index - 1].top;
|
|
1276
|
+
await expect(gap).toBeGreaterThanOrEqual(24);
|
|
1277
|
+
}
|
|
1278
|
+
},
|
|
1279
|
+
);
|
|
1280
|
+
|
|
1281
|
+
await step(
|
|
1282
|
+
'mobile: tapping an option selects it at the 320px breakpoint',
|
|
1283
|
+
async () => {
|
|
1284
|
+
const compact = within(group).getByRole('radio', { name: 'Compact' });
|
|
1285
|
+
await userEvent.click(compact);
|
|
1286
|
+
await expect(compact).toBeChecked();
|
|
1287
|
+
},
|
|
1288
|
+
);
|
|
1289
|
+
},
|
|
295
1290
|
};
|