@aleph-alpha/ui-library 6.3.2 → 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.
Files changed (51) hide show
  1. package/config.js +2 -0
  2. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  3. package/dist/system/components/UiStepper/context.d.ts +8 -0
  4. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  5. package/dist/system/icons/story-sidebar-icons.json +7 -0
  6. package/dist/system/lib.js +14776 -14598
  7. package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
  8. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
  9. package/dist/system/story-sidebar-icons.json +7 -0
  10. package/package.json +1 -1
  11. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  12. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  13. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  14. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  15. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  16. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  17. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  18. package/src/components/UiFileUploadBox/types.ts +8 -5
  19. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  20. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  21. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  22. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  23. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
  24. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  25. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  26. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  27. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  28. package/src/components/UiStepper/UiStepper.vue +14 -1
  29. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  30. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  31. package/src/components/UiStepper/context.ts +10 -0
  32. package/src/components/core/calendar/Calendar.vue +234 -2
  33. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  34. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  35. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  36. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  37. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  38. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  39. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  40. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  41. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  42. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  43. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  44. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  45. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  46. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  47. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  48. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  49. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  50. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  51. package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { CalendarDate, getLocalTimeZone, today } from '@internationalized/date';
3
3
  import type { DateValue } from '@internationalized/date';
4
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
4
5
  import { ref } from 'vue';
5
6
  import UiCalendar from './UiCalendar.vue';
6
7
  import { UiIcon } from '../UiIcon';
@@ -112,6 +113,23 @@ export default meta;
112
113
 
113
114
  type Story = StoryObj<typeof UiCalendar>;
114
115
 
116
+ // `UiCalendar` emits `update:modelValue` when the selected date changes. Play
117
+ // functions bind this module-level spy via `@update:model-value` and
118
+ // `mockClear()` it at the start of each `play`.
119
+ const onUpdate = fn();
120
+
121
+ /**
122
+ * Returns the day cell triggers (role button) of the month grid.
123
+ * @param canvasElement Story root element.
124
+ */
125
+ function getDayCells(canvasElement: HTMLElement): HTMLElement[] {
126
+ return Array.from(
127
+ canvasElement.querySelectorAll<HTMLElement>(
128
+ '[data-slot="calendar-cell-trigger"]:not([data-outside-view])',
129
+ ),
130
+ );
131
+ }
132
+
115
133
  const defaultTemplateSource = `<script setup lang="ts">
116
134
  import type { DateValue } from '@aleph-alpha/ui-library'
117
135
  import { ref } from 'vue'
@@ -165,6 +183,54 @@ export const Default: Story = {
165
183
  },
166
184
  },
167
185
  },
186
+ play: async ({ canvasElement, step }) => {
187
+ // Scenario (UiCalendar): the resting month grid — assistive tech reads a
188
+ // labelled calendar whose day cells are buttons named by their full date,
189
+ // with a single roving tab stop. Non-mutating so the primary snapshot
190
+ // stays stable.
191
+ const canvas = within(canvasElement);
192
+
193
+ await step(
194
+ 'screen-reader: the calendar root exposes an accessible label (WCAG 4.1.2)',
195
+ async () => {
196
+ const root = canvasElement.querySelector('[data-slot="calendar"]');
197
+ await expect(root).toHaveAttribute('aria-label');
198
+ },
199
+ );
200
+
201
+ await step(
202
+ 'screen-reader: every day cell is a button named by its full date (WCAG 4.1.2)',
203
+ async () => {
204
+ const days = getDayCells(canvasElement);
205
+ await expect(days.length).toBeGreaterThanOrEqual(28);
206
+ for (const day of days) {
207
+ await expect(day).toHaveAccessibleName();
208
+ }
209
+ },
210
+ );
211
+
212
+ await step(
213
+ 'screen-reader: exactly one day is the tab stop (roving tabindex)',
214
+ async () => {
215
+ const tabStops = canvasElement.querySelectorAll(
216
+ '[data-slot="calendar-cell-trigger"][tabindex="0"]',
217
+ );
218
+ await expect(tabStops).toHaveLength(1);
219
+ },
220
+ );
221
+
222
+ await step(
223
+ 'interaction: month heading and page controls are exposed',
224
+ async () => {
225
+ await expect(
226
+ canvas.getByRole('button', { name: 'Previous page' }),
227
+ ).toBeVisible();
228
+ await expect(
229
+ canvas.getByRole('button', { name: 'Next page' }),
230
+ ).toBeVisible();
231
+ },
232
+ );
233
+ },
168
234
  };
169
235
 
170
236
  const withLayoutTemplateSource = `<script setup lang="ts">
