@aleph-alpha/ui-library 6.3.3 → 6.3.4
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/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
- package/dist/system/components/UiStepper/context.d.ts +8 -0
- package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
- package/dist/system/icons/story-sidebar-icons.json +7 -0
- package/dist/system/lib.js +14776 -14598
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
- package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
- package/dist/system/story-sidebar-icons.json +7 -0
- package/package.json +1 -1
- package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
- package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
- package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
- package/src/components/UiFileUploadBox/types.ts +8 -5
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
- package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
- package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
- package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
- package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
- package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
- package/src/components/UiStepper/UiStepper.stories.ts +566 -2
- package/src/components/UiStepper/UiStepper.vue +14 -1
- package/src/components/UiStepper/UiStepperItem.vue +22 -4
- package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
- package/src/components/UiStepper/context.ts +10 -0
- package/src/components/core/calendar/Calendar.vue +234 -2
- package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
- package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
- package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
- package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
- package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
- package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
- package/src/patterns/UiLayout/layout-shell.ts +159 -13
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
- package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
- package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
|
@@ -92,8 +92,9 @@ const toasterProps = computed(() => ({
|
|
|
92
92
|
order: 9;
|
|
93
93
|
flex-shrink: 0;
|
|
94
94
|
align-self: center;
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
/* 24px is the WCAG 2.5.8 minimum touch-target size for the dismiss control. */
|
|
96
|
+
width: 24px;
|
|
97
|
+
height: 24px;
|
|
97
98
|
padding: 0;
|
|
98
99
|
border: none;
|
|
99
100
|
border-radius: var(--radius-sm);
|
|
@@ -103,7 +103,7 @@ const showCloseButton = computed(
|
|
|
103
103
|
v-if="showCloseButton"
|
|
104
104
|
type="button"
|
|
105
105
|
data-slot="snackbar-close-button"
|
|
106
|
-
class="inline-flex size-
|
|
106
|
+
class="inline-flex size-6 shrink-0 items-center justify-center rounded-sm border-none bg-transparent p-0 text-inherit hover:bg-overlay-hover-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-surface-focus-ring"
|
|
107
107
|
:aria-label="props.closeButtonAriaLabel"
|
|
108
108
|
@click="props.onCloseToast"
|
|
109
109
|
>
|
|
@@ -93,7 +93,9 @@ describe('UiSnackbarContent', () => {
|
|
|
93
93
|
|
|
94
94
|
const closeButton = getByRole('button', { name: 'Close toast' });
|
|
95
95
|
expect(getByRole('button', { name: 'Undo' })).toBeInTheDocument();
|
|
96
|
-
|
|
96
|
+
// `size-6` (24px) keeps the dismiss control at the WCAG 2.5.8 minimum
|
|
97
|
+
// touch-target size.
|
|
98
|
+
expect(closeButton).toHaveClass('size-6');
|
|
97
99
|
await closeButton.click();
|
|
98
100
|
expect(onCloseToast).toHaveBeenCalledTimes(1);
|
|
99
101
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
2
3
|
import { ref, watch } from 'vue';
|
|
3
4
|
import {
|
|
4
5
|
UiStepper,
|
|
@@ -9,13 +10,21 @@ import {
|
|
|
9
10
|
UiStepperDescription,
|
|
10
11
|
UiStepperSeparator,
|
|
11
12
|
} from './index';
|
|
13
|
+
import type { UiStepperItemProps, UiStepperProps } from './types';
|
|
12
14
|
import { UiIcon } from '../UiIcon';
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Story args: the UiStepper props plus the UiStepperItem props that are
|
|
18
|
+
* surfaced in the Controls panel under the "UiStepperItem" category.
|
|
19
|
+
*/
|
|
20
|
+
type StepperStoryArgs = UiStepperProps &
|
|
21
|
+
Pick<UiStepperItemProps, 'disabled' | 'completed'>;
|
|
22
|
+
|
|
14
23
|
/**
|
|
15
24
|
* UiStepper is a multi-step workflow indicator with step titles, descriptions, separators, and per-step icons.
|
|
16
25
|
* Use it for onboarding, checkout, and multi-page form flows where users need to see overall progress and the current step.
|
|
17
26
|
*/
|
|
18
|
-
const meta: Meta<
|
|
27
|
+
const meta: Meta<StepperStoryArgs> = {
|
|
19
28
|
title: 'Components/UiStepper',
|
|
20
29
|
component: UiStepper,
|
|
21
30
|
tags: ['autodocs'],
|
|
@@ -36,16 +45,29 @@ const meta: Meta<typeof UiStepper> = {
|
|
|
36
45
|
description:
|
|
37
46
|
'Whether navigation must be sequential (user cannot skip ahead to incomplete steps)',
|
|
38
47
|
},
|
|
48
|
+
disabled: {
|
|
49
|
+
control: 'boolean',
|
|
50
|
+
description:
|
|
51
|
+
'Whether a step is disabled and cannot be navigated to (UiStepperItem prop)',
|
|
52
|
+
table: { category: 'UiStepperItem' },
|
|
53
|
+
},
|
|
54
|
+
completed: {
|
|
55
|
+
control: 'boolean',
|
|
56
|
+
description: 'Whether a step is marked as completed (UiStepperItem prop)',
|
|
57
|
+
table: { category: 'UiStepperItem' },
|
|
58
|
+
},
|
|
39
59
|
},
|
|
40
60
|
args: {
|
|
41
61
|
orientation: 'horizontal',
|
|
42
62
|
linear: true,
|
|
63
|
+
disabled: false,
|
|
64
|
+
completed: false,
|
|
43
65
|
},
|
|
44
66
|
};
|
|
45
67
|
|
|
46
68
|
export default meta;
|
|
47
69
|
|
|
48
|
-
type Story = StoryObj<
|
|
70
|
+
type Story = StoryObj<StepperStoryArgs>;
|
|
49
71
|
|
|
50
72
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
51
73
|
import { ref } from 'vue'
|
|
@@ -156,6 +178,8 @@ export const Default: Story = {
|
|
|
156
178
|
v-for="item in steps"
|
|
157
179
|
:key="item.step"
|
|
158
180
|
:step="item.step"
|
|
181
|
+
:disabled="args.disabled"
|
|
182
|
+
:completed="args.completed"
|
|
159
183
|
:class="args.orientation === 'vertical'
|
|
160
184
|
? 'relative flex w-full items-start justify-start gap-6'
|
|
161
185
|
: 'relative flex w-full flex-col items-center justify-center'"
|
|
@@ -450,3 +474,543 @@ export const Vertical: Story = {
|
|
|
450
474
|
},
|
|
451
475
|
},
|
|
452
476
|
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Accessibility guidance for distinguishing step states without colour,
|
|
480
|
+
* comfortable targets, reading order, and the accessible theme.
|
|
481
|
+
*/
|
|
482
|
+
export const Accessibility: Story = {
|
|
483
|
+
render: () => ({
|
|
484
|
+
components: {
|
|
485
|
+
UiStepper,
|
|
486
|
+
UiStepperItem,
|
|
487
|
+
UiStepperTrigger,
|
|
488
|
+
UiStepperIndicator,
|
|
489
|
+
UiStepperTitle,
|
|
490
|
+
UiStepperDescription,
|
|
491
|
+
UiStepperSeparator,
|
|
492
|
+
},
|
|
493
|
+
setup() {
|
|
494
|
+
const steps = [1, 2, 3];
|
|
495
|
+
return { steps };
|
|
496
|
+
},
|
|
497
|
+
template: `
|
|
498
|
+
<section class="flex w-full flex-col gap-6 p-4">
|
|
499
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
500
|
+
Accessibility
|
|
501
|
+
</h2>
|
|
502
|
+
|
|
503
|
+
<div class="flex flex-col gap-2">
|
|
504
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
505
|
+
Requirements
|
|
506
|
+
</h3>
|
|
507
|
+
<ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
|
|
508
|
+
<li>Complete, active and pending differ in shape and weight, not colour alone</li>
|
|
509
|
+
<li>The complete state carries a mark, such as a tick, rather than only a fill change</li>
|
|
510
|
+
<li>Labels stay legible at the sm size and when they wrap</li>
|
|
511
|
+
<li>The active step is identifiable without relying on the connector's colour</li>
|
|
512
|
+
<li>Triggers and labels are comfortable targets where steps can be revisited</li>
|
|
513
|
+
<li>Reading order follows the step order, horizontally or vertically as laid out</li>
|
|
514
|
+
<li>Give every trigger an accessible title or name; never use an icon alone as its name</li>
|
|
515
|
+
<li>Keyboard users can Tab into the stepper, move with arrow keys, and activate with Enter or Space</li>
|
|
516
|
+
</ul>
|
|
517
|
+
</div>
|
|
518
|
+
|
|
519
|
+
<div class="flex flex-col gap-2">
|
|
520
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
521
|
+
Enable accessibility theme
|
|
522
|
+
</h3>
|
|
523
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
524
|
+
When accessibility is required, enable our accessibility theme.
|
|
525
|
+
This increases contrast and ensures there are no color contrast
|
|
526
|
+
issues.
|
|
527
|
+
</p>
|
|
528
|
+
</div>
|
|
529
|
+
|
|
530
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
531
|
+
<div class="flex flex-col gap-3">
|
|
532
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
533
|
+
Default
|
|
534
|
+
</h3>
|
|
535
|
+
<div class="flex justify-center border border-border-surface-default p-6">
|
|
536
|
+
<UiStepper :default-value="2" class="flex w-full items-start gap-2">
|
|
537
|
+
<UiStepperItem
|
|
538
|
+
v-for="step in steps"
|
|
539
|
+
:key="step"
|
|
540
|
+
:step="step"
|
|
541
|
+
class="relative flex w-full flex-col items-center justify-center"
|
|
542
|
+
>
|
|
543
|
+
<UiStepperTrigger>
|
|
544
|
+
<UiStepperIndicator>
|
|
545
|
+
<span>{{ step }}</span>
|
|
546
|
+
</UiStepperIndicator>
|
|
547
|
+
</UiStepperTrigger>
|
|
548
|
+
<UiStepperSeparator v-if="step !== steps.length" />
|
|
549
|
+
<div class="flex flex-col items-center">
|
|
550
|
+
<UiStepperTitle>Address</UiStepperTitle>
|
|
551
|
+
<UiStepperDescription>Add your address</UiStepperDescription>
|
|
552
|
+
</div>
|
|
553
|
+
</UiStepperItem>
|
|
554
|
+
</UiStepper>
|
|
555
|
+
</div>
|
|
556
|
+
</div>
|
|
557
|
+
|
|
558
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
559
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
560
|
+
Accessible
|
|
561
|
+
</h3>
|
|
562
|
+
<div class="flex justify-center border border-border-surface-default p-6">
|
|
563
|
+
<UiStepper :default-value="2" class="flex w-full items-start gap-2">
|
|
564
|
+
<UiStepperItem
|
|
565
|
+
v-for="step in steps"
|
|
566
|
+
:key="step"
|
|
567
|
+
:step="step"
|
|
568
|
+
class="relative flex w-full flex-col items-center justify-center"
|
|
569
|
+
>
|
|
570
|
+
<UiStepperTrigger>
|
|
571
|
+
<UiStepperIndicator>
|
|
572
|
+
<span>{{ step }}</span>
|
|
573
|
+
</UiStepperIndicator>
|
|
574
|
+
</UiStepperTrigger>
|
|
575
|
+
<UiStepperSeparator v-if="step !== steps.length" />
|
|
576
|
+
<div class="flex flex-col items-center">
|
|
577
|
+
<UiStepperTitle>Address</UiStepperTitle>
|
|
578
|
+
<UiStepperDescription>Add your address</UiStepperDescription>
|
|
579
|
+
</div>
|
|
580
|
+
</UiStepperItem>
|
|
581
|
+
</UiStepper>
|
|
582
|
+
</div>
|
|
583
|
+
</div>
|
|
584
|
+
</div>
|
|
585
|
+
</section>
|
|
586
|
+
`,
|
|
587
|
+
}),
|
|
588
|
+
tags: ['!autodocs'],
|
|
589
|
+
parameters: {
|
|
590
|
+
a11y: { test: 'off' },
|
|
591
|
+
chromatic: {
|
|
592
|
+
disableSnapshot: true,
|
|
593
|
+
},
|
|
594
|
+
docs: {
|
|
595
|
+
canvas: {
|
|
596
|
+
sourceState: 'none',
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
/*
|
|
603
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
604
|
+
* Interaction & accessibility tests (play functions)
|
|
605
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
606
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
607
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
608
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
609
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
610
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
611
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2)
|
|
612
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
613
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
614
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
615
|
+
* an `a11y:` prefix.
|
|
616
|
+
*/
|
|
617
|
+
|
|
618
|
+
const onUpdate = fn();
|
|
619
|
+
|
|
620
|
+
const TEST_STEPS = [
|
|
621
|
+
{ step: 1, title: 'Address', description: 'Add your address' },
|
|
622
|
+
{ step: 2, title: 'Shipping', description: 'Choose a shipping speed' },
|
|
623
|
+
{ step: 3, title: 'Payment', description: 'Add a payment method' },
|
|
624
|
+
{ step: 4, title: 'Checkout', description: 'Confirm your order' },
|
|
625
|
+
];
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* The stepper the test stories drive: four steps with the third one disabled,
|
|
629
|
+
* non-linear so any enabled step can be revisited or skipped to directly.
|
|
630
|
+
* @returns Vue component options for a story `render` function.
|
|
631
|
+
*/
|
|
632
|
+
function renderTestStepper() {
|
|
633
|
+
return {
|
|
634
|
+
components: {
|
|
635
|
+
UiStepper,
|
|
636
|
+
UiStepperItem,
|
|
637
|
+
UiStepperTrigger,
|
|
638
|
+
UiStepperIndicator,
|
|
639
|
+
UiStepperTitle,
|
|
640
|
+
UiStepperDescription,
|
|
641
|
+
UiStepperSeparator,
|
|
642
|
+
},
|
|
643
|
+
setup() {
|
|
644
|
+
const currentStep = ref(1);
|
|
645
|
+
return { currentStep, steps: TEST_STEPS, onUpdate };
|
|
646
|
+
},
|
|
647
|
+
template: `
|
|
648
|
+
<UiStepper
|
|
649
|
+
v-model="currentStep"
|
|
650
|
+
:linear="false"
|
|
651
|
+
class="flex w-full items-start gap-2"
|
|
652
|
+
@update:model-value="onUpdate"
|
|
653
|
+
>
|
|
654
|
+
<UiStepperItem
|
|
655
|
+
v-for="item in steps"
|
|
656
|
+
:key="item.step"
|
|
657
|
+
:step="item.step"
|
|
658
|
+
:disabled="item.step === 3"
|
|
659
|
+
class="relative flex w-full flex-col items-center justify-center"
|
|
660
|
+
>
|
|
661
|
+
<UiStepperTrigger>
|
|
662
|
+
<UiStepperIndicator>
|
|
663
|
+
<span>{{ item.step }}</span>
|
|
664
|
+
</UiStepperIndicator>
|
|
665
|
+
</UiStepperTrigger>
|
|
666
|
+
<UiStepperSeparator v-if="item.step !== steps.length" />
|
|
667
|
+
<div class="flex flex-col items-center">
|
|
668
|
+
<UiStepperTitle>{{ item.title }}</UiStepperTitle>
|
|
669
|
+
<UiStepperDescription>{{ item.description }}</UiStepperDescription>
|
|
670
|
+
</div>
|
|
671
|
+
</UiStepperItem>
|
|
672
|
+
</UiStepper>
|
|
673
|
+
`,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Resolves the stepper item element that owns a trigger — the element carrying
|
|
679
|
+
* `aria-current` and the item-level `data-state`.
|
|
680
|
+
* @param trigger The step trigger button.
|
|
681
|
+
* @returns The surrounding stepper item element.
|
|
682
|
+
*/
|
|
683
|
+
function itemOf(trigger: HTMLElement): HTMLElement {
|
|
684
|
+
const item = trigger.closest<HTMLElement>('div[data-state]');
|
|
685
|
+
if (!item) throw new Error('Stepper trigger has no surrounding item');
|
|
686
|
+
return item;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Activating an enabled step moves the selection; the disabled step stays
|
|
691
|
+
* inert. Hidden test-only story.
|
|
692
|
+
*/
|
|
693
|
+
export const SelectionBehavior: Story = {
|
|
694
|
+
name: 'test - Selection Behavior',
|
|
695
|
+
tags: ['!dev', '!autodocs'],
|
|
696
|
+
parameters: {
|
|
697
|
+
chromatic: { disableSnapshot: true },
|
|
698
|
+
docs: {
|
|
699
|
+
description: {
|
|
700
|
+
story:
|
|
701
|
+
'Click an enabled step to move the selection; the disabled step does not activate.',
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
render: () => renderTestStepper(),
|
|
706
|
+
play: async ({ canvasElement, step }) => {
|
|
707
|
+
// Scenario (UiStepper + UiStepperItem + UiStepperTrigger): a pointer user
|
|
708
|
+
// moves between enabled steps while the disabled one stays inert.
|
|
709
|
+
onUpdate.mockClear();
|
|
710
|
+
const canvas = within(canvasElement);
|
|
711
|
+
const address = canvas.getByRole('button', { name: 'Address' });
|
|
712
|
+
const shipping = canvas.getByRole('button', { name: 'Shipping' });
|
|
713
|
+
const checkout = canvas.getByRole('button', { name: 'Checkout' });
|
|
714
|
+
|
|
715
|
+
await step('interaction: the first step is active initially', async () => {
|
|
716
|
+
await expect(itemOf(address)).toHaveAttribute('aria-current', 'step');
|
|
717
|
+
await expect(address).toHaveAttribute('data-state', 'active');
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
await step(
|
|
721
|
+
'interaction: activating an enabled step moves the selection',
|
|
722
|
+
async () => {
|
|
723
|
+
await userEvent.click(shipping);
|
|
724
|
+
await expect(onUpdate).toHaveBeenCalledWith(2);
|
|
725
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
726
|
+
await expect(itemOf(address)).not.toHaveAttribute('aria-current');
|
|
727
|
+
await expect(address).toHaveAttribute('data-state', 'completed');
|
|
728
|
+
},
|
|
729
|
+
);
|
|
730
|
+
|
|
731
|
+
await step('interaction: the disabled step does not activate', async () => {
|
|
732
|
+
const payment = canvas.getByRole('button', { name: 'Payment' });
|
|
733
|
+
await expect(payment).toBeDisabled();
|
|
734
|
+
|
|
735
|
+
// The item blocks pointer events, so a real user cannot click it at
|
|
736
|
+
// all; dispatching the activation event directly proves the handler
|
|
737
|
+
// also guards against it.
|
|
738
|
+
await userEvent.click(payment, { pointerEventsCheck: 0 });
|
|
739
|
+
await expect(payment).toHaveAttribute('data-state', 'inactive');
|
|
740
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
741
|
+
await expect(onUpdate).toHaveBeenCalledTimes(1);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
await step(
|
|
745
|
+
'interaction: a later enabled step activates directly (non-linear)',
|
|
746
|
+
async () => {
|
|
747
|
+
await userEvent.click(checkout);
|
|
748
|
+
await expect(onUpdate).toHaveBeenCalledWith(4);
|
|
749
|
+
await expect(itemOf(checkout)).toHaveAttribute('aria-current', 'step');
|
|
750
|
+
},
|
|
751
|
+
);
|
|
752
|
+
},
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Steps are reachable and operable from the keyboard; the disabled step is
|
|
757
|
+
* skipped by both Tab and arrow navigation. Hidden test-only story.
|
|
758
|
+
*/
|
|
759
|
+
export const KeyboardNavigation: Story = {
|
|
760
|
+
name: 'test - Keyboard Navigation',
|
|
761
|
+
tags: ['!dev', '!autodocs'],
|
|
762
|
+
parameters: {
|
|
763
|
+
chromatic: { disableSnapshot: true },
|
|
764
|
+
docs: {
|
|
765
|
+
description: {
|
|
766
|
+
story:
|
|
767
|
+
'Press `Tab` or arrow keys to move between steps, then `Enter` or `Space` to activate one; the disabled step is skipped.',
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
render: () => renderTestStepper(),
|
|
772
|
+
play: async ({ canvasElement, step }) => {
|
|
773
|
+
// Scenario (UiStepper + UiStepperTrigger): a keyboard user tabs into the
|
|
774
|
+
// stepper, moves with arrow keys, and activates steps with Enter and
|
|
775
|
+
// Space; the disabled step never receives focus.
|
|
776
|
+
onUpdate.mockClear();
|
|
777
|
+
const canvas = within(canvasElement);
|
|
778
|
+
const address = canvas.getByRole('button', { name: 'Address' });
|
|
779
|
+
const shipping = canvas.getByRole('button', { name: 'Shipping' });
|
|
780
|
+
const checkout = canvas.getByRole('button', { name: 'Checkout' });
|
|
781
|
+
|
|
782
|
+
await step('keyboard: Tab reaches the first step trigger', async () => {
|
|
783
|
+
await userEvent.tab();
|
|
784
|
+
await expect(address).toHaveFocus();
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
await step(
|
|
788
|
+
'keyboard: arrow keys move focus and skip the disabled step (WCAG 2.1.1)',
|
|
789
|
+
async () => {
|
|
790
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
791
|
+
await expect(shipping).toHaveFocus();
|
|
792
|
+
// Payment (step 3) is disabled, so the next stop is Checkout.
|
|
793
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
794
|
+
await expect(checkout).toHaveFocus();
|
|
795
|
+
await userEvent.keyboard('{ArrowLeft}');
|
|
796
|
+
await expect(shipping).toHaveFocus();
|
|
797
|
+
},
|
|
798
|
+
);
|
|
799
|
+
|
|
800
|
+
await step(
|
|
801
|
+
'keyboard: Tab also skips the disabled step (inert)',
|
|
802
|
+
async () => {
|
|
803
|
+
await userEvent.tab();
|
|
804
|
+
await expect(checkout).toHaveFocus();
|
|
805
|
+
},
|
|
806
|
+
);
|
|
807
|
+
|
|
808
|
+
await step('keyboard: Enter activates the focused step', async () => {
|
|
809
|
+
await userEvent.keyboard('{Enter}');
|
|
810
|
+
await expect(onUpdate).toHaveBeenCalledWith(4);
|
|
811
|
+
await expect(itemOf(checkout)).toHaveAttribute('aria-current', 'step');
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
await step('keyboard: Space activates the focused step', async () => {
|
|
815
|
+
await userEvent.keyboard('{ArrowLeft}');
|
|
816
|
+
await expect(shipping).toHaveFocus();
|
|
817
|
+
await userEvent.keyboard(' ');
|
|
818
|
+
await expect(onUpdate).toHaveBeenCalledWith(2);
|
|
819
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
820
|
+
});
|
|
821
|
+
},
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Screen-reader semantics: a named group with a polite progress announcement,
|
|
826
|
+
* named step triggers with descriptions, `aria-current="step"` on the active
|
|
827
|
+
* item, and the disabled step announced as such. Hidden test-only story.
|
|
828
|
+
*/
|
|
829
|
+
export const ScreenReader: Story = {
|
|
830
|
+
name: 'test - Screen Reader',
|
|
831
|
+
tags: ['!dev', '!autodocs'],
|
|
832
|
+
parameters: {
|
|
833
|
+
chromatic: { disableSnapshot: true },
|
|
834
|
+
docs: {
|
|
835
|
+
description: {
|
|
836
|
+
story:
|
|
837
|
+
'Verifies the group role, the polite "Step x of y" live region, named triggers, and `aria-current="step"` on the active item.',
|
|
838
|
+
},
|
|
839
|
+
},
|
|
840
|
+
},
|
|
841
|
+
render: () => renderTestStepper(),
|
|
842
|
+
play: async ({ canvasElement, step }) => {
|
|
843
|
+
// Scenario (UiStepper + UiStepperItem + UiStepperTrigger + UiStepperTitle
|
|
844
|
+
// + UiStepperDescription): assistive tech finds a named group, hears
|
|
845
|
+
// progress politely, and can tell current, disabled, and completed steps
|
|
846
|
+
// apart from their exposed states.
|
|
847
|
+
const canvas = within(canvasElement);
|
|
848
|
+
const address = canvas.getByRole('button', { name: 'Address' });
|
|
849
|
+
const shipping = canvas.getByRole('button', { name: 'Shipping' });
|
|
850
|
+
|
|
851
|
+
await step(
|
|
852
|
+
'screen-reader: the stepper is a named group (WCAG 4.1.2)',
|
|
853
|
+
async () => {
|
|
854
|
+
await expect(
|
|
855
|
+
canvas.getByRole('group', { name: 'progress' }),
|
|
856
|
+
).toBeVisible();
|
|
857
|
+
},
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
await step(
|
|
861
|
+
'screen-reader: progress is announced from a polite status region (WCAG 4.1.3)',
|
|
862
|
+
async () => {
|
|
863
|
+
const status = canvas.getByRole('status');
|
|
864
|
+
await expect(status).toHaveAttribute('aria-live', 'polite');
|
|
865
|
+
await expect(status).toHaveTextContent('Step 1 of 4');
|
|
866
|
+
},
|
|
867
|
+
);
|
|
868
|
+
|
|
869
|
+
await step(
|
|
870
|
+
'screen-reader: step triggers expose a name and a description',
|
|
871
|
+
async () => {
|
|
872
|
+
await expect(address).toHaveAccessibleName('Address');
|
|
873
|
+
await expect(address).toHaveAccessibleDescription('Add your address');
|
|
874
|
+
},
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
await step(
|
|
878
|
+
'screen-reader: the current step is exposed via aria-current="step"',
|
|
879
|
+
async () => {
|
|
880
|
+
await expect(itemOf(address)).toHaveAttribute('aria-current', 'step');
|
|
881
|
+
await userEvent.click(shipping);
|
|
882
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
883
|
+
await expect(itemOf(address)).not.toHaveAttribute('aria-current');
|
|
884
|
+
await waitFor(async () => {
|
|
885
|
+
await expect(canvas.getByRole('status')).toHaveTextContent(
|
|
886
|
+
'Step 2 of 4',
|
|
887
|
+
);
|
|
888
|
+
});
|
|
889
|
+
},
|
|
890
|
+
);
|
|
891
|
+
|
|
892
|
+
await step(
|
|
893
|
+
'screen-reader: the disabled step is announced as disabled',
|
|
894
|
+
async () => {
|
|
895
|
+
await expect(
|
|
896
|
+
canvas.getByRole('button', { name: 'Payment' }),
|
|
897
|
+
).toBeDisabled();
|
|
898
|
+
},
|
|
899
|
+
);
|
|
900
|
+
},
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
905
|
+
* try 400% reflow (WCAG 1.4.10); the stepper must stay readable and operable.
|
|
906
|
+
* Hidden test-only story.
|
|
907
|
+
*/
|
|
908
|
+
export const ZoomMagnification: Story = {
|
|
909
|
+
name: 'test - Zoom Magnification',
|
|
910
|
+
tags: ['!dev', '!autodocs'],
|
|
911
|
+
globals: { zoom: '200' },
|
|
912
|
+
parameters: {
|
|
913
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
914
|
+
// already covers magnified snapshots, so skip this one.
|
|
915
|
+
chromatic: { disableSnapshot: true },
|
|
916
|
+
docs: {
|
|
917
|
+
description: {
|
|
918
|
+
story:
|
|
919
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
render: () => renderTestStepper(),
|
|
924
|
+
play: async ({ canvasElement, step }) => {
|
|
925
|
+
// Scenario (UiStepper + UiStepperTrigger): at 200% page zoom the stepper
|
|
926
|
+
// stays inside the viewport and steps remain activatable.
|
|
927
|
+
onUpdate.mockClear();
|
|
928
|
+
const canvas = within(canvasElement);
|
|
929
|
+
|
|
930
|
+
await step(
|
|
931
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
932
|
+
async () => {
|
|
933
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
934
|
+
},
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
await step('zoom: the stepper stays visible and readable', async () => {
|
|
938
|
+
const group = canvas.getByRole('group', { name: 'progress' });
|
|
939
|
+
await expect(group).toBeVisible();
|
|
940
|
+
await expect(canvas.getByText('Add your address')).toBeVisible();
|
|
941
|
+
|
|
942
|
+
const { left } = group.getBoundingClientRect();
|
|
943
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
await step('zoom: step triggers remain operable', async () => {
|
|
947
|
+
const shipping = canvas.getByRole('button', { name: 'Shipping' });
|
|
948
|
+
await userEvent.click(shipping);
|
|
949
|
+
await expect(onUpdate).toHaveBeenCalledWith(2);
|
|
950
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
951
|
+
});
|
|
952
|
+
},
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
957
|
+
* toolbar. The stepper fits the viewport and step triggers meet the minimum
|
|
958
|
+
* touch-target size (WCAG 2.5.8). Hidden test-only story.
|
|
959
|
+
*/
|
|
960
|
+
export const MobileBreakpoint: Story = {
|
|
961
|
+
name: 'test - Mobile Breakpoint',
|
|
962
|
+
tags: ['!dev', '!autodocs'],
|
|
963
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
964
|
+
parameters: {
|
|
965
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
966
|
+
chromatic: { disableSnapshot: true },
|
|
967
|
+
docs: {
|
|
968
|
+
description: {
|
|
969
|
+
story:
|
|
970
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
971
|
+
},
|
|
972
|
+
},
|
|
973
|
+
},
|
|
974
|
+
render: () => renderTestStepper(),
|
|
975
|
+
play: async ({ canvasElement, step }) => {
|
|
976
|
+
// Scenario (UiStepper + UiStepperTrigger): on a 320px viewport the step
|
|
977
|
+
// triggers stay inside the screen, are big enough to tap, and still move
|
|
978
|
+
// the selection.
|
|
979
|
+
onUpdate.mockClear();
|
|
980
|
+
const canvas = within(canvasElement);
|
|
981
|
+
const triggers = ['Address', 'Shipping', 'Checkout'].map((name) =>
|
|
982
|
+
canvas.getByRole('button', { name }),
|
|
983
|
+
);
|
|
984
|
+
|
|
985
|
+
await step(
|
|
986
|
+
'mobile: step triggers fit the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
987
|
+
async () => {
|
|
988
|
+
for (const trigger of triggers) {
|
|
989
|
+
const { left, right } = trigger.getBoundingClientRect();
|
|
990
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
991
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
);
|
|
995
|
+
|
|
996
|
+
await step(
|
|
997
|
+
'mobile: step triggers meet the minimum touch-target size (WCAG 2.5.8)',
|
|
998
|
+
async () => {
|
|
999
|
+
// The 40px indicator plus trigger padding keeps every step target
|
|
1000
|
+
// comfortably above the 24px floor.
|
|
1001
|
+
for (const trigger of triggers) {
|
|
1002
|
+
const { width, height } = trigger.getBoundingClientRect();
|
|
1003
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1004
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
);
|
|
1008
|
+
|
|
1009
|
+
await step('mobile: tapping a step moves the selection', async () => {
|
|
1010
|
+
const shipping = canvas.getByRole('button', { name: 'Shipping' });
|
|
1011
|
+
await userEvent.click(shipping);
|
|
1012
|
+
await expect(onUpdate).toHaveBeenCalledWith(2);
|
|
1013
|
+
await expect(itemOf(shipping)).toHaveAttribute('aria-current', 'step');
|
|
1014
|
+
});
|
|
1015
|
+
},
|
|
1016
|
+
};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed, provide } from 'vue';
|
|
2
3
|
import { Stepper as ShadcnStepper } from '@/components/core/stepper';
|
|
4
|
+
import { UI_STEPPER_CURRENT_STEP } from './context';
|
|
3
5
|
import type { UiStepperProps } from './types';
|
|
4
6
|
|
|
5
7
|
defineOptions({
|
|
6
8
|
name: 'UiStepper',
|
|
7
9
|
});
|
|
8
10
|
|
|
9
|
-
defineProps<UiStepperProps>();
|
|
11
|
+
const props = defineProps<UiStepperProps>();
|
|
10
12
|
const model = defineModel<number>();
|
|
13
|
+
|
|
14
|
+
// reka-ui marks the active StepperItem with `aria-current="true"`; the design
|
|
15
|
+
// system requires the specific `aria-current="step"` token. Provide the
|
|
16
|
+
// current step so UiStepperItem can override the attribute, covering both
|
|
17
|
+
// controlled (v-model) and uncontrolled (defaultValue) usage — in uncontrolled
|
|
18
|
+
// mode the model ref still tracks reka-ui's emitted updates.
|
|
19
|
+
const initialStep = props.defaultValue ?? 1;
|
|
20
|
+
provide(
|
|
21
|
+
UI_STEPPER_CURRENT_STEP,
|
|
22
|
+
computed(() => model.value ?? initialStep),
|
|
23
|
+
);
|
|
11
24
|
</script>
|
|
12
25
|
|
|
13
26
|
<template>
|