@aleph-alpha/ui-library 5.11.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/config.d.ts +28 -4
  3. package/config.js +99 -23
  4. package/dist/system/components/UiTagsInput/UiTagsInput.vue.d.ts +2 -0
  5. package/dist/system/components/UiTagsInput/UiTagsInputItemDelete.vue.d.ts +2 -1
  6. package/dist/system/components/UiTagsInput/types.d.ts +21 -2
  7. package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
  8. package/dist/system/icons/story-sidebar-icons.json +7 -0
  9. package/dist/system/lib.js +1752 -1708
  10. package/dist/system/story-sidebar-icons.json +7 -0
  11. package/docs/public-docs/migration-guide.md +402 -0
  12. package/docs/public-docs/quick-start.md +20 -11
  13. package/package.json +5 -2
  14. package/src/components/UiAlert/UiAlert.stories.ts +732 -0
  15. package/src/components/UiAlert/__tests__/UiAlert.test.ts +57 -11
  16. package/src/components/UiChip/UiChip.stories.ts +756 -2
  17. package/src/components/UiChip/UiChip.vue +7 -6
  18. package/src/components/UiChip/__tests__/UiChip.test.ts +38 -61
  19. package/src/components/UiDrawer/UiDrawer.stories.ts +665 -0
  20. package/src/components/UiDrawer/__tests__/UiDrawer.test.ts +6 -190
  21. package/src/components/UiLabel/UiLabel.stories.ts +691 -16
  22. package/src/components/UiLabel/__tests__/UiLabel.test.ts +18 -26
  23. package/src/components/UiSheet/UiSheet.stories.ts +751 -0
  24. package/src/components/UiSheet/__tests__/UiSheet.test.ts +6 -190
  25. package/src/components/UiSlider/UiSlider.stories.ts +716 -0
  26. package/src/components/UiSlider/__tests__/UiSlider.test.ts +8 -45
  27. package/src/components/UiSwitch/UiSwitch.stories.ts +11 -5
  28. package/src/components/UiTagsInput/UiTagsInput.stories.ts +850 -4
  29. package/src/components/UiTagsInput/UiTagsInput.vue +34 -0
  30. package/src/components/UiTagsInput/UiTagsInputItemDelete.vue +4 -1
  31. package/src/components/UiTagsInput/__tests__/UiTagsInput.test.ts +113 -29
  32. package/src/components/UiTagsInput/types.ts +24 -2
  33. package/src/components/core/sheet/SheetContent.vue +6 -1
  34. package/src/components/core/switch/index.ts +8 -7
  35. package/src/components/core/tags-input/TagsInput.vue +4 -1
  36. package/src/components/core/tags-input/TagsInputItem.vue +13 -1
  37. package/src/components/core/tags-input/TagsInputItemDelete.vue +40 -7
  38. package/src/theme/Typography.stories.ts +125 -133
  39. package/tokens.json +8132 -2475
  40. package/dist/system/icons/mobile-device-frame.png +0 -0
  41. 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
  UiSheet,
4
5
  UiSheetClose,