@@ -326,6 +392,23 @@ export const DisabledWeekends: Story = {
326
392
  },
327
393
  },
328
394
  },
395
+ play: async ({ canvasElement, step }) => {
396
+ // Scenario (UiCalendar): weekend days are disabled — they announce their
397
+ // disabled state and clicking them does not select a date.
398
+ await step(
399
+ 'interaction: disabled dates expose aria-disabled and cannot be selected (WCAG 4.1.2)',
400
+ async () => {
401
+ const disabledDay = canvasElement.querySelector<HTMLElement>(
402
+ '[data-slot="calendar-cell-trigger"][data-disabled]:not([data-outside-view])',
403
+ );
404
+ await expect(disabledDay).not.toBeNull();
405
+ if (!disabledDay) throw new Error('No disabled day rendered');
406
+ await expect(disabledDay).toHaveAttribute('aria-disabled', 'true');
407
+ await userEvent.click(disabledDay);
408
+ await expect(canvasElement.querySelector('[data-selected]')).toBeNull();
409
+ },
410
+ );
411
+ },
329
412
  };
330
413
 
331
414
  const dateRangeTemplateSource = `<script setup lang="ts">
@@ -461,6 +544,29 @@ export const Disabled: Story = {
461
544
  },
462
545
  },
463
546
  },
547
+ play: async ({ canvasElement, step }) => {
548
+ // Scenario (UiCalendar): a fully disabled calendar — every day announces
549
+ // its disabled state and nothing inside the calendar is keyboard
550
+ // reachable.
551
+ await step(
552
+ 'interaction: every day exposes the disabled state (WCAG 4.1.2)',
553
+ async () => {
554
+ for (const day of getDayCells(canvasElement)) {
555
+ await expect(day).toHaveAttribute('aria-disabled', 'true');
556
+ }
557
+ },
558
+ );
559
+
560
+ await step(
561
+ 'keyboard: the disabled calendar is removed from the tab order (WCAG 2.1.1)',
562
+ async () => {
563
+ await userEvent.tab();
564
+ await expect(canvasElement.contains(document.activeElement)).toBe(
565
+ false,
566
+ );
567
+ },
568
+ );
569
+ },
464
570
  };
465
571
 
466
572
  const readonlyTemplateSource = `<script setup lang="ts">
@@ -504,6 +610,31 @@ export const Readonly: Story = {
504
610
  },
505
611
  },
506
612
  },
613
+ play: async ({ canvasElement, step }) => {
614
+ // Scenario (UiCalendar): a read-only calendar keeps its selection even
615
+ // when the user clicks another day. Ends unchanged, so the snapshot is
616
+ // stable.
617
+ await step(
618
+ 'interaction: clicking another day does not change the selection in read-only mode',
619
+ async () => {
620
+ const selected = canvasElement.querySelector<HTMLElement>(
621
+ '[data-slot="calendar-cell-trigger"][data-selected]',
622
+ );
623
+ await expect(selected).not.toBeNull();
624
+ if (!selected) throw new Error('No selected day rendered');
625
+ const otherDay = getDayCells(canvasElement).find(
626
+ (day) =>
627
+ !day.hasAttribute('data-selected') &&
628
+ !day.hasAttribute('data-disabled'),
629
+ );
630
+ await expect(otherDay).toBeDefined();
631
+ if (!otherDay) throw new Error('No other enabled day rendered');
632
+ await userEvent.click(otherDay);
633
+ await expect(otherDay).not.toHaveAttribute('data-selected');
634
+ await expect(selected).toHaveAttribute('data-selected');
635
+ },
636
+ );
637
+ },
507
638
  };
508
639
 
