@aleph-alpha/ui-library 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.d.ts +28 -4
- package/config.js +141 -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/sidebar/utils.d.ts +9 -0
- package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
- package/dist/system/icons/story-sidebar-icons.json +8 -0
- package/dist/system/lib.js +6106 -5997
- package/dist/system/patterns/UiLayout/UiLayoutContent.vue.d.ts +39 -0
- package/dist/system/patterns/UiLayout/index.d.ts +2 -0
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +944 -0
- package/dist/system/patterns/UiLayout/types.d.ts +43 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +8 -0
- package/docs/public-docs/migration-guide.md +402 -0
- package/docs/public-docs/quick-start.md +19 -10
- package/package.json +7 -4
- 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/sidebar/Sidebar.vue +21 -5
- package/src/components/core/sidebar/utils.ts +10 -0
- 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/patterns/UiLayout/UiLayoutContent.stories.ts +1234 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +98 -0
- package/src/patterns/UiLayout/__tests__/UiLayoutContent.test.ts +97 -0
- package/src/patterns/UiLayout/index.ts +2 -0
- package/src/patterns/UiLayout/layout-shell.ts +64 -15
- package/src/patterns/UiLayout/types.ts +44 -0
- package/src/patterns/index.ts +1 -0
- package/src/theme/Typography.stories.ts +125 -133
- package/tokens.json +8132 -2475
- package/dist/system/icons/mobile-device-frame.png +0 -0
- package/dist/system/mobile-device-frame.png +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
2
3
|
import {
|
|
3
4
|
UiDrawer,
|
|
4
5
|
UiDrawerClose,
|
|
@@ -41,6 +42,12 @@ const meta: Meta<typeof UiDrawer> = {
|
|
|
41
42
|
export default meta;
|
|
42
43
|
type Story = StoryObj<typeof UiDrawer>;
|
|
43
44
|
|
|
45
|
+
// `UiDrawer` wires `defineModel('open')` and `UiDrawerContent` re-emits
|
|
46
|
+
// `escapeKeyDown` — neither is a handler prop, so play functions bind these
|
|
47
|
+
// module-level spies in the template and `mockClear()` them first.
|
|
48
|
+
const onUpdateOpen = fn();
|
|
49
|
+
const onEscapeKeyDown = fn();
|
|
50
|
+
|
|
44
51
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
45
52
|
import {
|
|
46
53
|
UiDrawer,
|
|
@@ -142,6 +149,30 @@ export const Default: Story = {
|
|
|
142
149
|
parameters: {
|
|
143
150
|
docs: { source: { code: defaultTemplateSource } },
|
|
144
151
|
},
|
|
152
|
+
play: async ({ canvasElement, step }) => {
|
|
153
|
+
// Scenario (UiDrawer): assistive tech sees a named trigger that reports the
|
|
154
|
+
// drawer it controls and that it is currently closed. Nothing here opens
|
|
155
|
+
// the drawer, so the Chromatic snapshot stays valid.
|
|
156
|
+
const canvas = within(canvasElement);
|
|
157
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
158
|
+
|
|
159
|
+
await step(
|
|
160
|
+
'screen-reader: the trigger exposes a named button (WCAG 4.1.2)',
|
|
161
|
+
async () => {
|
|
162
|
+
await expect(trigger).toBeEnabled();
|
|
163
|
+
await expect(trigger).toHaveAccessibleName('Open Drawer');
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
await step(
|
|
168
|
+
'interaction: the closed trigger reports the collapsed drawer it opens',
|
|
169
|
+
async () => {
|
|
170
|
+
await expect(trigger).toHaveAttribute('aria-haspopup', 'dialog');
|
|
171
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
172
|
+
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
},
|
|
145
176
|
};
|
|
146
177
|
|
|
147
178
|
const controlledTemplateSource = `<script setup lang="ts">
|
|
@@ -601,4 +632,638 @@ export const OpenByDefault: Story = {
|
|
|
601
632
|
controls: { disable: true },
|
|
602
633
|
docs: { source: { code: openByDefaultTemplateSource } },
|
|
603
634
|
},
|
|
635
|
+
play: async ({ step }) => {
|
|
636
|
+
// Scenario (UiDrawer): the drawer is already open, so assistive tech can be
|
|
637
|
+
// checked against the resting panel — no interaction, and the Chromatic
|
|
638
|
+
// snapshot of the open drawer stays valid. The panel is portalled to
|
|
639
|
+
// `document.body`, so queries are bound there rather than to the canvas.
|
|
640
|
+
const body = within(document.body);
|
|
641
|
+
const drawer = await body.findByRole('dialog');
|
|
642
|
+
|
|
643
|
+
await step(
|
|
644
|
+
'screen-reader: the panel exposes a dialog named by its title (WCAG 4.1.2)',
|
|
645
|
+
async () => {
|
|
646
|
+
await expect(drawer).toHaveAccessibleName('Open by default');
|
|
647
|
+
},
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
await step(
|
|
651
|
+
'screen-reader: the panel is described by its supporting text (WCAG 4.1.2)',
|
|
652
|
+
async () => {
|
|
653
|
+
await expect(drawer).toHaveAccessibleDescription(
|
|
654
|
+
'Useful for visual regression testing.',
|
|
655
|
+
);
|
|
656
|
+
},
|
|
657
|
+
);
|
|
658
|
+
|
|
659
|
+
await step(
|
|
660
|
+
'interaction: the open drawer reports its state and holds a named close control',
|
|
661
|
+
async () => {
|
|
662
|
+
await expect(drawer).toHaveAttribute('data-state', 'open');
|
|
663
|
+
await expect(
|
|
664
|
+
body.getByRole('button', { name: 'Close' }),
|
|
665
|
+
).toHaveAccessibleName('Close');
|
|
666
|
+
},
|
|
667
|
+
);
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Accessibility guidance for naming the drawer, describing it, keeping it
|
|
673
|
+
* dismissible, and contrast.
|
|
674
|
+
*/
|
|
675
|
+
export const Accessibility: Story = {
|
|
676
|
+
render: () => ({
|
|
677
|
+
components: {
|
|
678
|
+
UiDrawer,
|
|
679
|
+
UiDrawerClose,
|
|
680
|
+
UiDrawerContent,
|
|
681
|
+
UiDrawerDescription,
|
|
682
|
+
UiDrawerFooter,
|
|
683
|
+
UiDrawerHeader,
|
|
684
|
+
UiDrawerTitle,
|
|
685
|
+
UiDrawerTrigger,
|
|
686
|
+
UiButton,
|
|
687
|
+
},
|
|
688
|
+
setup() {
|
|
689
|
+
const defaultOpen = ref(false);
|
|
690
|
+
const accessibleOpen = ref(false);
|
|
691
|
+
return { defaultOpen, accessibleOpen };
|
|
692
|
+
},
|
|
693
|
+
template: `
|
|
694
|
+
<section class="flex flex-col gap-6 p-4">
|
|
695
|
+
<div>
|
|
696
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
697
|
+
Accessibility
|
|
698
|
+
</h2>
|
|
699
|
+
</div>
|
|
700
|
+
|
|
701
|
+
<div class="flex flex-col gap-6">
|
|
702
|
+
<div class="flex flex-col gap-2">
|
|
703
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
704
|
+
Always include a title
|
|
705
|
+
</h3>
|
|
706
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
707
|
+
<code>UiDrawerTitle</code> becomes the drawer's accessible name
|
|
708
|
+
via <code>aria-labelledby</code>. Without it the panel is
|
|
709
|
+
announced as an unnamed dialog, and a screen-reader user has no
|
|
710
|
+
idea what just opened.
|
|
711
|
+
</p>
|
|
712
|
+
</div>
|
|
713
|
+
|
|
714
|
+
<div class="flex flex-col gap-2">
|
|
715
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
716
|
+
Describe what the drawer is for
|
|
717
|
+
</h3>
|
|
718
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
719
|
+
<code>UiDrawerDescription</code> is wired up as
|
|
720
|
+
<code>aria-describedby</code>, so it is read straight after the
|
|
721
|
+
title. Keep it to one sentence that explains the purpose rather
|
|
722
|
+
than repeating the title.
|
|
723
|
+
</p>
|
|
724
|
+
</div>
|
|
725
|
+
|
|
726
|
+
<div class="flex flex-col gap-2">
|
|
727
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
728
|
+
Keep it dismissible from the keyboard
|
|
729
|
+
</h3>
|
|
730
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
731
|
+
A modal drawer traps focus, so it must always offer a way out.
|
|
732
|
+
<code>Escape</code> closes it and focus returns to the trigger;
|
|
733
|
+
add a <code>UiDrawerClose</code> button in the footer so the exit
|
|
734
|
+
is visible too.
|
|
735
|
+
</p>
|
|
736
|
+
</div>
|
|
737
|
+
|
|
738
|
+
<div class="flex flex-col gap-2">
|
|
739
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
740
|
+
The handle is decorative
|
|
741
|
+
</h3>
|
|
742
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
743
|
+
The grab handle at the top of the sheet is presentational only —
|
|
744
|
+
it is not focusable and announces nothing. Never make it the only
|
|
745
|
+
way to close the drawer.
|
|
746
|
+
</p>
|
|
747
|
+
</div>
|
|
748
|
+
|
|
749
|
+
<div class="flex flex-col gap-2">
|
|
750
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
751
|
+
Enable accessibility theme
|
|
752
|
+
</h3>
|
|
753
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
754
|
+
When accessibility is required, enable our accessibility theme.
|
|
755
|
+
This increases contrast and makes sure there are no color
|
|
756
|
+
contrast issues.
|
|
757
|
+
</p>
|
|
758
|
+
</div>
|
|
759
|
+
</div>
|
|
760
|
+
|
|
761
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
762
|
+
<div class="flex flex-col gap-3">
|
|
763
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
764
|
+
Default
|
|
765
|
+
</h3>
|
|
766
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
767
|
+
<UiDrawer v-model:open="defaultOpen">
|
|
768
|
+
<UiDrawerTrigger as-child>
|
|
769
|
+
<UiButton variant="outline">Open Drawer</UiButton>
|
|
770
|
+
</UiDrawerTrigger>
|
|
771
|
+
<UiDrawerContent>
|
|
772
|
+
<UiDrawerHeader>
|
|
773
|
+
<UiDrawerTitle>Drawer title</UiDrawerTitle>
|
|
774
|
+
<UiDrawerDescription>
|
|
775
|
+
Review the details below before continuing.
|
|
776
|
+
</UiDrawerDescription>
|
|
777
|
+
</UiDrawerHeader>
|
|
778
|
+
<div class="p-4 pt-0 body-14-regular">Put any content here.</div>
|
|
779
|
+
<UiDrawerFooter>
|
|
780
|
+
<UiDrawerClose as-child>
|
|
781
|
+
<UiButton>Close</UiButton>
|
|
782
|
+
</UiDrawerClose>
|
|
783
|
+
</UiDrawerFooter>
|
|
784
|
+
</UiDrawerContent>
|
|
785
|
+
</UiDrawer>
|
|
786
|
+
</div>
|
|
787
|
+
</div>
|
|
788
|
+
|
|
789
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
790
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
791
|
+
Accessible
|
|
792
|
+
</h3>
|
|
793
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
794
|
+
<UiDrawer v-model:open="accessibleOpen">
|
|
795
|
+
<UiDrawerTrigger as-child>
|
|
796
|
+
<UiButton variant="outline">Open Drawer</UiButton>
|
|
797
|
+
</UiDrawerTrigger>
|
|
798
|
+
<UiDrawerContent>
|
|
799
|
+
<UiDrawerHeader>
|
|
800
|
+
<UiDrawerTitle>Drawer title</UiDrawerTitle>
|
|
801
|
+
<UiDrawerDescription>
|
|
802
|
+
Review the details below before continuing.
|
|
803
|
+
</UiDrawerDescription>
|
|
804
|
+
</UiDrawerHeader>
|
|
805
|
+
<div class="p-4 pt-0 body-14-regular">Put any content here.</div>
|
|
806
|
+
<UiDrawerFooter>
|
|
807
|
+
<UiDrawerClose as-child>
|
|
808
|
+
<UiButton>Close</UiButton>
|
|
809
|
+
</UiDrawerClose>
|
|
810
|
+
</UiDrawerFooter>
|
|
811
|
+
</UiDrawerContent>
|
|
812
|
+
</UiDrawer>
|
|
813
|
+
</div>
|
|
814
|
+
</div>
|
|
815
|
+
</div>
|
|
816
|
+
</section>
|
|
817
|
+
`,
|
|
818
|
+
}),
|
|
819
|
+
tags: ['!autodocs'],
|
|
820
|
+
parameters: {
|
|
821
|
+
a11y: { test: 'off' },
|
|
822
|
+
chromatic: {
|
|
823
|
+
disableSnapshot: true,
|
|
824
|
+
},
|
|
825
|
+
docs: {
|
|
826
|
+
canvas: {
|
|
827
|
+
sourceState: 'none',
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
/*
|
|
834
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
835
|
+
* Interaction & accessibility tests (play functions)
|
|
836
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
837
|
+
* The stories below are hidden from the sidebar and the docs page but still run
|
|
838
|
+
* in the Storybook test-runner on every PR, alongside the axe audit. The
|
|
839
|
+
* `step()` prefix is parsed into the CI report, so keep it accurate:
|
|
840
|
+
* • `interaction:` behaviour and guards (WCAG 4.1.2)
|
|
841
|
+
* • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
|
|
842
|
+
* • `screen-reader:` names, roles and states (WCAG 4.1.2)
|
|
843
|
+
* • `zoom:` operable when magnified (WCAG 1.4.4)
|
|
844
|
+
* • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
|
|
845
|
+
* The Accessibility column is filled automatically by the axe audit — never add
|
|
846
|
+
* an `a11y:` prefix.
|
|
847
|
+
*
|
|
848
|
+
* Between them these plays exercise every sub-component: `UiDrawerTrigger`
|
|
849
|
+
* opens the panel, `UiDrawerContent` provides the dialog and its focus trap,
|
|
850
|
+
* `UiDrawerTitle` / `UiDrawerDescription` supply the accessible name and
|
|
851
|
+
* description, and `UiDrawerClose` in `UiDrawerFooter` dismisses it. Class
|
|
852
|
+
* forwarding on `UiDrawerContent` needs no browser and stays in Vitest under
|
|
853
|
+
* `__tests__/`.
|
|
854
|
+
*/
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Waits for the drawer to be open and painted. The sheet fades and slides up,
|
|
858
|
+
* so it is in the DOM a frame before it is visible.
|
|
859
|
+
* @param body Queries bound to the document body, where the drawer is portalled.
|
|
860
|
+
* @returns The open drawer panel.
|
|
861
|
+
*/
|
|
862
|
+
async function expectOpenDrawer(body: ReturnType<typeof within>) {
|
|
863
|
+
const drawer = await body.findByRole('dialog');
|
|
864
|
+
await waitFor(async () => {
|
|
865
|
+
await expect(drawer).toBeVisible();
|
|
866
|
+
});
|
|
867
|
+
return drawer;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Waits until the portalled drawer has left the accessibility tree.
|
|
872
|
+
* @param body Queries bound to the document body, where the drawer is portalled.
|
|
873
|
+
*/
|
|
874
|
+
async function expectClosedDrawer(body: ReturnType<typeof within>) {
|
|
875
|
+
await waitFor(async () => {
|
|
876
|
+
await expect(body.queryByRole('dialog')).toBeNull();
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* The drawer the test stories drive: a titled and described sheet with a single
|
|
882
|
+
* `UiDrawerClose` in the footer. Closed on load, so a play function can open it
|
|
883
|
+
* the way a user would.
|
|
884
|
+
* @returns Vue component options for a story `render` function.
|
|
885
|
+
*/
|
|
886
|
+
function renderTestDrawer() {
|
|
887
|
+
return {
|
|
888
|
+
components: {
|
|
889
|
+
UiDrawer,
|
|
890
|
+
UiDrawerClose,
|
|
891
|
+
UiDrawerContent,
|
|
892
|
+
UiDrawerDescription,
|
|
893
|
+
UiDrawerFooter,
|
|
894
|
+
UiDrawerHeader,
|
|
895
|
+
UiDrawerTitle,
|
|
896
|
+
UiDrawerTrigger,
|
|
897
|
+
UiButton,
|
|
898
|
+
},
|
|
899
|
+
setup() {
|
|
900
|
+
const open = ref(false);
|
|
901
|
+
return { open, onUpdateOpen, onEscapeKeyDown };
|
|
902
|
+
},
|
|
903
|
+
template: `
|
|
904
|
+
<UiDrawer v-model:open="open" @update:open="onUpdateOpen">
|
|
905
|
+
<UiDrawerTrigger as-child>
|
|
906
|
+
<UiButton variant="outline">Open Drawer</UiButton>
|
|
907
|
+
</UiDrawerTrigger>
|
|
908
|
+
<UiDrawerContent @escape-key-down="onEscapeKeyDown">
|
|
909
|
+
<UiDrawerHeader>
|
|
910
|
+
<UiDrawerTitle>Drawer title</UiDrawerTitle>
|
|
911
|
+
<UiDrawerDescription>
|
|
912
|
+
Review the details below before continuing.
|
|
913
|
+
</UiDrawerDescription>
|
|
914
|
+
</UiDrawerHeader>
|
|
915
|
+
<div class="p-4 pt-0 body-14-regular">Put any content here.</div>
|
|
916
|
+
<UiDrawerFooter>
|
|
917
|
+
<UiDrawerClose as-child>
|
|
918
|
+
<UiButton>Close</UiButton>
|
|
919
|
+
</UiDrawerClose>
|
|
920
|
+
</UiDrawerFooter>
|
|
921
|
+
</UiDrawerContent>
|
|
922
|
+
</UiDrawer>
|
|
923
|
+
`,
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Opening the drawer from its trigger and dismissing it with the footer close
|
|
929
|
+
* control, which hands focus back to the trigger. Hidden test-only story.
|
|
930
|
+
*/
|
|
931
|
+
export const PointerInteraction: Story = {
|
|
932
|
+
name: 'test - Pointer Interaction',
|
|
933
|
+
tags: ['!dev', '!autodocs'],
|
|
934
|
+
parameters: {
|
|
935
|
+
// The drawer opens and focus moves during the play function.
|
|
936
|
+
chromatic: { disableSnapshot: true },
|
|
937
|
+
docs: {
|
|
938
|
+
description: {
|
|
939
|
+
story:
|
|
940
|
+
'Click the trigger to open the drawer, then dismiss it with the footer Close button.',
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
render: renderTestDrawer,
|
|
945
|
+
play: async ({ canvasElement, step }) => {
|
|
946
|
+
// Scenario (UiDrawer): a pointer user opens the sheet from the trigger,
|
|
947
|
+
// closes it with the footer button, and lands back on the trigger they
|
|
948
|
+
// started from.
|
|
949
|
+
onUpdateOpen.mockClear();
|
|
950
|
+
const canvas = within(canvasElement);
|
|
951
|
+
const body = within(document.body);
|
|
952
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
953
|
+
|
|
954
|
+
await step('interaction: the trigger opens the drawer', async () => {
|
|
955
|
+
await userEvent.click(trigger);
|
|
956
|
+
await expectOpenDrawer(body);
|
|
957
|
+
await expect(onUpdateOpen).toHaveBeenCalledWith(true);
|
|
958
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
await step(
|
|
962
|
+
'interaction: the footer close control dismisses the drawer',
|
|
963
|
+
async () => {
|
|
964
|
+
await userEvent.click(body.getByRole('button', { name: 'Close' }));
|
|
965
|
+
await expectClosedDrawer(body);
|
|
966
|
+
await expect(onUpdateOpen).toHaveBeenCalledWith(false);
|
|
967
|
+
},
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
await step(
|
|
971
|
+
'interaction: closing returns focus to the trigger that opened it (WCAG 2.4.3)',
|
|
972
|
+
async () => {
|
|
973
|
+
await waitFor(async () => {
|
|
974
|
+
await expect(trigger).toHaveFocus();
|
|
975
|
+
});
|
|
976
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
977
|
+
},
|
|
978
|
+
);
|
|
979
|
+
},
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Reaching the drawer, staying inside its focus trap, and dismissing it without
|
|
984
|
+
* a pointer. Hidden test-only story.
|
|
985
|
+
*/
|
|
986
|
+
export const KeyboardNavigation: Story = {
|
|
987
|
+
name: 'test - Keyboard Navigation',
|
|
988
|
+
tags: ['!dev', '!autodocs'],
|
|
989
|
+
parameters: {
|
|
990
|
+
// Focus moves and the drawer opens during the play function.
|
|
991
|
+
chromatic: { disableSnapshot: true },
|
|
992
|
+
docs: {
|
|
993
|
+
description: {
|
|
994
|
+
story:
|
|
995
|
+
'Press `Tab` to focus the trigger, `Enter` to open, `Tab` to move inside, and `Escape` to dismiss.',
|
|
996
|
+
},
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
render: renderTestDrawer,
|
|
1000
|
+
play: async ({ canvasElement, step }) => {
|
|
1001
|
+
// Scenario (UiDrawer): a keyboard user tabs to the trigger, opens the sheet
|
|
1002
|
+
// with Enter, finds focus moved inside and held there, dismisses with
|
|
1003
|
+
// Escape, and gets focus back on the trigger.
|
|
1004
|
+
onUpdateOpen.mockClear();
|
|
1005
|
+
onEscapeKeyDown.mockClear();
|
|
1006
|
+
const canvas = within(canvasElement);
|
|
1007
|
+
const body = within(document.body);
|
|
1008
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
1009
|
+
|
|
1010
|
+
await step(
|
|
1011
|
+
'keyboard: the trigger is reachable via Tab (WCAG 2.1.1)',
|
|
1012
|
+
async () => {
|
|
1013
|
+
await userEvent.tab();
|
|
1014
|
+
await expect(trigger).toHaveFocus();
|
|
1015
|
+
},
|
|
1016
|
+
);
|
|
1017
|
+
|
|
1018
|
+
await step(
|
|
1019
|
+
'keyboard: Enter opens the drawer and moves focus inside it',
|
|
1020
|
+
async () => {
|
|
1021
|
+
await userEvent.keyboard('{Enter}');
|
|
1022
|
+
const drawer = await expectOpenDrawer(body);
|
|
1023
|
+
await waitFor(async () => {
|
|
1024
|
+
await expect(drawer.contains(document.activeElement)).toBe(true);
|
|
1025
|
+
});
|
|
1026
|
+
},
|
|
1027
|
+
);
|
|
1028
|
+
|
|
1029
|
+
await step(
|
|
1030
|
+
'keyboard: Tab keeps focus trapped inside the open drawer (WCAG 2.4.3)',
|
|
1031
|
+
async () => {
|
|
1032
|
+
const drawer = body.getByRole('dialog');
|
|
1033
|
+
await userEvent.tab();
|
|
1034
|
+
await expect(drawer.contains(document.activeElement)).toBe(true);
|
|
1035
|
+
await userEvent.tab();
|
|
1036
|
+
await expect(drawer.contains(document.activeElement)).toBe(true);
|
|
1037
|
+
},
|
|
1038
|
+
);
|
|
1039
|
+
|
|
1040
|
+
await step(
|
|
1041
|
+
'keyboard: Escape dismisses the drawer and restores focus to the trigger (WCAG 2.1.2)',
|
|
1042
|
+
async () => {
|
|
1043
|
+
await userEvent.keyboard('{Escape}');
|
|
1044
|
+
await expect(onEscapeKeyDown).toHaveBeenCalled();
|
|
1045
|
+
await expectClosedDrawer(body);
|
|
1046
|
+
await waitFor(async () => {
|
|
1047
|
+
await expect(trigger).toHaveFocus();
|
|
1048
|
+
});
|
|
1049
|
+
},
|
|
1050
|
+
);
|
|
1051
|
+
|
|
1052
|
+
await step(
|
|
1053
|
+
'keyboard: Space also opens the drawer from the trigger',
|
|
1054
|
+
async () => {
|
|
1055
|
+
await userEvent.keyboard(' ');
|
|
1056
|
+
await expectOpenDrawer(body);
|
|
1057
|
+
await userEvent.keyboard('{Escape}');
|
|
1058
|
+
await expectClosedDrawer(body);
|
|
1059
|
+
},
|
|
1060
|
+
);
|
|
1061
|
+
},
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Screen-reader semantics: the open sheet is a dialog named by its title and
|
|
1066
|
+
* described by its supporting text, and the trigger reports the open state
|
|
1067
|
+
* (WCAG 4.1.2). Hidden test-only story.
|
|
1068
|
+
*/
|
|
1069
|
+
export const ScreenReader: Story = {
|
|
1070
|
+
name: 'test - Screen Reader',
|
|
1071
|
+
tags: ['!dev', '!autodocs'],
|
|
1072
|
+
parameters: {
|
|
1073
|
+
// The drawer opens and focus moves during the play function.
|
|
1074
|
+
chromatic: { disableSnapshot: true },
|
|
1075
|
+
docs: {
|
|
1076
|
+
description: {
|
|
1077
|
+
story:
|
|
1078
|
+
'Verifies the dialog role, accessible name, description, and trigger state that assistive technology announces.',
|
|
1079
|
+
},
|
|
1080
|
+
},
|
|
1081
|
+
},
|
|
1082
|
+
render: renderTestDrawer,
|
|
1083
|
+
play: async ({ canvasElement, step }) => {
|
|
1084
|
+
// Scenario (UiDrawer): assistive tech reads the sheet as a dialog named by
|
|
1085
|
+
// its title, hears the description, and hears the trigger switch to
|
|
1086
|
+
// expanded while it is open.
|
|
1087
|
+
const canvas = within(canvasElement);
|
|
1088
|
+
const body = within(document.body);
|
|
1089
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
1090
|
+
|
|
1091
|
+
await userEvent.click(trigger);
|
|
1092
|
+
const drawer = await expectOpenDrawer(body);
|
|
1093
|
+
|
|
1094
|
+
await step(
|
|
1095
|
+
'screen-reader: the panel exposes a dialog role named by its title (WCAG 4.1.2)',
|
|
1096
|
+
async () => {
|
|
1097
|
+
await expect(drawer).toHaveAttribute('role', 'dialog');
|
|
1098
|
+
await expect(drawer).toHaveAccessibleName('Drawer title');
|
|
1099
|
+
},
|
|
1100
|
+
);
|
|
1101
|
+
|
|
1102
|
+
await step(
|
|
1103
|
+
'screen-reader: the panel is described by its supporting text (WCAG 4.1.2)',
|
|
1104
|
+
async () => {
|
|
1105
|
+
await expect(drawer).toHaveAccessibleDescription(
|
|
1106
|
+
'Review the details below before continuing.',
|
|
1107
|
+
);
|
|
1108
|
+
},
|
|
1109
|
+
);
|
|
1110
|
+
|
|
1111
|
+
await step(
|
|
1112
|
+
'screen-reader: the trigger announces the expanded drawer it controls',
|
|
1113
|
+
async () => {
|
|
1114
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
1115
|
+
await expect(trigger).toHaveAttribute('aria-controls', drawer.id);
|
|
1116
|
+
},
|
|
1117
|
+
);
|
|
1118
|
+
|
|
1119
|
+
await step(
|
|
1120
|
+
'screen-reader: the close control exposes an accessible name (WCAG 4.1.2)',
|
|
1121
|
+
async () => {
|
|
1122
|
+
await expect(
|
|
1123
|
+
body.getByRole('button', { name: 'Close' }),
|
|
1124
|
+
).toHaveAccessibleName('Close');
|
|
1125
|
+
},
|
|
1126
|
+
);
|
|
1127
|
+
|
|
1128
|
+
await userEvent.keyboard('{Escape}');
|
|
1129
|
+
await expectClosedDrawer(body);
|
|
1130
|
+
},
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1135
|
+
* try 400% reflow (WCAG 1.4.10); the sheet must stay readable and operable.
|
|
1136
|
+
* Hidden test-only story.
|
|
1137
|
+
*/
|
|
1138
|
+
export const ZoomMagnification: Story = {
|
|
1139
|
+
name: 'test - Zoom Magnification',
|
|
1140
|
+
tags: ['!dev', '!autodocs'],
|
|
1141
|
+
globals: { zoom: '200' },
|
|
1142
|
+
parameters: {
|
|
1143
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
1144
|
+
// already covers magnified snapshots, so skip this one.
|
|
1145
|
+
chromatic: { disableSnapshot: true },
|
|
1146
|
+
docs: {
|
|
1147
|
+
description: {
|
|
1148
|
+
story:
|
|
1149
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1150
|
+
},
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
render: renderTestDrawer,
|
|
1154
|
+
play: async ({ canvasElement, step }) => {
|
|
1155
|
+
// Scenario (UiDrawer): at 200% page zoom the trigger stays named, the sheet
|
|
1156
|
+
// still opens with its title and description on screen, and Close works.
|
|
1157
|
+
onUpdateOpen.mockClear();
|
|
1158
|
+
const canvas = within(canvasElement);
|
|
1159
|
+
const body = within(document.body);
|
|
1160
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
1161
|
+
|
|
1162
|
+
await step(
|
|
1163
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1164
|
+
async () => {
|
|
1165
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1166
|
+
},
|
|
1167
|
+
);
|
|
1168
|
+
|
|
1169
|
+
await step(
|
|
1170
|
+
'zoom: the trigger stays visible with its accessible name',
|
|
1171
|
+
async () => {
|
|
1172
|
+
await expect(trigger).toBeVisible();
|
|
1173
|
+
await expect(trigger).toHaveAccessibleName('Open Drawer');
|
|
1174
|
+
},
|
|
1175
|
+
);
|
|
1176
|
+
|
|
1177
|
+
await step(
|
|
1178
|
+
'zoom: the drawer opens and stays readable when magnified',
|
|
1179
|
+
async () => {
|
|
1180
|
+
await userEvent.click(trigger);
|
|
1181
|
+
const drawer = await expectOpenDrawer(body);
|
|
1182
|
+
await expect(drawer).toHaveAccessibleName('Drawer title');
|
|
1183
|
+
await expect(body.getByText('Drawer title')).toBeVisible();
|
|
1184
|
+
await expect(
|
|
1185
|
+
body.getByText('Review the details below before continuing.'),
|
|
1186
|
+
).toBeVisible();
|
|
1187
|
+
|
|
1188
|
+
const { left, right } = drawer.getBoundingClientRect();
|
|
1189
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
1190
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth);
|
|
1191
|
+
},
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1194
|
+
await step('zoom: remains operable when magnified', async () => {
|
|
1195
|
+
await userEvent.click(body.getByRole('button', { name: 'Close' }));
|
|
1196
|
+
await expectClosedDrawer(body);
|
|
1197
|
+
await expect(onUpdateOpen).toHaveBeenCalledWith(false);
|
|
1198
|
+
});
|
|
1199
|
+
},
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1204
|
+
* toolbar. Stays operable, fits the viewport, and its controls meet the minimum
|
|
1205
|
+
* touch-target size (WCAG 2.5.8). Hidden test-only story.
|
|
1206
|
+
*/
|
|
1207
|
+
export const MobileBreakpoint: Story = {
|
|
1208
|
+
name: 'test - Mobile Breakpoint',
|
|
1209
|
+
tags: ['!dev', '!autodocs'],
|
|
1210
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1211
|
+
parameters: {
|
|
1212
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
1213
|
+
chromatic: { disableSnapshot: true },
|
|
1214
|
+
docs: {
|
|
1215
|
+
description: {
|
|
1216
|
+
story:
|
|
1217
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1218
|
+
},
|
|
1219
|
+
},
|
|
1220
|
+
},
|
|
1221
|
+
render: renderTestDrawer,
|
|
1222
|
+
play: async ({ canvasElement, step }) => {
|
|
1223
|
+
// Scenario (UiDrawer): at the 320px mobile breakpoint the trigger opens the
|
|
1224
|
+
// sheet, the sheet fits the viewport, and both controls are big enough to
|
|
1225
|
+
// tap.
|
|
1226
|
+
onUpdateOpen.mockClear();
|
|
1227
|
+
const canvas = within(canvasElement);
|
|
1228
|
+
const body = within(document.body);
|
|
1229
|
+
const trigger = canvas.getByRole('button', { name: 'Open Drawer' });
|
|
1230
|
+
|
|
1231
|
+
await step(
|
|
1232
|
+
'mobile: the trigger stays operable at the 320px breakpoint',
|
|
1233
|
+
async () => {
|
|
1234
|
+
await expect(trigger).toBeVisible();
|
|
1235
|
+
await expect(trigger).toBeEnabled();
|
|
1236
|
+
await userEvent.click(trigger);
|
|
1237
|
+
await expectOpenDrawer(body);
|
|
1238
|
+
},
|
|
1239
|
+
);
|
|
1240
|
+
|
|
1241
|
+
await step(
|
|
1242
|
+
'mobile: the drawer fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
1243
|
+
async () => {
|
|
1244
|
+
const { left, right } = body
|
|
1245
|
+
.getByRole('dialog')
|
|
1246
|
+
.getBoundingClientRect();
|
|
1247
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
1248
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth);
|
|
1249
|
+
},
|
|
1250
|
+
);
|
|
1251
|
+
|
|
1252
|
+
await step(
|
|
1253
|
+
'mobile: the trigger and close control meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1254
|
+
async () => {
|
|
1255
|
+
const close = body.getByRole('button', { name: 'Close' });
|
|
1256
|
+
|
|
1257
|
+
for (const control of [trigger, close]) {
|
|
1258
|
+
const { width, height } = control.getBoundingClientRect();
|
|
1259
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1260
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
);
|
|
1264
|
+
|
|
1265
|
+
// Close again so the end-of-play axe audit sees the resting state.
|
|
1266
|
+
await userEvent.keyboard('{Escape}');
|
|
1267
|
+
await expectClosedDrawer(body);
|
|
1268
|
+
},
|
|
604
1269
|
};
|