@@ -44,6 +45,12 @@ const meta: Meta<typeof UiSheet> = {
44
45
  export default meta;
45
46
  type Story = StoryObj<typeof UiSheet>;
46
47
 
48
+ // `UiSheet` wires reka-ui's `open` model and `UiSheetContent` re-emits
49
+ // `escapeKeyDown` — neither is a handler prop, so play functions bind these
50
+ // module-level spies in the template and `mockClear()` them first.
51
+ const onUpdateOpen = fn();
52
+ const onEscapeKeyDown = fn();
53
+
47
54
  const defaultTemplateSource = `<script setup lang="ts">
48
55
  import {
49
56
  UiSheet,
@@ -145,6 +152,32 @@ export const Default: Story = {
145
152
  parameters: {
146
153
  docs: { source: { code: defaultTemplateSource } },
147
154
  },
155
+ play: async ({ canvasElement, step }) => {
156
+ // Scenario (UiSheet): assistive tech sees a named trigger that reports the
157
+ // sheet it controls and that it is currently closed. Nothing here opens the
158
+ // sheet, so the Chromatic snapshot stays valid.
159
+ const canvas = within(canvasElement);
160
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
161
+
162
+ await step(
163
+ 'screen-reader: the trigger exposes a named button (WCAG 4.1.2)',
164
+ async () => {
165
+ await expect(trigger).toBeEnabled();
166
+ await expect(trigger).toHaveAccessibleName('Open Sheet');
167
+ },
168
+ );
169
+
170
+ await step(
171
+ 'interaction: the closed trigger reports the collapsed sheet it opens',
172
+ async () => {
173
+ await expect(trigger).toHaveAttribute('aria-haspopup', 'dialog');
174
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
175
+ await expect(
176
+ within(document.body).queryByRole('dialog'),
177
+ ).not.toBeInTheDocument();
178
+ },
179
+ );
180
+ },
148
181
  };
149
182
 
150
183
  const controlledTemplateSource = `<script setup lang="ts">
@@ -714,4 +747,722 @@ export const OpenByDefault: Story = {
714
747
  controls: { disable: true },
715
748
  docs: { source: { code: openByDefaultTemplateSource } },
716
749
  },
750
+ play: async ({ step }) => {
751
+ // Scenario (UiSheet): the sheet is already open, so assistive tech can be
752
+ // checked against the resting panel — no interaction, and the Chromatic
753
+ // snapshot of the open sheet stays valid. The panel is portalled to
754
+ // `document.body`, so queries are bound there rather than to the canvas.
755
+ const body = within(document.body);
756
+ const sheet = await body.findByRole('dialog');
757
+
758
+ await step(
759
+ 'screen-reader: the panel exposes a dialog named by its title (WCAG 4.1.2)',
760
+ async () => {
761
+ await expect(sheet).toHaveAccessibleName('Open by default');
762
+ },
763
+ );
764
+
765
+ await step(
766
+ 'screen-reader: the panel is described by its supporting text (WCAG 4.1.2)',
767
+ async () => {
768
+ await expect(sheet).toHaveAccessibleDescription(
769
+ 'Useful for visual regression testing.',
770
+ );
771
+ },
772
+ );
773
+
774
+ await step(
775
+ 'interaction: the open sheet reports its state and offers a labelled close control',
776
+ async () => {
777
+ await expect(sheet).toHaveAttribute('data-state', 'open');
778
+ // This story pairs a footer `UiSheetClose` with the built-in X, so both
779
+ // carry the default "Close" label — see the Accessibility story for why
780
+ // a distinct footer label reads better.
781
+ const closeControls = within(sheet).getAllByRole('button', {
782
+ name: 'Close',
783
+ });
784
+ await expect(closeControls.length).toBeGreaterThanOrEqual(1);
785
+ for (const control of closeControls) {
786
+ await expect(control).toBeEnabled();
787
+ }
788
+ },
789
+ );
790
+ },
791
+ };
792
+
793
+ /**
794
+ * Accessibility guidance for naming the sheet, describing it, labelling the
795
+ * built-in close control, and contrast.
796
+ */
797
+ export const Accessibility: Story = {
798
+ render: () => ({
799
+ components: {
800
+ UiSheet,
801
+ UiSheetClose,
802
+ UiSheetContent,
803
+ UiSheetDescription,
804
+ UiSheetFooter,
805
+ UiSheetHeader,
806
+ UiSheetTitle,
807
+ UiSheetTrigger,
808
+ UiButton,
809
+ },
810
+ setup() {
811
+ const defaultOpen = ref(false);
812
+ const accessibleOpen = ref(false);
813
+ return { defaultOpen, accessibleOpen };
814
+ },
815
+ template: `
816
+ <section class="flex flex-col gap-6 p-4">
817
+ <div>
818
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
819
+ Accessibility
820
+ </h2>
821
+ </div>
822
+
823
+ <div class="flex flex-col gap-6">
824
+ <div class="flex flex-col gap-2">
825
+ <h3 class="body-16-medium text-content-on-surface-primary">
826
+ Always include a title
827
+ </h3>
828
+ <p class="body-16-regular text-content-on-surface-primary">
829
+ <code>UiSheetTitle</code> becomes the sheet's accessible name via
830
+ <code>aria-labelledby</code>. Without it the panel is announced as
831
+ an unnamed dialog, and a screen-reader user has no idea what just
832
+ slid in.
833
+ </p>
834
+ </div>
835
+
836
+ <div class="flex flex-col gap-2">
837
+ <h3 class="body-16-medium text-content-on-surface-primary">
838
+ Describe what the sheet is for
839
+ </h3>
840
+ <p class="body-16-regular text-content-on-surface-primary">
841
+ <code>UiSheetDescription</code> is wired up as
842
+ <code>aria-describedby</code>, so it is read straight after the
843
+ title. Keep it to one sentence that explains the purpose rather
844
+ than repeating the title.
845
+ </p>
846
+ </div>
847
+
848
+ <div class="flex flex-col gap-2">
849
+ <h3 class="body-16-medium text-content-on-surface-primary">
850
+ Don't duplicate the built-in close
851
+ </h3>
852
+ <p class="body-16-regular text-content-on-surface-primary">
853
+ <code>UiSheetContent</code> already renders an X close control
854
+ labelled <code>Close</code>. If you also add a footer
855
+ <code>UiSheetClose</code>, give it a distinct label such as
856
+ <code>Done</code> or <code>Cancel</code> — otherwise a
857
+ screen-reader user hears two identical "Close" buttons and cannot
858
+ tell them apart. Use <code>closeLabel</code> to translate or
859
+ sharpen the built-in one.
860
+ </p>
861
+ </div>
862
+
863
+ <div class="flex flex-col gap-2">
864
+ <h3 class="body-16-medium text-content-on-surface-primary">
865
+ Keep every exit available
866
+ </h3>
867
+ <p class="body-16-regular text-content-on-surface-primary">
868
+ A modal sheet traps focus, so it must always offer a way out. It
869
+ can be dismissed with <code>Escape</code>, by clicking the
870
+ overlay, or with either close control — and focus returns to the
871
+ trigger every time.
872
+ </p>
873
+ </div>
874
+
875
+ <div class="flex flex-col gap-2">
876
+ <h3 class="body-16-medium text-content-on-surface-primary">
877
+ Enable accessibility theme
878
+ </h3>
879
+ <p class="body-16-regular text-content-on-surface-primary">
880
+ When accessibility is required, enable our accessibility theme.
881
+ This increases contrast and makes sure there are no color
882
+ contrast issues.
883
+ </p>
884
+ </div>
885
+ </div>
886
+
887
+ <div class="grid gap-4 md:grid-cols-2">
888
+ <div class="flex flex-col gap-3">
889
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
890
+ Default
891
+ </h3>
892
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
893
+ <UiSheet v-model:open="defaultOpen">
894
+ <UiSheetTrigger as-child>
895
+ <UiButton variant="outline">Open Sheet</UiButton>
896
+ </UiSheetTrigger>
897
+ <UiSheetContent close-label="Close sheet">
898
+ <UiSheetHeader>
899
+ <UiSheetTitle>Sheet title</UiSheetTitle>
900
+ <UiSheetDescription>
901
+ A slide-out panel for supplementary content.
902
+ </UiSheetDescription>
903
+ </UiSheetHeader>
904
+ <div class="flex-1 overflow-auto px-4 py-4 body-14-regular">
905
+ Put any content here.
906
+ </div>
907
+ <UiSheetFooter>
908
+ <UiSheetClose as-child>
909
+ <UiButton>Done</UiButton>
910
+ </UiSheetClose>
911
+ </UiSheetFooter>
912
+ </UiSheetContent>
913
+ </UiSheet>
914
+ </div>
915
+ </div>
916
+
917
+ <div class="accessible-theme flex flex-col gap-3">
918
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
919
+ Accessible
920
+ </h3>
921
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
922
+ <UiSheet v-model:open="accessibleOpen">
923
+ <UiSheetTrigger as-child>
924
+ <UiButton variant="outline">Open Sheet</UiButton>
925
+ </UiSheetTrigger>
926
+ <UiSheetContent close-label="Close sheet">
927
+ <UiSheetHeader>
928
+ <UiSheetTitle>Sheet title</UiSheetTitle>
929
+ <UiSheetDescription>
930
+ A slide-out panel for supplementary content.
931
+ </UiSheetDescription>
932
+ </UiSheetHeader>
933
+ <div class="flex-1 overflow-auto px-4 py-4 body-14-regular">
934
+ Put any content here.
935
+ </div>
936
+ <UiSheetFooter>
937
+ <UiSheetClose as-child>
938
+ <UiButton>Done</UiButton>
939
+ </UiSheetClose>
940
+ </UiSheetFooter>
941
+ </UiSheetContent>
942
+ </UiSheet>
943
+ </div>
944
+ </div>
945
+ </div>
946
+ </section>
947
+ `,
948
+ }),
949
+ tags: ['!autodocs'],
950
+ parameters: {
951
+ a11y: { test: 'off' },
952
+ chromatic: {
953
+ disableSnapshot: true,
954
+ },
955
+ docs: {
956
+ canvas: {
957
+ sourceState: 'none',
958
+ },
959
+ },
960
+ },
961
+ };
962
+
963
+ /*
964
+ * ─────────────────────────────────────────────────────────────────────────────
965
+ * Interaction & accessibility tests (play functions)
966
+ * ─────────────────────────────────────────────────────────────────────────────
967
+ * The stories below are hidden from the sidebar and the docs page but still run
968
+ * in the Storybook test-runner on every PR, alongside the axe audit. The
969
+ * `step()` prefix is parsed into the CI report, so keep it accurate:
970
+ * • `interaction:` behaviour and guards (WCAG 4.1.2)
971
+ * • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
972
+ * • `screen-reader:` names, roles and states (WCAG 4.1.2)
973
+ * • `zoom:` operable when magnified (WCAG 1.4.4)
974
+ * • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
975
+ * The Accessibility column is filled automatically by the axe audit — never add
976
+ * an `a11y:` prefix.
977
+ *
978
+ * Between them these plays exercise every sub-component: `UiSheetTrigger` opens
979
+ * the panel, `UiSheetContent` provides the dialog, its overlay, its focus trap,
980
+ * and the built-in X close, `UiSheetTitle` / `UiSheetDescription` supply the
981
+ * accessible name and description, and `UiSheetClose` in `UiSheetFooter`
982
+ * dismisses it. The test sheet gives its footer button a distinct "Done" label
983
+ * so it never collides with the built-in "Close sheet" control. Class
984
+ * forwarding on `UiSheetContent` needs no browser and stays in Vitest under
985
+ * `__tests__/`.
986
+ */
987
+
988
+ /**
989
+ * Waits for an element's CSS animations to finish so its geometry is stable.
990
+ * `finished` rejects when an animation is cancelled, which is not a failure
991
+ * here — it just means the element settled another way.
992
+ * @param element Element whose animations should settle.
993
+ */
994
+ async function settleAnimations(element: HTMLElement) {
995
+ if (typeof element.getAnimations !== 'function') return;
996
+ await Promise.all(
997
+ element
998
+ .getAnimations()
999
+ .map((animation) => animation.finished.catch(() => undefined)),
1000
+ );
1001
+ }
1002
+
1003
+ /**
1004
+ * Waits for the sheet to be open and finished sliding in. The panel starts
1005
+ * translated fully out of the viewport, so it reports as visible for the whole
1006
+ * ~500ms slide — measuring geometry before it settles reads the off-screen
1007
+ * position, not the resting one.
1008
+ * @param body Queries bound to the document body, where the sheet is portalled.
1009
+ * @returns The open sheet panel, at rest.
1010
+ */
1011
+ async function expectOpenSheet(body: ReturnType<typeof within>) {
1012
+ const sheet = await body.findByRole('dialog');
1013
+ await waitFor(async () => {
1014
+ await expect(sheet).toBeVisible();
1015
+ });
1016
+ await settleAnimations(sheet);
1017
+ return sheet;
1018
+ }
1019
+
1020
+ /**
1021
+ * Waits until the portalled sheet has left the accessibility tree.
1022
+ * @param body Queries bound to the document body, where the sheet is portalled.
1023
+ */
1024
+ async function expectClosedSheet(body: ReturnType<typeof within>) {
1025
+ await waitFor(async () => {
1026
+ await expect(body.queryByRole('dialog')).toBeNull();
1027
+ });
1028
+ }
1029
+
1030
+ /**
1031
+ * The scrim behind an open sheet. reka-ui gives it `pointer-events: auto` even
1032
+ * in modal mode, so a pointer user really can click it to dismiss.
1033
+ * @returns The overlay element.
1034
+ */
1035
+ function getSheetOverlay(): HTMLElement {
1036
+ const overlay = document.querySelector<HTMLElement>(
1037
+ '[data-slot="sheet-overlay"]',
1038
+ );
1039
+ expect(overlay).not.toBeNull();
1040
+ return overlay as HTMLElement;
1041
+ }
1042
+
1043
+ /**
1044
+ * The sheet the test stories drive: a titled and described panel with a
1045
+ * distinctly labelled footer close plus the built-in X. Closed on load, so a
1046
+ * play function can open it the way a user would.
1047
+ * @returns Vue component options for a story `render` function.
1048
+ */
1049
+ function renderTestSheet() {
1050
+ return {
1051
+ components: {
1052
+ UiSheet,
1053
+ UiSheetClose,
1054
+ UiSheetContent,
1055
+ UiSheetDescription,
1056
+ UiSheetFooter,
1057
+ UiSheetHeader,
1058
+ UiSheetTitle,
1059
+ UiSheetTrigger,
1060
+ UiButton,
1061
+ },
1062
+ setup() {
1063
+ const open = ref(false);
1064
+ return { open, onUpdateOpen, onEscapeKeyDown };
1065
+ },
1066
+ template: `
1067
+ <UiSheet v-model:open="open" @update:open="onUpdateOpen">
1068
+ <UiSheetTrigger as-child>
1069
+ <UiButton variant="outline">Open Sheet</UiButton>
1070
+ </UiSheetTrigger>
1071
+ <UiSheetContent close-label="Close sheet" @escape-key-down="onEscapeKeyDown">
1072
+ <UiSheetHeader>
1073
+ <UiSheetTitle>Sheet title</UiSheetTitle>
1074
+ <UiSheetDescription>
1075
+ A slide-out panel for supplementary content.
1076
+ </UiSheetDescription>
1077
+ </UiSheetHeader>
1078
+ <div class="flex-1 overflow-auto px-4 py-4 body-14-regular">
1079
+ Put any content here.
1080
+ </div>
1081
+ <UiSheetFooter>
1082
+ <UiSheetClose as-child>
1083
+ <UiButton>Done</UiButton>
1084
+ </UiSheetClose>
1085
+ </UiSheetFooter>
1086
+ </UiSheetContent>
1087
+ </UiSheet>
1088
+ `,
1089
+ };
1090
+ }
1091
+
1092
+ /**
1093
+ * Opening the sheet from its trigger and dismissing it three ways — the footer
1094
+ * button, the built-in X, and the overlay — each handing focus back to the
1095
+ * trigger. Hidden test-only story.
1096
+ */
1097
+ export const PointerInteraction: Story = {
1098
+ name: 'test - Pointer Interaction',
1099
+ tags: ['!dev', '!autodocs'],
1100
+ parameters: {
1101
+ // The sheet opens and focus moves during the play function.
1102
+ chromatic: { disableSnapshot: true },
1103
+ docs: {
1104
+ description: {
1105
+ story:
1106
+ 'Click the trigger to open the sheet, then dismiss it with the footer button, the X control, or the overlay.',
1107
+ },
1108
+ },
1109
+ },
1110
+ render: renderTestSheet,
1111
+ play: async ({ canvasElement, step }) => {
1112
+ // Scenario (UiSheet): a pointer user opens the panel from the trigger and
1113
+ // closes it each of the three ways the sheet offers, landing back on the
1114
+ // trigger they started from every time.
1115
+ onUpdateOpen.mockClear();
1116
+ const canvas = within(canvasElement);
1117
+ const body = within(document.body);
1118
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
1119
+
1120
+ await step('interaction: the trigger opens the sheet', async () => {
1121
+ await userEvent.click(trigger);
1122
+ await expectOpenSheet(body);
1123
+ await expect(onUpdateOpen).toHaveBeenCalledWith(true);
1124
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1125
+ });
1126
+
1127
+ await step(
1128
+ 'interaction: the footer close control dismisses the sheet and restores focus',
1129
+ async () => {
1130
+ await userEvent.click(body.getByRole('button', { name: 'Done' }));
1131
+ await expectClosedSheet(body);
1132
+ await expect(onUpdateOpen).toHaveBeenCalledWith(false);
1133
+ await waitFor(async () => {
1134
+ await expect(trigger).toHaveFocus();
1135
+ });
1136
+ },
1137
+ );
1138
+
1139
+ await step(
1140
+ 'interaction: the built-in X control dismisses the sheet and restores focus',
1141
+ async () => {
1142
+ await userEvent.click(trigger);
1143
+ await expectOpenSheet(body);
1144
+ await userEvent.click(
1145
+ body.getByRole('button', { name: 'Close sheet' }),
1146
+ );
1147
+ await expectClosedSheet(body);
1148
+ await waitFor(async () => {
1149
+ await expect(trigger).toHaveFocus();
1150
+ });
1151
+ },
1152
+ );
1153
+
1154
+ await step(
1155
+ 'interaction: clicking the overlay dismisses the sheet and returns focus to the trigger (WCAG 2.4.3)',
1156
+ async () => {
1157
+ onUpdateOpen.mockClear();
1158
+ await userEvent.click(trigger);
1159
+ await expectOpenSheet(body);
1160
+
1161
+ await userEvent.click(getSheetOverlay());
1162
+ await expectClosedSheet(body);
1163
+ await expect(onUpdateOpen).toHaveBeenCalledWith(false);
1164
+ await waitFor(async () => {
1165
+ await expect(trigger).toHaveFocus();
1166
+ });
1167
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
1168
+ },
1169
+ );
1170
+ },
1171
+ };
1172
+
1173
+ /**
1174
+ * Reaching the sheet, staying inside its focus trap, and dismissing it without
1175
+ * a pointer. Hidden test-only story.
1176
+ */
1177
+ export const KeyboardNavigation: Story = {
1178
+ name: 'test - Keyboard Navigation',
1179
+ tags: ['!dev', '!autodocs'],
1180
+ parameters: {
1181
+ // Focus moves and the sheet opens during the play function.
1182
+ chromatic: { disableSnapshot: true },
1183
+ docs: {
1184
+ description: {
1185
+ story:
1186
+ 'Press `Tab` to focus the trigger, `Enter` to open, `Tab` to move inside, and `Escape` to dismiss.',
1187
+ },
1188
+ },
1189
+ },
1190
+ render: renderTestSheet,
1191
+ play: async ({ canvasElement, step }) => {
1192
+ // Scenario (UiSheet): a keyboard user tabs to the trigger, opens the panel
1193
+ // with Enter, finds focus moved inside and held there across both close
1194
+ // controls, dismisses with Escape, and gets focus back on the trigger.
1195
+ onUpdateOpen.mockClear();
1196
+ onEscapeKeyDown.mockClear();
1197
+ const canvas = within(canvasElement);
1198
+ const body = within(document.body);
1199
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
1200
+
1201
+ await step(
1202
+ 'keyboard: the trigger is reachable via Tab (WCAG 2.1.1)',
1203
+ async () => {
1204
+ await userEvent.tab();
1205
+ await expect(trigger).toHaveFocus();
1206
+ },
1207
+ );
1208
+
1209
+ await step(
1210
+ 'keyboard: Enter opens the sheet and moves focus inside it',
1211
+ async () => {
1212
+ await userEvent.keyboard('{Enter}');
1213
+ const sheet = await expectOpenSheet(body);
1214
+ await waitFor(async () => {
1215
+ await expect(sheet.contains(document.activeElement)).toBe(true);
1216
+ });
1217
+ },
1218
+ );
1219
+
1220
+ await step(
1221
+ 'keyboard: Tab cycles the sheet controls without escaping the trap (WCAG 2.4.3)',
1222
+ async () => {
1223
+ const sheet = body.getByRole('dialog');
1224
+ for (let press = 0; press < 3; press += 1) {
1225
+ await userEvent.tab();
1226
+ await expect(sheet.contains(document.activeElement)).toBe(true);
1227
+ }
1228
+ },
1229
+ );
1230
+
1231
+ await step(
1232
+ 'keyboard: Escape dismisses the sheet and restores focus to the trigger (WCAG 2.1.2)',
1233
+ async () => {
1234
+ await userEvent.keyboard('{Escape}');
1235
+ await expect(onEscapeKeyDown).toHaveBeenCalled();
1236
+ await expectClosedSheet(body);
1237
+ await waitFor(async () => {
1238
+ await expect(trigger).toHaveFocus();
1239
+ });
1240
+ },
1241
+ );
1242
+
1243
+ await step(
1244
+ 'keyboard: Space also opens the sheet from the trigger',
1245
+ async () => {
1246
+ await userEvent.keyboard(' ');
1247
+ await expectOpenSheet(body);
1248
+ await userEvent.keyboard('{Escape}');
1249
+ await expectClosedSheet(body);
1250
+ },
1251
+ );
1252
+ },
1253
+ };
1254
+
1255
+ /**
1256
+ * Screen-reader semantics: the open panel is a dialog named by its title and
1257
+ * described by its supporting text, with distinctly labelled close controls
1258
+ * (WCAG 4.1.2). Hidden test-only story.
1259
+ */
1260
+ export const ScreenReader: Story = {
1261
+ name: 'test - Screen Reader',
1262
+ tags: ['!dev', '!autodocs'],
1263
+ parameters: {
1264
+ // The sheet opens and focus moves during the play function.
1265
+ chromatic: { disableSnapshot: true },
1266
+ docs: {
1267
+ description: {
1268
+ story:
1269
+ 'Verifies the dialog role, accessible name, description, and control labels that assistive technology announces.',
1270
+ },
1271
+ },
1272
+ },
1273
+ render: renderTestSheet,
1274
+ play: async ({ canvasElement, step }) => {
1275
+ // Scenario (UiSheet): assistive tech reads the panel as a dialog named by
1276
+ // its title, hears the description, and can tell the two close controls
1277
+ // apart by name.
1278
+ const canvas = within(canvasElement);
1279
+ const body = within(document.body);
1280
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
1281
+
1282
+ await userEvent.click(trigger);
1283
+ const sheet = await expectOpenSheet(body);
1284
+
1285
+ await step(
1286
+ 'screen-reader: the panel exposes a dialog role named by its title (WCAG 4.1.2)',
1287
+ async () => {
1288
+ await expect(sheet).toHaveAttribute('role', 'dialog');
1289
+ await expect(sheet).toHaveAccessibleName('Sheet title');
1290
+ },
1291
+ );
1292
+
1293
+ await step(
1294
+ 'screen-reader: the panel is described by its supporting text (WCAG 4.1.2)',
1295
+ async () => {
1296
+ await expect(sheet).toHaveAccessibleDescription(
1297
+ 'A slide-out panel for supplementary content.',
1298
+ );
1299
+ },
1300
+ );
1301
+
1302
+ await step(
1303
+ 'screen-reader: the trigger announces the expanded sheet it controls',
1304
+ async () => {
1305
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1306
+ await expect(trigger).toHaveAttribute('aria-controls', sheet.id);
1307
+ },
1308
+ );
1309
+
1310
+ await step(
1311
+ 'screen-reader: both close controls expose distinct accessible names (WCAG 4.1.2)',
1312
+ async () => {
1313
+ await expect(
1314
+ body.getByRole('button', { name: 'Close sheet' }),
1315
+ ).toHaveAccessibleName('Close sheet');
1316
+ await expect(
1317
+ body.getByRole('button', { name: 'Done' }),
1318
+ ).toHaveAccessibleName('Done');
1319
+ },
1320
+ );
1321
+
1322
+ await userEvent.keyboard('{Escape}');
1323
+ await expectClosedSheet(body);
1324
+ },
1325
+ };
1326
+
1327
+ /**
1328
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1329
+ * try 400% reflow (WCAG 1.4.10); the panel must stay readable and operable.
1330
+ * Hidden test-only story.
1331
+ */
1332
+ export const ZoomMagnification: Story = {
1333
+ name: 'test - Zoom Magnification',
1334
+ tags: ['!dev', '!autodocs'],
1335
+ globals: { zoom: '200' },
1336
+ parameters: {
1337
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
1338
+ // already covers magnified snapshots, so skip this one.
1339
+ chromatic: { disableSnapshot: true },
1340
+ docs: {
1341
+ description: {
1342
+ story:
1343
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1344
+ },
1345
+ },
1346
+ },
1347
+ render: renderTestSheet,
1348
+ play: async ({ canvasElement, step }) => {
1349
+ // Scenario (UiSheet): at 200% page zoom the trigger stays named, the panel
1350
+ // still opens with its title and description on screen, and it closes.
1351
+ onUpdateOpen.mockClear();
1352
+ const canvas = within(canvasElement);
1353
+ const body = within(document.body);
1354
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
1355
+
1356
+ await step(
1357
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1358
+ async () => {
1359
+ await expect(document.documentElement.style.zoom).toBe('200%');
1360
+ },
1361
+ );
1362
+
1363
+ await step(
1364
+ 'zoom: the trigger stays visible with its accessible name',
1365
+ async () => {
1366
+ await expect(trigger).toBeVisible();
1367
+ await expect(trigger).toHaveAccessibleName('Open Sheet');
1368
+ },
1369
+ );
1370
+
1371
+ await step(
1372
+ 'zoom: the sheet opens and stays readable when magnified',
1373
+ async () => {
1374
+ await userEvent.click(trigger);
1375
+ const sheet = await expectOpenSheet(body);
1376
+ await expect(sheet).toHaveAccessibleName('Sheet title');
1377
+ await expect(body.getByText('Sheet title')).toBeVisible();
1378
+ await expect(
1379
+ body.getByText('A slide-out panel for supplementary content.'),
1380
+ ).toBeVisible();
1381
+
1382
+ const { top, bottom, right } = sheet.getBoundingClientRect();
1383
+ await expect(top).toBeGreaterThanOrEqual(0);
1384
+ await expect(bottom).toBeLessThanOrEqual(window.innerHeight + 1);
1385
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
1386
+ },
1387
+ );
1388
+
1389
+ await step('zoom: remains operable when magnified', async () => {
1390
+ await userEvent.click(body.getByRole('button', { name: 'Done' }));
1391
+ await expectClosedSheet(body);
1392
+ await expect(onUpdateOpen).toHaveBeenCalledWith(false);
1393
+ });
1394
+ },
1395
+ };
1396
+
1397
+ /**
1398
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1399
+ * toolbar. Stays operable, fits the viewport, and its controls meet the minimum
1400
+ * touch-target size (WCAG 2.5.8). Hidden test-only story.
1401
+ */
1402
+ export const MobileBreakpoint: Story = {
1403
+ name: 'test - Mobile Breakpoint',
1404
+ tags: ['!dev', '!autodocs'],
1405
+ globals: { mediaBreakpoint: 'reflow' },
1406
+ parameters: {
1407
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1408
+ chromatic: { disableSnapshot: true },
1409
+ docs: {
1410
+ description: {
1411
+ story:
1412
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1413
+ },
1414
+ },
1415
+ },
1416
+ render: renderTestSheet,
1417
+ play: async ({ canvasElement, step }) => {
1418
+ // Scenario (UiSheet): at the 320px mobile breakpoint the trigger opens the
1419
+ // panel, the panel fits the viewport, and every control is big enough to
1420
+ // tap.
1421
+ onUpdateOpen.mockClear();
1422
+ const canvas = within(canvasElement);
1423
+ const body = within(document.body);
1424
+ const trigger = canvas.getByRole('button', { name: 'Open Sheet' });
1425
+
1426
+ await step(
1427
+ 'mobile: the trigger stays operable at the 320px breakpoint',
1428
+ async () => {
1429
+ await expect(trigger).toBeVisible();
1430
+ await expect(trigger).toBeEnabled();
1431
+ await userEvent.click(trigger);
1432
+ await expectOpenSheet(body);
1433
+ },
1434
+ );
1435
+
1436
+ await step(
1437
+ 'mobile: the sheet fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
1438
+ async () => {
1439
+ const { left, right } = body
1440
+ .getByRole('dialog')
1441
+ .getBoundingClientRect();
1442
+ await expect(left).toBeGreaterThanOrEqual(0);
1443
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
1444
+ },
1445
+ );
1446
+
1447
+ await step(
1448
+ 'mobile: every control meets the minimum touch-target size (WCAG 2.5.8)',
1449
+ async () => {
1450
+ const controls = [
1451
+ trigger,
1452
+ body.getByRole('button', { name: 'Done' }),
1453
+ body.getByRole('button', { name: 'Close sheet' }),
1454
+ ];
1455
+
1456
+ for (const control of controls) {
1457
+ const { width, height } = control.getBoundingClientRect();
1458
+ await expect(width).toBeGreaterThanOrEqual(24);
1459
+ await expect(height).toBeGreaterThanOrEqual(24);
1460
+ }
1461
+ },
1462
+ );
1463
+
1464
+ // Close again so the end-of-play axe audit sees the resting state.
1465
+ await userEvent.keyboard('{Escape}');
1466
+ await expectClosedSheet(body);
1467
+ },
717
1468
  };