509
640
  const multipleSelectionTemplateSource = `<script setup lang="ts">
@@ -777,3 +908,606 @@ export const CustomHeadingAndCellSize: Story = {
777
908
  },
778
909
  },
779
910
  };
911
+
912
+ /**
913
+ * Accessibility guidance for calendars: today and selection distinguishable
914
+ * without colour, distinct selected/hover/focus treatments, visible focus on
915
+ * selected days, comfortable day targets, unavailable days marked beyond low
916
+ * contrast, and a stable grid size — shown side by side in the default and
917
+ * accessible themes.
918
+ */
919
+ export const Accessibility: Story = {
920
+ tags: ['!autodocs'],
921
+ parameters: {
922
+ a11y: { test: 'off' },
923
+ chromatic: { disableSnapshot: true },
924
+ docs: {
925
+ canvas: {
926
+ sourceState: 'none',
927
+ },
928
+ },
929
+ },
930
+ render: () => ({
931
+ components: { UiCalendar },
932
+ setup() {
933
+ const defaultDate = ref<DateValue>(new CalendarDate(2026, 1, 10));
934
+ const accessibleDate = ref<DateValue>(new CalendarDate(2026, 1, 10));
935
+ const placeholder = new CalendarDate(2026, 1, 1);
936
+ return { defaultDate, accessibleDate, placeholder };
937
+ },
938
+ template: `
939
+ <section class="flex flex-col gap-6 p-4">
940
+ <div>
941
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
942
+ Accessibility
943
+ </h2>
944
+ </div>
945
+
946
+ <div class="flex flex-col gap-6">
947
+ <div class="flex flex-col gap-2">
948
+ <h3 class="body-16-medium text-content-on-surface-primary">
949
+ Requirements
950
+ </h3>
951
+ <ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
952
+ <li>
953
+ Today and the selected day differ in shape as well as fill, so
954
+ both survive without colour
955
+ </li>
956
+ <li>
957
+ Selected, hover and focus use three distinguishable treatments,
958
+ not variations of one
959
+ </li>
960
+ <li>
961
+ Focus stays visible on a day even when that day is selected or
962
+ inside a range
963
+ </li>
964
+ <li>
965
+ Day buttons are a comfortable target at the size chosen,
966
+ including the smallest one used
967
+ </li>
968
+ <li>
969
+ Unavailable days carry a visible treatment beyond low contrast
970
+ </li>
971
+ <li>
972
+ The grid keeps a stable size between months, so the page does
973
+ not shift under the header
974
+ </li>
975
+ </ul>
976
+ </div>
977
+
978
+ <div class="flex flex-col gap-2">
979
+ <h3 class="body-16-medium text-content-on-surface-primary">
980
+ Enable accessibility theme
981
+ </h3>
982
+ <p class="body-16-regular text-content-on-surface-primary">
983
+ When accessibility is required, enable our accessibility theme.
984
+ This increases contrast and ensures there are no color contrast
985
+ issues.
986
+ </p>
987
+ </div>
988
+ </div>
989
+
990
+ <div class="grid gap-4 md:grid-cols-2">
991
+ <div class="flex flex-col gap-3">
992
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
993
+ Default
994
+ </h3>
995
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
996
+ <UiCalendar
997
+ v-model="defaultDate"
998
+ :default-placeholder="placeholder"
999
+ fixed-weeks
1000
+ />
1001
+ </div>
1002
+ </div>
1003
+
1004
+ <div class="accessible-theme flex flex-col gap-3">
1005
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1006
+ Accessible
1007
+ </h3>
1008
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1009
+ <UiCalendar
1010
+ v-model="accessibleDate"
1011
+ :default-placeholder="placeholder"
1012
+ fixed-weeks
1013
+ />
1014
+ </div>
1015
+ </div>
1016
+ </div>
1017
+ </section>
1018
+ `,
1019
+ }),
1020
+ };
1021
+
1022
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
1023
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
1024
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
1025
+ // in the automated report under their `test - …` name. `name`/`tags` must be
1026
+ // literal properties so Storybook's static CSF indexer can read them.
1027
+
1028
+ // Shared render for the test-only scenarios: a fixed June 2026 view (so the
1029
+ // assertions never depend on the real date) with the 16th disabled, covering
1030
+ // selection, the disabled-date guard, and arrow/Home/End/PageUp/PageDown
1031
+ // navigation from June 15 (a Monday).
1032
+ function renderTestCalendar(options: { selected?: boolean } = {}) {
1033
+ return () => ({
1034
+ components: { UiCalendar },
1035
+ setup() {
1036
+ const date = ref<DateValue | undefined>(
1037
+ options.selected ? new CalendarDate(2026, 6, 15) : undefined,
1038
+ );
1039
+ const placeholder = new CalendarDate(2026, 6, 15);
1040
+ /**
1041
+ * Disables the 16th of every month.
1042
+ * @param d Date to check.
1043
+ */
1044
+ const isDateDisabled = (d: DateValue) => d.day === 16;
1045
+ return { date, placeholder, isDateDisabled, onUpdate };
1046
+ },
1047
+ template: `
1048
+ <UiCalendar
1049
+ v-model="date"
1050
+ :default-placeholder="placeholder"
1051
+ :is-date-disabled="isDateDisabled"
1052
+ calendar-label="Event date"
1053
+ @update:model-value="onUpdate"
1054
+ />
1055
+ `,
1056
+ });
1057
+ }
1058
+
1059
+ /**
1060
+ * Selection behaviour: clicking a day selects it and emits
1061
+ * `update:modelValue`, clicking another day moves the selection, clicking the
1062
+ * selected day deselects it, and a disabled date cannot be selected.
1063
+ */
1064
+ export const SelectionBehavior: Story = {
1065
+ name: 'test - Selection Behavior',
1066
+ tags: ['!dev', '!autodocs'],
1067
+ parameters: {
1068
+ chromatic: { disableSnapshot: true },
1069
+ docs: {
1070
+ description: {
1071
+ story:
1072
+ 'Select days with the pointer and confirm the disabled-date guard holds.',
1073
+ },
1074
+ },
1075
+ },
1076
+ render: renderTestCalendar(),
1077
+ play: async ({ canvasElement, step }) => {
1078
+ // Scenario (UiCalendar): a pointer user selects a day, moves the
1079
+ // selection, deselects, and cannot select the disabled 16th.
1080
+ onUpdate.mockClear();
1081
+ const canvas = within(canvasElement);
1082
+ const day15 = canvas.getByRole('button', { name: /June 15, 2026/ });
1083
+ const day16 = canvas.getByRole('button', { name: /June 16, 2026/ });
1084
+ const day17 = canvas.getByRole('button', { name: /June 17, 2026/ });
1085
+
1086
+ await step(
1087
+ 'interaction: selecting a day updates the value and emits update:modelValue',
1088
+ async () => {
1089
+ await userEvent.click(day15);
1090
+ await expect(day15).toHaveAttribute('data-selected');
1091
+ await expect(day15.closest('td')).toHaveAttribute(
1092
+ 'aria-selected',
1093
+ 'true',
1094
+ );
1095
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-15');
1096
+ },
1097
+ );
1098
+
1099
+ await step(
1100
+ 'interaction: selecting another day moves the selection',
1101
+ async () => {
1102
+ await userEvent.click(day17);
1103
+ await expect(day17).toHaveAttribute('data-selected');
1104
+ await expect(day15).not.toHaveAttribute('data-selected');
1105
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-17');
1106
+ },
1107
+ );
1108
+
1109
+ await step(
1110
+ 'interaction: clicking the selected day deselects it',
1111
+ async () => {
1112
+ await userEvent.click(day17);
1113
+ await expect(day17).not.toHaveAttribute('data-selected');
1114
+ await expect(onUpdate.mock.lastCall?.[0]).toBeUndefined();
1115
+ },
1116
+ );
1117
+
1118
+ await step(
1119
+ 'interaction: a disabled date cannot be selected (WCAG 4.1.2)',
1120
+ async () => {
1121
+ onUpdate.mockClear();
1122
+ await expect(day16).toHaveAttribute('aria-disabled', 'true');
1123
+ await userEvent.click(day16);
1124
+ await expect(day16).not.toHaveAttribute('data-selected');
1125
+ await expect(onUpdate).not.toHaveBeenCalled();
1126
+ },
1127
+ );
1128
+ },
1129
+ };
1130
+
1131
+ /**
1132
+ * `UiCalendar` is fully keyboard operable: `Tab` reaches the grid as a single
1133
+ * stop, arrow keys move by day and week (skipping disabled dates),
1134
+ * `Home`/`End` jump to the first/last day of the week, `PageUp`/`PageDown`
1135
+ * switch months (`Shift` switches years), and `Enter`/`Space` select the
1136
+ * focused day.
1137
+ */
1138
+ export const KeyboardNavigation: Story = {
1139
+ name: 'test - Keyboard Navigation',
1140
+ tags: ['!dev', '!autodocs'],
1141
+ parameters: {
1142
+ // Focus moves during the play function; skip the visual snapshot so the
1143
+ // focus ring doesn't register as a Chromatic diff.
1144
+ chromatic: { disableSnapshot: true },
1145
+ docs: {
1146
+ description: {
1147
+ story:
1148
+ 'Press `Tab` to reach the grid, arrow keys / `Home` / `End` / `PageUp` / `PageDown` (with `Shift` for years) to move, and `Enter` or `Space` to select.',
1149
+ },
1150
+ },
1151
+ },
1152
+ render: renderTestCalendar(),
1153
+ play: async ({ canvasElement, step }) => {
1154
+ // Scenario (UiCalendar): a keyboard user tabs past the page controls into
1155
+ // the grid, moves with arrows (the disabled 16th is skipped), jumps with
1156
+ // Home/End, pages between months with PageUp/PageDown, and selects with
1157
+ // Enter and Space.
1158
+ onUpdate.mockClear();
1159
+ const canvas = within(canvasElement);
1160
+
1161
+ await step(
1162
+ 'keyboard: Tab reaches the day grid as a single stop (WCAG 2.1.1 Keyboard)',
1163
+ async () => {
1164
+ await userEvent.tab();
1165
+ await expect(
1166
+ canvas.getByRole('button', { name: 'Previous page' }),
1167
+ ).toHaveFocus();
1168
+ await userEvent.tab();
1169
+ await expect(
1170
+ canvas.getByRole('button', { name: 'Next page' }),
1171
+ ).toHaveFocus();
1172
+ await userEvent.tab();
1173
+ await expect(
1174
+ canvas.getByRole('button', { name: /June 15, 2026/ }),
1175
+ ).toHaveFocus();
1176
+ },
1177
+ );
1178
+
1179
+ await step(
1180
+ 'keyboard: arrow keys move focus by day and week, skipping disabled dates',
1181
+ async () => {
1182
+ await userEvent.keyboard('{ArrowRight}');
1183
+ await expect(
1184
+ canvas.getByRole('button', { name: /June 17, 2026/ }),
1185
+ ).toHaveFocus();
1186
+ await userEvent.keyboard('{ArrowDown}');
1187
+ await expect(
1188
+ canvas.getByRole('button', { name: /June 24, 2026/ }),
1189
+ ).toHaveFocus();
1190
+ await userEvent.keyboard('{ArrowUp}');
1191
+ await expect(
1192
+ canvas.getByRole('button', { name: /June 17, 2026/ }),
1193
+ ).toHaveFocus();
1194
+ await userEvent.keyboard('{ArrowLeft}');
1195
+ await expect(
1196
+ canvas.getByRole('button', { name: /June 15, 2026/ }),
1197
+ ).toHaveFocus();
1198
+ },
1199
+ );
1200
+
1201
+ await step(
1202
+ 'keyboard: Home and End jump to the first and last day of the week (WCAG 2.4.3)',
1203
+ async () => {
1204
+ await userEvent.keyboard('{Home}');
1205
+ await expect(
1206
+ canvas.getByRole('button', { name: /June 14, 2026/ }),
1207
+ ).toHaveFocus();
1208
+ await userEvent.keyboard('{End}');
1209
+ await expect(
1210
+ canvas.getByRole('button', { name: /June 20, 2026/ }),
1211
+ ).toHaveFocus();
1212
+ },
1213
+ );
1214
+
1215
+ await step(
1216
+ 'keyboard: PageDown and PageUp move to the same day in the next and previous month',
1217
+ async () => {
1218
+ await userEvent.keyboard('{PageDown}');
1219
+ await waitFor(async () => {
1220
+ await expect(
1221
+ canvas.getByRole('button', { name: /July 20, 2026/ }),
1222
+ ).toHaveFocus();
1223
+ });
1224
+ await expect(canvas.getByText('July 2026')).toBeVisible();
1225
+ await userEvent.keyboard('{PageUp}');
1226
+ await waitFor(async () => {
1227
+ await expect(
1228
+ canvas.getByRole('button', { name: /June 20, 2026/ }),
1229
+ ).toHaveFocus();
1230
+ });
1231
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1232
+ },
1233
+ );
1234
+
1235
+ await step(
1236
+ 'keyboard: Shift+PageDown and Shift+PageUp move to the same day in the next and previous year',
1237
+ async () => {
1238
+ await userEvent.keyboard('{Shift>}{PageDown}{/Shift}');
1239
+ await waitFor(async () => {
1240
+ await expect(
1241
+ canvas.getByRole('button', { name: /June 20, 2027/ }),
1242
+ ).toHaveFocus();
1243
+ });
1244
+ await expect(canvas.getByText('June 2027')).toBeVisible();
1245
+ await userEvent.keyboard('{Shift>}{PageUp}{/Shift}');
1246
+ await waitFor(async () => {
1247
+ await expect(
1248
+ canvas.getByRole('button', { name: /June 20, 2026/ }),
1249
+ ).toHaveFocus();
1250
+ });
1251
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1252
+ },
1253
+ );
1254
+
1255
+ await step('keyboard: Enter selects the focused day', async () => {
1256
+ await userEvent.keyboard('{Enter}');
1257
+ await expect(
1258
+ canvas.getByRole('button', { name: /June 20, 2026/ }),
1259
+ ).toHaveAttribute('data-selected');
1260
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-20');
1261
+ });
1262
+
1263
+ await step('keyboard: Space selects the focused day', async () => {
1264
+ await userEvent.keyboard('{ArrowLeft}');
1265
+ await userEvent.keyboard(' ');
1266
+ await expect(
1267
+ canvas.getByRole('button', { name: /June 19, 2026/ }),
1268
+ ).toHaveAttribute('data-selected');
1269
+ await expect(
1270
+ canvas.getByRole('button', { name: /June 20, 2026/ }),
1271
+ ).not.toHaveAttribute('data-selected');
1272
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-19');
1273
+ });
1274
+
1275
+ await step(
1276
+ 'keyboard: Home and End reach enabled days from the adjacent month in boundary rows',
1277
+ async () => {
1278
+ // Move to June 1, whose row starts with May 31 — a visible,
1279
+ // selectable outside-view day (disableDaysOutsideCurrentView is off
1280
+ // by default).
1281
+ await userEvent.keyboard('{Home}'); // June 14
1282
+ await userEvent.keyboard('{ArrowUp}'); // June 7
1283
+ await userEvent.keyboard('{ArrowRight}'); // June 8
1284
+ await userEvent.keyboard('{ArrowUp}'); // June 1
1285
+ await expect(
1286
+ canvas.getByRole('button', { name: /June 1, 2026/ }),
1287
+ ).toHaveFocus();
1288
+
1289
+ // Home targets May 31. Outside-view cells are never focus targets in
1290
+ // reka-ui, so the view flips to May and focuses the date there — the
1291
+ // same behaviour ArrowLeft has at a month boundary.
1292
+ await userEvent.keyboard('{Home}');
1293
+ await waitFor(async () => {
1294
+ await expect(
1295
+ canvas.getByRole('button', { name: /May 31, 2026/ }),
1296
+ ).toHaveFocus();
1297
+ });
1298
+ await expect(canvas.getByText('May 2026')).toBeVisible();
1299
+
1300
+ // End from May 31 targets June 6 at the end of the same row,
1301
+ // flipping the view back to June.
1302
+ await userEvent.keyboard('{End}');
1303
+ await waitFor(async () => {
1304
+ await expect(
1305
+ canvas.getByRole('button', { name: /June 6, 2026/ }),
1306
+ ).toHaveFocus();
1307
+ });
1308
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1309
+ },
1310
+ );
1311
+ },
1312
+ };
1313
+
1314
+ /**
1315
+ * Screen-reader semantics: the calendar exposes an accessible label, day
1316
+ * cells are buttons named by their full date inside gridcells, the selected
1317
+ * day is announced via aria-selected, the focused day is the single tab stop,
1318
+ * and disabled dates announce aria-disabled.
1319
+ */
1320
+ export const ScreenReader: Story = {
1321
+ name: 'test - Screen Reader',
1322
+ tags: ['!dev', '!autodocs'],
1323
+ parameters: {
1324
+ chromatic: { disableSnapshot: true },
1325
+ docs: {
1326
+ description: {
1327
+ story:
1328
+ 'Verifies the roles, names, and states that assistive technology announces.',
1329
+ },
1330
+ },
1331
+ },
1332
+ render: renderTestCalendar({ selected: true }),
1333
+ play: async ({ canvasElement, step }) => {
1334
+ // Scenario (UiCalendar): assistive tech reads a labelled calendar, hears
1335
+ // each day's full date, is told which day is selected and which is
1336
+ // unavailable, and the announced state follows a new selection.
1337
+ const canvas = within(canvasElement);
1338
+ const day15 = canvas.getByRole('button', { name: /June 15, 2026/ });
1339
+ const day16 = canvas.getByRole('button', { name: /June 16, 2026/ });
1340
+ const day17 = canvas.getByRole('button', { name: /June 17, 2026/ });
1341
+
1342
+ await step(
1343
+ 'screen-reader: the calendar exposes its accessible label (WCAG 4.1.2)',
1344
+ async () => {
1345
+ const root = canvasElement.querySelector('[data-slot="calendar"]');
1346
+ await expect(root?.getAttribute('aria-label')).toContain('Event date');
1347
+ },
1348
+ );
1349
+
1350
+ await step(
1351
+ 'screen-reader: day cells are buttons named by their full date inside gridcells (WCAG 1.3.1 / 4.1.2)',
1352
+ async () => {
1353
+ await expect(day15).toHaveAccessibleName();
1354
+ await expect(day15.closest('td')).toHaveAttribute('role', 'gridcell');
1355
+ },
1356
+ );
1357
+
1358
+ await step(
1359
+ 'screen-reader: the selected day is announced via aria-selected (WCAG 4.1.2)',
1360
+ async () => {
1361
+ await expect(day15.closest('td')).toHaveAttribute(
1362
+ 'aria-selected',
1363
+ 'true',
1364
+ );
1365
+ await expect(day17.closest('td')).not.toHaveAttribute('aria-selected');
1366
+ },
1367
+ );
1368
+
1369
+ await step(
1370
+ 'screen-reader: the focused day is the single tab stop (roving tabindex)',
1371
+ async () => {
1372
+ const tabStops = canvasElement.querySelectorAll(
1373
+ '[data-slot="calendar-cell-trigger"][tabindex="0"]',
1374
+ );
1375
+ await expect(tabStops).toHaveLength(1);
1376
+ await expect(tabStops[0]).toBe(day15);
1377
+ },
1378
+ );
1379
+
1380
+ await step(
1381
+ 'screen-reader: disabled dates announce aria-disabled (WCAG 4.1.2)',
1382
+ async () => {
1383
+ await expect(day16).toHaveAttribute('aria-disabled', 'true');
1384
+ },
1385
+ );
1386
+
1387
+ await step(
1388
+ 'screen-reader: the announced selection follows a new choice (WCAG 4.1.2)',
1389
+ async () => {
1390
+ await userEvent.click(day17);
1391
+ await expect(day17.closest('td')).toHaveAttribute(
1392
+ 'aria-selected',
1393
+ 'true',
1394
+ );
1395
+ await expect(day15.closest('td')).not.toHaveAttribute('aria-selected');
1396
+ },
1397
+ );
1398
+ },
1399
+ };
1400
+
1401
+ /**
1402
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1403
+ * try 400% reflow (WCAG 1.4.10); the calendar must stay visible, readable,
1404
+ * and operable.
1405
+ */
1406
+ export const ZoomMagnification: Story = {
1407
+ name: 'test - Zoom Magnification',
1408
+ tags: ['!dev', '!autodocs'],
1409
+ globals: { zoom: '200' },
1410
+ parameters: {
1411
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
1412
+ // already covers magnified snapshots, so skip this one.
1413
+ chromatic: { disableSnapshot: true },
1414
+ docs: {
1415
+ description: {
1416
+ story:
1417
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1418
+ },
1419
+ },
1420
+ },
1421
+ render: renderTestCalendar(),
1422
+ play: async ({ canvasElement, step }) => {
1423
+ // Scenario (UiCalendar): at 200% page zoom the month heading and every
1424
+ // day stay visible with their labels, and a day can still be selected.
1425
+ onUpdate.mockClear();
1426
+ const canvas = within(canvasElement);
1427
+
1428
+ await step(
1429
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1430
+ async () => {
1431
+ await expect(document.documentElement.style.zoom).toBe('200%');
1432
+ },
1433
+ );
1434
+
1435
+ await step(
1436
+ 'zoom: the month heading and every day stay visible when magnified',
1437
+ async () => {
1438
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1439
+ for (const day of getDayCells(canvasElement)) {
1440
+ await expect(day).toBeVisible();
1441
+ await expect(day).toHaveAccessibleName();
1442
+ }
1443
+ },
1444
+ );
1445
+
1446
+ await step('zoom: remains operable when magnified', async () => {
1447
+ const day20 = canvas.getByRole('button', { name: /June 20, 2026/ });
1448
+ await userEvent.click(day20);
1449
+ await expect(day20).toHaveAttribute('data-selected');
1450
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-20');
1451
+ });
1452
+ },
1453
+ };
1454
+
1455
+ /**
1456
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1457
+ * toolbar. The calendar stays usable and day cells meet the minimum
1458
+ * touch-target size (WCAG 2.5.8).
1459
+ */
1460
+ export const MobileBreakpoint: Story = {
1461
+ name: 'test - Mobile Breakpoint',
1462
+ tags: ['!dev', '!autodocs'],
1463
+ globals: { mediaBreakpoint: 'reflow' },
1464
+ parameters: {
1465
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1466
+ chromatic: { disableSnapshot: true },
1467
+ docs: {
1468
+ description: {
1469
+ story:
1470
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1471
+ },
1472
+ },
1473
+ },
1474
+ render: renderTestCalendar(),
1475
+ play: async ({ canvasElement, step }) => {
1476
+ // Scenario (UiCalendar): at the 320px mobile breakpoint the calendar fits
1477
+ // the viewport, every day cell is big enough to tap, and a tap still
1478
+ // selects.
1479
+ onUpdate.mockClear();
1480
+ const canvas = within(canvasElement);
1481
+
1482
+ await step(
1483
+ 'mobile: the calendar fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
1484
+ async () => {
1485
+ await expect(canvasElement.scrollWidth).toBeLessThanOrEqual(
1486
+ window.innerWidth,
1487
+ );
1488
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1489
+ },
1490
+ );
1491
+
1492
+ await step(
1493
+ 'mobile: day cells meet the minimum touch-target size (WCAG 2.5.8)',
1494
+ async () => {
1495
+ for (const day of getDayCells(canvasElement)) {
1496
+ const { width, height } = day.getBoundingClientRect();
1497
+ await expect(width).toBeGreaterThanOrEqual(24);
1498
+ await expect(height).toBeGreaterThanOrEqual(24);
1499
+ }
1500
+ },
1501
+ );
1502
+
1503
+ await step(
1504
+ 'mobile: tapping a day selects it at the 320px breakpoint',
1505
+ async () => {
1506
+ const day20 = canvas.getByRole('button', { name: /June 20, 2026/ });
1507
+ await userEvent.click(day20);
1508
+ await expect(day20).toHaveAttribute('data-selected');
1509
+ await expect(String(onUpdate.mock.lastCall?.[0])).toBe('2026-06-20');
1510
+ },
1511
+ );
1512
+ },
1513
+ };