@aleph-alpha/ui-library 6.3.3 → 6.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  2. package/dist/system/components/UiStepper/context.d.ts +8 -0
  3. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  4. package/dist/system/icons/story-sidebar-icons.json +7 -0
  5. package/dist/system/lib.js +14776 -14598
  6. package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
  7. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
  8. package/dist/system/story-sidebar-icons.json +7 -0
  9. package/package.json +1 -1
  10. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  11. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  12. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  13. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  14. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  15. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  16. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  17. package/src/components/UiFileUploadBox/types.ts +8 -5
  18. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  19. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  20. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  21. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  22. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
  23. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  24. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  25. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  26. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  27. package/src/components/UiStepper/UiStepper.vue +14 -1
  28. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  29. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  30. package/src/components/UiStepper/context.ts +10 -0
  31. package/src/components/core/calendar/Calendar.vue +234 -2
  32. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  33. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  34. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  35. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  36. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  37. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  38. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  39. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  40. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  41. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  42. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  43. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  44. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  45. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  46. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  47. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  48. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  49. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  50. package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
@@ -1,9 +1,29 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { CalendarDate, getLocalTimeZone, today } from '@internationalized/date';
3
3
  import type { DateRange, DateValue } from 'reka-ui';
4
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
4
5
  import { ref } from 'vue';
5
6
  import UiRangeCalendar from './UiRangeCalendar.vue';
6
7
 
8
+ // Module-level spy shared by every story with a play function; each play
9
+ // clears it first so runs stay independent.
10
+ const onUpdate = fn();
11
+
12
+ /**
13
+ * Returns the day cell trigger for the given ISO date, throwing when absent.
14
+ * Day triggers are divs with `role="button"` (not native buttons) so the
15
+ * roving tabindex can exclude disabled/outside-view days.
16
+ * @param canvasElement Story canvas root.
17
+ * @param value ISO date string, e.g. `2026-06-15`.
18
+ */
19
+ function getDayCell(canvasElement: HTMLElement, value: string): HTMLElement {
20
+ const cell = canvasElement.querySelector<HTMLElement>(
21
+ `[data-slot="range-calendar-trigger"][data-value='${value}']:not([data-outside-view])`,
22
+ );
23
+ if (!cell) throw new Error(`Expected a day cell for ${value}`);
24
+ return cell;
25
+ }
26
+
7
27
  /**
8
28
  * UiRangeCalendar is a month-grid date picker for selecting a start and end date.
9
29
  * Use it standalone or inside a `UiPopover` to power range filters and reservation flows; for single-date selection, use `UiCalendar`.
@@ -13,8 +33,13 @@ const meta: Meta<typeof UiRangeCalendar> = {
13
33
  component: UiRangeCalendar,
14
34
  tags: ['autodocs'],
15
35
  decorators: [
16
- () => ({
17
- template: '<div class="inline-block"><story /></div>',
36
+ // The Accessibility story renders Default/Accessible panels side by side
37
+ // with explanatory text, so it needs the full canvas width; every other
38
+ // story shrinks to the calendar's intrinsic size.
39
+ (story, context) => ({
40
+ template: `<div class="${
41
+ context.name === 'Accessibility' ? 'w-full p-4' : 'inline-block'
42
+ }"><story /></div>`,
18
43
  }),
19
44
  ],
20
45
  argTypes: {
@@ -111,7 +136,7 @@ export const Default: Story = {
111
136
  setup() {
112
137
  const dateRange = ref<DateRange>();
113
138
  const placeholder = ref(today(getLocalTimeZone()));
114
- return { dateRange, placeholder, args };
139
+ return { dateRange, placeholder, args, onUpdate };
115
140
  },
116
141
  template: `<UiRangeCalendar
117
142
  v-model="dateRange"
@@ -127,15 +152,52 @@ export const Default: Story = {
127
152
  :prevent-deselect="args.preventDeselect"
128
153
  :calendar-label="args.calendarLabel"
129
154
  :initial-focus="args.initialFocus"
155
+ @update:model-value="onUpdate"
130
156
  />`,
131
157
  }),
132
158
  parameters: {
159
+ // The play selects a range and moves focus to the clicked days, so the
160
+ // end state no longer matches the empty calendar this story showcases.
161
+ chromatic: { disableSnapshot: true },
133
162
  docs: {
134
163
  source: {
135
164
  code: defaultTemplateSource,
136
165
  },
137
166
  },
138
167
  },
168
+ play: async ({ canvasElement, step }) => {
169
+ // Scenario (UiRangeCalendar): a pointer user clicks a start and an end
170
+ // day to build a range. This story shows the current month, so the days
171
+ // derive from today().
172
+ onUpdate.mockClear();
173
+ const month = today(getLocalTimeZone());
174
+ const start = String(month.set({ day: 10 }));
175
+ const middle = String(month.set({ day: 12 }));
176
+ const end = String(month.set({ day: 14 }));
177
+
178
+ await step(
179
+ 'interaction: selecting start and end builds a range and emits update:modelValue',
180
+ async () => {
181
+ await userEvent.click(getDayCell(canvasElement, start));
182
+ await expect(getDayCell(canvasElement, start)).toHaveAttribute(
183
+ 'data-selection-start',
184
+ );
185
+ await userEvent.click(getDayCell(canvasElement, end));
186
+ await expect(getDayCell(canvasElement, end)).toHaveAttribute(
187
+ 'data-selection-end',
188
+ );
189
+ // Every day inside the range reports selected on its gridcell.
190
+ for (const value of [start, middle, end]) {
191
+ await expect(
192
+ getDayCell(canvasElement, value).closest('td'),
193
+ ).toHaveAttribute('aria-selected', 'true');
194
+ }
195
+ const range = onUpdate.mock.lastCall?.[0] as DateRange;
196
+ await expect(String(range.start)).toBe(start);
197
+ await expect(String(range.end)).toBe(end);
198
+ },
199
+ );
200
+ },
139
201
  };
140
202
 
141
203
  const multipleMonthsTemplateSource = `<script setup lang="ts">
@@ -212,22 +274,63 @@ export const WithPreselectedRange: Story = {
212
274
  end: new CalendarDate(2025, 1, 20),
213
275
  });
214
276
  const placeholder = ref(new CalendarDate(2025, 1, 1));
215
- return { dateRange, placeholder, args };
277
+ return { dateRange, placeholder, args, onUpdate };
216
278
  },
217
279
  template: `<UiRangeCalendar
218
280
  v-model="dateRange"
219
281
  :default-placeholder="placeholder"
220
282
  :disabled="args.disabled"
221
283
  :locale="args.locale"
284
+ @update:model-value="onUpdate"
222
285
  />`,
223
286
  }),
224
287
  parameters: {
288
+ // The play replaces the preselected range and moves focus to the clicked
289
+ // days, so the end state no longer matches the showcased selection.
290
+ chromatic: { disableSnapshot: true },
225
291
  docs: {
226
292
  source: {
227
293
  code: withPreselectedRangeTemplateSource,
228
294
  },
229
295
  },
230
296
  },
297
+ play: async ({ canvasElement, step }) => {
298
+ // Scenario (UiRangeCalendar): a pointer user adjusts an existing range —
299
+ // picking a day after a complete range starts a new one.
300
+ onUpdate.mockClear();
301
+
302
+ await step(
303
+ 'interaction: the preselected range reports its start and end',
304
+ async () => {
305
+ await expect(getDayCell(canvasElement, '2025-01-10')).toHaveAttribute(
306
+ 'data-selection-start',
307
+ );
308
+ await expect(getDayCell(canvasElement, '2025-01-20')).toHaveAttribute(
309
+ 'data-selection-end',
310
+ );
311
+ },
312
+ );
313
+
314
+ await step(
315
+ 'interaction: picking a day after a complete range starts a new range',
316
+ async () => {
317
+ await userEvent.click(getDayCell(canvasElement, '2025-01-25'));
318
+ await expect(getDayCell(canvasElement, '2025-01-25')).toHaveAttribute(
319
+ 'data-selection-start',
320
+ );
321
+ await expect(
322
+ getDayCell(canvasElement, '2025-01-10'),
323
+ ).not.toHaveAttribute('data-selection-start');
324
+ await userEvent.click(getDayCell(canvasElement, '2025-01-27'));
325
+ await expect(getDayCell(canvasElement, '2025-01-27')).toHaveAttribute(
326
+ 'data-selection-end',
327
+ );
328
+ const range = onUpdate.mock.lastCall?.[0] as DateRange;
329
+ await expect(String(range.start)).toBe('2025-01-25');
330
+ await expect(String(range.end)).toBe('2025-01-27');
331
+ },
332
+ );
333
+ },
231
334
  };
232
335
 
233
336
  const disabledDatesTemplateSource = `<script setup lang="ts">
@@ -265,7 +368,7 @@ export const DisabledWeekends: Story = {
265
368
  return dayOfWeek === 0 || dayOfWeek === 6;
266
369
  };
267
370
 
268
- return { dateRange, placeholder, isDateDisabled, args };
371
+ return { dateRange, placeholder, isDateDisabled, args, onUpdate };
269
372
  },
270
373
  template: `<UiRangeCalendar
271
374
  v-model="dateRange"
@@ -273,6 +376,7 @@ export const DisabledWeekends: Story = {
273
376
  :is-date-disabled="isDateDisabled"
274
377
  :disabled="args.disabled"
275
378
  :locale="args.locale"
379
+ @update:model-value="onUpdate"
276
380
  />`,
277
381
  }),
278
382
  parameters: {
@@ -282,6 +386,30 @@ export const DisabledWeekends: Story = {
282
386
  },
283
387
  },
284
388
  },
389
+ play: async ({ canvasElement, step }) => {
390
+ // Scenario (UiRangeCalendar): a pointer user bounces off a disabled
391
+ // weekend day. The story shows the current month, so walk from the 1st to
392
+ // its first Saturday. The click leaves no selection behind, so the
393
+ // Chromatic snapshot of the disabled styling stays valid.
394
+ onUpdate.mockClear();
395
+ let saturday = today(getLocalTimeZone()).set({ day: 1 });
396
+ while (saturday.toDate(getLocalTimeZone()).getDay() !== 6) {
397
+ saturday = saturday.add({ days: 1 });
398
+ }
399
+ const disabledDay = getDayCell(canvasElement, String(saturday));
400
+
401
+ await step(
402
+ 'interaction: a disabled day cannot be selected (WCAG 4.1.2)',
403
+ async () => {
404
+ await expect(disabledDay).toHaveAttribute('aria-disabled', 'true');
405
+ // Disabled days render with pointer-events: none; bypass the check to
406
+ // prove the guard itself blocks selection.
407
+ await userEvent.click(disabledDay, { pointerEventsCheck: 0 });
408
+ await expect(disabledDay).not.toHaveAttribute('data-selection-start');
409
+ await expect(onUpdate).not.toHaveBeenCalled();
410
+ },
411
+ );
412
+ },
285
413
  };
286
414
 
287
415
  const dateRangeConstraintsTemplateSource = `<script setup lang="ts">
@@ -395,11 +523,12 @@ export const Disabled: Story = {
395
523
  components: { UiRangeCalendar },
396
524
  setup() {
397
525
  const placeholder = ref(today(getLocalTimeZone()));
398
- return { placeholder, args };
526
+ return { placeholder, args, onUpdate };
399
527
  },
400
528
  template: `<UiRangeCalendar
401
529
  :default-placeholder="placeholder"
402
530
  :disabled="args.disabled"
531
+ @update:model-value="onUpdate"
403
532
  />`,
404
533
  }),
405
534
  parameters: {
@@ -409,6 +538,50 @@ export const Disabled: Story = {
409
538
  },
410
539
  },
411
540
  },
541
+ play: async ({ canvasElement, step }) => {
542
+ // Scenario (UiRangeCalendar): the whole calendar is disabled — every day
543
+ // and both month-navigation buttons must be inert. Nothing changes state,
544
+ // so the Chromatic snapshot of the disabled styling stays valid.
545
+ onUpdate.mockClear();
546
+ const canvas = within(canvasElement);
547
+ const day = getDayCell(
548
+ canvasElement,
549
+ String(today(getLocalTimeZone()).set({ day: 15 })),
550
+ );
551
+
552
+ await step(
553
+ 'interaction: every day is announced and rendered disabled (WCAG 4.1.2)',
554
+ async () => {
555
+ await expect(day).toHaveAttribute('aria-disabled', 'true');
556
+ await expect(day).toHaveAttribute('data-disabled');
557
+ await expect(
558
+ canvasElement.querySelector(
559
+ '[data-slot="range-calendar-trigger"]:not([data-disabled])',
560
+ ),
561
+ ).toBeNull();
562
+ },
563
+ );
564
+
565
+ await step(
566
+ 'interaction: clicking a day selects nothing and emits no update',
567
+ async () => {
568
+ // Disabled days render with pointer-events: none; bypass the check to
569
+ // prove the guard itself blocks selection.
570
+ await userEvent.click(day, { pointerEventsCheck: 0 });
571
+ await expect(day).not.toHaveAttribute('data-selection-start');
572
+ await expect(onUpdate).not.toHaveBeenCalled();
573
+ },
574
+ );
575
+
576
+ await step('interaction: month navigation is disabled too', async () => {
577
+ await expect(
578
+ canvas.getByRole('button', { name: /previous/i }),
579
+ ).toBeDisabled();
580
+ await expect(
581
+ canvas.getByRole('button', { name: /next/i }),
582
+ ).toBeDisabled();
583
+ });
584
+ },
412
585
  };
413
586
 
414
587
  const readonlyTemplateSource = `<script setup lang="ts">
@@ -442,21 +615,65 @@ export const Readonly: Story = {
442
615
  end: new CalendarDate(2025, 1, 20),
443
616
  });
444
617
  const placeholder = ref(new CalendarDate(2025, 1, 1));
445
- return { dateRange, placeholder, args };
618
+ return { dateRange, placeholder, args, onUpdate };
446
619
  },
447
620
  template: `<UiRangeCalendar
448
621
  v-model="dateRange"
449
622
  :default-placeholder="placeholder"
450
623
  :readonly="args.readonly"
624
+ @update:model-value="onUpdate"
451
625
  />`,
452
626
  }),
453
627
  parameters: {
628
+ // The play clicks days and navigation buttons, moving focus; the final
629
+ // frame would otherwise register focus styling as a visual diff.
630
+ chromatic: { disableSnapshot: true },
454
631
  docs: {
455
632
  source: {
456
633
  code: readonlyTemplateSource,
457
634
  },
458
635
  },
459
636
  },
637
+ play: async ({ canvasElement, step }) => {
638
+ // Scenario (UiRangeCalendar): the whole calendar is read-only — users can
639
+ // browse months, but clicking must never change the preselected range.
640
+ onUpdate.mockClear();
641
+ const canvas = within(canvasElement);
642
+
643
+ await step(
644
+ 'interaction: clicking a day leaves the range untouched and emits no update',
645
+ async () => {
646
+ await userEvent.click(getDayCell(canvasElement, '2025-01-15'));
647
+ await expect(
648
+ getDayCell(canvasElement, '2025-01-15'),
649
+ ).not.toHaveAttribute('data-selection-start');
650
+ await expect(getDayCell(canvasElement, '2025-01-10')).toHaveAttribute(
651
+ 'data-selection-start',
652
+ );
653
+ await expect(getDayCell(canvasElement, '2025-01-20')).toHaveAttribute(
654
+ 'data-selection-end',
655
+ );
656
+ await expect(onUpdate).not.toHaveBeenCalled();
657
+ },
658
+ );
659
+
660
+ await step(
661
+ 'interaction: month navigation still works in read-only mode',
662
+ async () => {
663
+ // The month name also appears in the calendar's visually hidden
664
+ // accessible heading, so assert on the visible heading element.
665
+ const heading = canvasElement.querySelector(
666
+ '[data-slot="range-calendar-heading"]',
667
+ );
668
+ await userEvent.click(canvas.getByRole('button', { name: /next/i }));
669
+ await waitFor(() => expect(heading).toHaveTextContent('February 2025'));
670
+ await userEvent.click(
671
+ canvas.getByRole('button', { name: /previous/i }),
672
+ );
673
+ await waitFor(() => expect(heading).toHaveTextContent('January 2025'));
674
+ },
675
+ );
676
+ },
460
677
  };
461
678
 
462
679
  const unavailableDatesTemplateSource = `<script setup lang="ts">
@@ -601,3 +818,598 @@ export const PagedNavigation: Story = {
601
818
  },
602
819
  },
603
820
  };
821
+
822
+ /**
823
+ * Shared fixture for the hidden test stories: a fixed June 2026 view (so runs
824
+ * never depend on the real date), labelled "Stay dates", with June 16
825
+ * optionally disabled, an optional preselected June 10–12 range, and optional
826
+ * min/max bounds (May 20 – July 10 2026) for paging-boundary coverage.
827
+ * @param options Fixture options.
828
+ * @param options.disableDay16 Disables June 16 to exercise disabled-day guards.
829
+ * @param options.withRange Preselects June 10–12.
830
+ * @param options.withBounds Sets minValue May 20 2026 and maxValue July 10 2026.
831
+ */
832
+ function renderTestRangeCalendar(
833
+ options: {
834
+ disableDay16?: boolean;
835
+ withRange?: boolean;
836
+ withBounds?: boolean;
837
+ } = {},
838
+ ) {
839
+ return () => ({
840
+ components: { UiRangeCalendar },
841
+ setup() {
842
+ const placeholder = new CalendarDate(2026, 6, 15);
843
+ const defaultValue: DateRange | undefined = options.withRange
844
+ ? {
845
+ start: new CalendarDate(2026, 6, 10),
846
+ end: new CalendarDate(2026, 6, 12),
847
+ }
848
+ : undefined;
849
+ const isDateDisabled = options.disableDay16
850
+ ? (d: DateValue) => d.year === 2026 && d.month === 6 && d.day === 16
851
+ : undefined;
852
+ const minValue = options.withBounds
853
+ ? new CalendarDate(2026, 5, 20)
854
+ : undefined;
855
+ const maxValue = options.withBounds
856
+ ? new CalendarDate(2026, 7, 10)
857
+ : undefined;
858
+ return {
859
+ placeholder,
860
+ defaultValue,
861
+ isDateDisabled,
862
+ minValue,
863
+ maxValue,
864
+ onUpdate,
865
+ };
866
+ },
867
+ template: `<UiRangeCalendar
868
+ :default-placeholder="placeholder"
869
+ :default-value="defaultValue"
870
+ :is-date-disabled="isDateDisabled"
871
+ :min-value="minValue"
872
+ :max-value="maxValue"
873
+ fixed-weeks
874
+ calendar-label="Stay dates"
875
+ @update:model-value="onUpdate"
876
+ />`,
877
+ });
878
+ }
879
+
880
+ /**
881
+ * `UiRangeCalendar` is fully keyboard operable with the WAI-ARIA date-grid
882
+ * keys: `Tab` reaches the grid as a single stop, arrows move by day and week
883
+ * while skipping disabled days, `Home`/`End` jump within the week,
884
+ * `PageUp`/`PageDown` switch months, and `Enter`/`Space` pick the range ends.
885
+ */
886
+ export const KeyboardNavigation: Story = {
887
+ name: 'test - Keyboard Navigation',
888
+ tags: ['!dev', '!autodocs'],
889
+ parameters: {
890
+ chromatic: { disableSnapshot: true },
891
+ docs: {
892
+ description: {
893
+ story:
894
+ 'Press `Tab` to reach the grid, arrows/Home/End/PageUp/PageDown to move, and Enter/Space to pick the range ends.',
895
+ },
896
+ },
897
+ },
898
+ render: renderTestRangeCalendar({ disableDay16: true }),
899
+ play: async ({ canvasElement, step }) => {
900
+ // Scenario (UiRangeCalendar): a keyboard user tabs past the month
901
+ // controls onto the grid's single tab stop, walks the grid with the
902
+ // calendar keys, and picks both range ends without a pointer.
903
+ onUpdate.mockClear();
904
+ const canvas = within(canvasElement);
905
+ const activeDataValue = () =>
906
+ canvasElement.ownerDocument.activeElement?.getAttribute('data-value');
907
+
908
+ await step(
909
+ 'keyboard: Tab reaches the grid as a single stop after the month controls (WCAG 2.1.1)',
910
+ async () => {
911
+ await userEvent.tab();
912
+ await expect(
913
+ canvas.getByRole('button', { name: 'Previous page' }),
914
+ ).toHaveFocus();
915
+ await userEvent.tab();
916
+ await expect(
917
+ canvas.getByRole('button', { name: 'Next page' }),
918
+ ).toHaveFocus();
919
+ await userEvent.tab();
920
+ await expect(activeDataValue()).toBe('2026-06-15');
921
+ },
922
+ );
923
+
924
+ await step(
925
+ 'keyboard: arrow keys move by day and week, skipping the disabled day',
926
+ async () => {
927
+ await userEvent.keyboard('{ArrowRight}');
928
+ await expect(activeDataValue()).toBe('2026-06-17');
929
+ await userEvent.keyboard('{ArrowLeft}');
930
+ await expect(activeDataValue()).toBe('2026-06-15');
931
+ await userEvent.keyboard('{ArrowDown}');
932
+ await expect(activeDataValue()).toBe('2026-06-22');
933
+ await userEvent.keyboard('{ArrowUp}');
934
+ await expect(activeDataValue()).toBe('2026-06-15');
935
+ },
936
+ );
937
+
938
+ await step(
939
+ 'keyboard: Enter picks the range start and Space the range end',
940
+ async () => {
941
+ await userEvent.keyboard('{ArrowRight}');
942
+ await userEvent.keyboard('{Enter}');
943
+ await expect(getDayCell(canvasElement, '2026-06-17')).toHaveAttribute(
944
+ 'data-selection-start',
945
+ );
946
+ await userEvent.keyboard('{ArrowRight}{ArrowRight}');
947
+ await expect(activeDataValue()).toBe('2026-06-19');
948
+ await userEvent.keyboard(' ');
949
+ await expect(getDayCell(canvasElement, '2026-06-19')).toHaveAttribute(
950
+ 'data-selection-end',
951
+ );
952
+ for (const day of ['17', '18', '19']) {
953
+ await expect(
954
+ getDayCell(canvasElement, `2026-06-${day}`).closest('td'),
955
+ ).toHaveAttribute('aria-selected', 'true');
956
+ }
957
+ const range = onUpdate.mock.lastCall?.[0] as DateRange;
958
+ await expect(String(range.start)).toBe('2026-06-17');
959
+ await expect(String(range.end)).toBe('2026-06-19');
960
+ },
961
+ );
962
+
963
+ await step(
964
+ 'keyboard: Home and End jump to the first and last enabled day of the week (WCAG 2.4.3)',
965
+ async () => {
966
+ await userEvent.keyboard('{Home}');
967
+ await expect(activeDataValue()).toBe('2026-06-14');
968
+ await userEvent.keyboard('{End}');
969
+ await expect(activeDataValue()).toBe('2026-06-20');
970
+ },
971
+ );
972
+
973
+ await step(
974
+ 'keyboard: PageDown and PageUp move to the same day in the adjacent month',
975
+ async () => {
976
+ await userEvent.keyboard('{PageDown}');
977
+ await waitFor(async () => {
978
+ await expect(canvas.getByText('July 2026')).toBeVisible();
979
+ await expect(activeDataValue()).toBe('2026-07-20');
980
+ });
981
+ await userEvent.keyboard('{PageUp}');
982
+ await waitFor(async () => {
983
+ await expect(canvas.getByText('June 2026')).toBeVisible();
984
+ await expect(activeDataValue()).toBe('2026-06-20');
985
+ });
986
+ },
987
+ );
988
+ },
989
+ };
990
+
991
+ /**
992
+ * Paging against min/max bounds: when only part of the target month is
993
+ * allowed, PageUp/PageDown land on the clamped boundary date instead of being
994
+ * rejected; paging is refused only when the whole target month lies outside
995
+ * the bounds, keeping focus where it was.
996
+ */
997
+ export const KeyboardMonthBoundaries: Story = {
998
+ name: 'test - Keyboard Month Boundaries',
999
+ tags: ['!dev', '!autodocs'],
1000
+ parameters: {
1001
+ chromatic: { disableSnapshot: true },
1002
+ docs: {
1003
+ description: {
1004
+ story:
1005
+ 'PageUp/PageDown clamp to the allowed portion of a partially allowed month and refuse to leave the bounds entirely.',
1006
+ },
1007
+ },
1008
+ },
1009
+ render: renderTestRangeCalendar({ withBounds: true }),
1010
+ play: async ({ canvasElement, step }) => {
1011
+ // Scenario (UiRangeCalendar): a keyboard user pages across months in a
1012
+ // calendar bounded to May 20 – July 10 2026, starting from June 15.
1013
+ const canvas = within(canvasElement);
1014
+ const activeDataValue = () =>
1015
+ canvasElement.ownerDocument.activeElement?.getAttribute('data-value');
1016
+
1017
+ await step('keyboard: Tab reaches the grid single stop', async () => {
1018
+ await userEvent.tab();
1019
+ await userEvent.tab();
1020
+ await userEvent.tab();
1021
+ await expect(activeDataValue()).toBe('2026-06-15');
1022
+ });
1023
+
1024
+ await step(
1025
+ 'keyboard: PageUp into a partially allowed month lands on the clamped minValue day',
1026
+ async () => {
1027
+ // The same day in May (May 15) is before minValue May 20, but May
1028
+ // 20–31 are selectable, so navigation clamps instead of rejecting.
1029
+ await userEvent.keyboard('{PageUp}');
1030
+ await waitFor(async () => {
1031
+ await expect(canvas.getByText('May 2026')).toBeVisible();
1032
+ await expect(activeDataValue()).toBe('2026-05-20');
1033
+ });
1034
+ },
1035
+ );
1036
+
1037
+ await step(
1038
+ 'keyboard: PageUp is refused when the whole previous month is out of bounds',
1039
+ async () => {
1040
+ await userEvent.keyboard('{PageUp}');
1041
+ await expect(canvas.getByText('May 2026')).toBeVisible();
1042
+ await expect(activeDataValue()).toBe('2026-05-20');
1043
+ },
1044
+ );
1045
+
1046
+ await step(
1047
+ 'keyboard: PageDown into a partially allowed month lands on the clamped maxValue day',
1048
+ async () => {
1049
+ // Back to June 20 (fully allowed), then July: July 20 exceeds
1050
+ // maxValue July 10, so navigation clamps to July 10.
1051
+ await userEvent.keyboard('{PageDown}');
1052
+ await waitFor(async () => {
1053
+ await expect(activeDataValue()).toBe('2026-06-20');
1054
+ });
1055
+ await userEvent.keyboard('{PageDown}');
1056
+ await waitFor(async () => {
1057
+ await expect(canvas.getByText('July 2026')).toBeVisible();
1058
+ await expect(activeDataValue()).toBe('2026-07-10');
1059
+ });
1060
+ },
1061
+ );
1062
+
1063
+ await step(
1064
+ 'keyboard: PageDown is refused when the whole next month is out of bounds',
1065
+ async () => {
1066
+ await userEvent.keyboard('{PageDown}');
1067
+ await expect(canvas.getByText('July 2026')).toBeVisible();
1068
+ await expect(activeDataValue()).toBe('2026-07-10');
1069
+ },
1070
+ );
1071
+ },
1072
+ };
1073
+
1074
+ /**
1075
+ * Screen-reader semantics: the calendar announces its label, day cells expose
1076
+ * `gridcell` with `aria-selected` across the range, the start and end days
1077
+ * announce their pressed state, every day is named by its full date, and the
1078
+ * grid keeps a single roving tab stop.
1079
+ */
1080
+ export const ScreenReader: Story = {
1081
+ name: 'test - Screen Reader',
1082
+ tags: ['!dev', '!autodocs'],
1083
+ parameters: {
1084
+ chromatic: { disableSnapshot: true },
1085
+ docs: {
1086
+ description: {
1087
+ story:
1088
+ 'Verifies the roles, names, and states that assistive technology announces.',
1089
+ },
1090
+ },
1091
+ },
1092
+ render: renderTestRangeCalendar({ disableDay16: true, withRange: true }),
1093
+ play: async ({ canvasElement, step }) => {
1094
+ // Scenario (UiRangeCalendar): assistive tech reads a labelled calendar,
1095
+ // hears every day as a full date, and is told which days are selected —
1096
+ // including the start and end of the preselected June 10–12 range.
1097
+ await step(
1098
+ 'screen-reader: the calendar announces its accessible label (WCAG 1.3.1)',
1099
+ async () => {
1100
+ const root = canvasElement.querySelector(
1101
+ '[data-slot="range-calendar"]',
1102
+ );
1103
+ if (!root) throw new Error('Expected the range calendar root');
1104
+ await expect(root.getAttribute('aria-label')).toContain('Stay dates');
1105
+ },
1106
+ );
1107
+
1108
+ await step(
1109
+ 'screen-reader: every day in the range announces aria-selected on its gridcell (WCAG 4.1.2)',
1110
+ async () => {
1111
+ for (const day of ['10', '11', '12']) {
1112
+ await expect(
1113
+ getDayCell(canvasElement, `2026-06-${day}`).closest('td'),
1114
+ ).toHaveAttribute('aria-selected', 'true');
1115
+ }
1116
+ await expect(
1117
+ getDayCell(canvasElement, '2026-06-20').closest('td'),
1118
+ ).not.toHaveAttribute('aria-selected');
1119
+ },
1120
+ );
1121
+
1122
+ await step(
1123
+ 'screen-reader: the start and end days announce their selected state',
1124
+ async () => {
1125
+ const start = getDayCell(canvasElement, '2026-06-10');
1126
+ const end = getDayCell(canvasElement, '2026-06-12');
1127
+ await expect(start).toHaveAttribute('data-selection-start');
1128
+ await expect(start).toHaveAttribute('aria-pressed', 'true');
1129
+ await expect(end).toHaveAttribute('data-selection-end');
1130
+ await expect(end).toHaveAttribute('aria-pressed', 'true');
1131
+ },
1132
+ );
1133
+
1134
+ await step(
1135
+ 'screen-reader: every day is a button named by its full date (WCAG 4.1.2)',
1136
+ async () => {
1137
+ const day = getDayCell(canvasElement, '2026-06-10');
1138
+ await expect(day).toHaveAttribute('role', 'button');
1139
+ await expect(day.getAttribute('aria-label')).toContain('2026');
1140
+ },
1141
+ );
1142
+
1143
+ await step(
1144
+ 'screen-reader: the grid keeps a single roving tab stop (WCAG 2.4.3)',
1145
+ async () => {
1146
+ const tabbable = canvasElement.querySelectorAll(
1147
+ '[data-slot="range-calendar-trigger"][tabindex="0"]',
1148
+ );
1149
+ await expect(tabbable).toHaveLength(1);
1150
+ },
1151
+ );
1152
+
1153
+ await step(
1154
+ 'screen-reader: the disabled day announces aria-disabled (WCAG 4.1.2)',
1155
+ async () => {
1156
+ await expect(getDayCell(canvasElement, '2026-06-16')).toHaveAttribute(
1157
+ 'aria-disabled',
1158
+ 'true',
1159
+ );
1160
+ },
1161
+ );
1162
+ },
1163
+ };
1164
+
1165
+ /**
1166
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1167
+ * try 400% reflow (WCAG 1.4.10); the grid must stay visible, readable, and
1168
+ * operable.
1169
+ */
1170
+ export const ZoomMagnification: Story = {
1171
+ name: 'test - Zoom Magnification',
1172
+ tags: ['!dev', '!autodocs'],
1173
+ globals: { zoom: '200' },
1174
+ parameters: {
1175
+ chromatic: { disableSnapshot: true },
1176
+ docs: {
1177
+ description: {
1178
+ story:
1179
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1180
+ },
1181
+ },
1182
+ },
1183
+ render: renderTestRangeCalendar({ withRange: true }),
1184
+ play: async ({ canvasElement, step }) => {
1185
+ // Scenario (UiRangeCalendar): at 200% page zoom the month heading and
1186
+ // every day stay on screen, and a new range can still be started.
1187
+ const canvas = within(canvasElement);
1188
+
1189
+ await step(
1190
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1191
+ async () => {
1192
+ await expect(document.documentElement.style.zoom).toBe('200%');
1193
+ },
1194
+ );
1195
+
1196
+ await step(
1197
+ 'zoom: the month heading and day grid stay visible when magnified',
1198
+ async () => {
1199
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1200
+ await expect(getDayCell(canvasElement, '2026-06-10')).toBeVisible();
1201
+ await expect(getDayCell(canvasElement, '2026-06-30')).toBeVisible();
1202
+ },
1203
+ );
1204
+
1205
+ await step('zoom: the grid remains operable when magnified', async () => {
1206
+ await userEvent.click(getDayCell(canvasElement, '2026-06-20'));
1207
+ await expect(getDayCell(canvasElement, '2026-06-20')).toHaveAttribute(
1208
+ 'data-selection-start',
1209
+ );
1210
+ });
1211
+ },
1212
+ };
1213
+
1214
+ /**
1215
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1216
+ * toolbar. The grid stays usable and day cells meet the minimum touch-target
1217
+ * size (WCAG 2.5.8).
1218
+ */
1219
+ export const MobileBreakpoint: Story = {
1220
+ name: 'test - Mobile Breakpoint',
1221
+ tags: ['!dev', '!autodocs'],
1222
+ globals: { mediaBreakpoint: 'reflow' },
1223
+ parameters: {
1224
+ chromatic: { disableSnapshot: true },
1225
+ docs: {
1226
+ description: {
1227
+ story:
1228
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1229
+ },
1230
+ },
1231
+ },
1232
+ render: renderTestRangeCalendar(),
1233
+ play: async ({ canvasElement, step }) => {
1234
+ // Scenario (UiRangeCalendar): at the 320px mobile breakpoint the grid
1235
+ // stays visible, days are big enough to tap, and tapping still builds a
1236
+ // range.
1237
+ onUpdate.mockClear();
1238
+ const canvas = within(canvasElement);
1239
+
1240
+ await step(
1241
+ 'mobile: the calendar stays visible at the 320px breakpoint (WCAG 1.4.10 Reflow)',
1242
+ async () => {
1243
+ await expect(canvas.getByText('June 2026')).toBeVisible();
1244
+ await expect(getDayCell(canvasElement, '2026-06-15')).toBeVisible();
1245
+ const calendar = canvasElement.querySelector<HTMLElement>(
1246
+ '[data-slot="range-calendar"]',
1247
+ );
1248
+ if (!calendar) throw new Error('Expected the range calendar root');
1249
+ const { left, right } = calendar.getBoundingClientRect();
1250
+ await expect(left).toBeGreaterThanOrEqual(0);
1251
+ await expect(right).toBeLessThanOrEqual(
1252
+ canvasElement.ownerDocument.documentElement.clientWidth,
1253
+ );
1254
+ },
1255
+ );
1256
+
1257
+ await step(
1258
+ 'mobile: day cells meet the minimum touch-target size (WCAG 2.5.8)',
1259
+ async () => {
1260
+ for (const day of ['1', '15', '30']) {
1261
+ const { width, height } = getDayCell(
1262
+ canvasElement,
1263
+ `2026-06-${day.padStart(2, '0')}`,
1264
+ ).getBoundingClientRect();
1265
+ await expect(width).toBeGreaterThanOrEqual(24);
1266
+ await expect(height).toBeGreaterThanOrEqual(24);
1267
+ }
1268
+ },
1269
+ );
1270
+
1271
+ await step(
1272
+ 'mobile: tapping start and end builds a range at the 320px breakpoint',
1273
+ async () => {
1274
+ await userEvent.click(getDayCell(canvasElement, '2026-06-10'));
1275
+ await userEvent.click(getDayCell(canvasElement, '2026-06-12'));
1276
+ await expect(getDayCell(canvasElement, '2026-06-10')).toHaveAttribute(
1277
+ 'data-selection-start',
1278
+ );
1279
+ await expect(getDayCell(canvasElement, '2026-06-12')).toHaveAttribute(
1280
+ 'data-selection-end',
1281
+ );
1282
+ const range = onUpdate.mock.lastCall?.[0] as DateRange;
1283
+ await expect(String(range.start)).toBe('2026-06-10');
1284
+ await expect(String(range.end)).toBe('2026-06-12');
1285
+ },
1286
+ );
1287
+ },
1288
+ };
1289
+
1290
+ /**
1291
+ * Accessibility guidance for the range calendar: selection, today, focus and
1292
+ * unavailable treatments that survive without colour, comfortable day
1293
+ * targets, and a stable grid — shown side by side in the default and
1294
+ * accessible themes.
1295
+ */
1296
+ export const Accessibility: Story = {
1297
+ tags: ['!autodocs'],
1298
+ parameters: {
1299
+ a11y: { test: 'off' },
1300
+ chromatic: { disableSnapshot: true },
1301
+ docs: {
1302
+ canvas: {
1303
+ sourceState: 'none',
1304
+ },
1305
+ },
1306
+ },
1307
+ render: () => ({
1308
+ components: { UiRangeCalendar },
1309
+ setup() {
1310
+ const range: DateRange = {
1311
+ start: new CalendarDate(2025, 1, 10),
1312
+ end: new CalendarDate(2025, 1, 14),
1313
+ };
1314
+ const placeholder = new CalendarDate(2025, 1, 1);
1315
+ return { range, placeholder };
1316
+ },
1317
+ template: `
1318
+ <section class="flex w-full flex-col gap-6 p-4">
1319
+ <div>
1320
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1321
+ Accessibility
1322
+ </h2>
1323
+ </div>
1324
+
1325
+ <div class="flex flex-col gap-6">
1326
+ <div class="flex flex-col gap-2">
1327
+ <h3 class="body-16-medium text-content-on-surface-primary">
1328
+ Requirements
1329
+ </h3>
1330
+ <ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
1331
+ <li>
1332
+ Today and the selected day differ in shape as well as fill, so
1333
+ both survive without colour
1334
+ </li>
1335
+ <li>
1336
+ Selected, hover and focus are three distinguishable treatments,
1337
+ not variations of one
1338
+ </li>
1339
+ <li>
1340
+ Focus stays visible on a day even when that day is selected or
1341
+ inside a range
1342
+ </li>
1343
+ <li>
1344
+ Day buttons are a comfortable target at the size chosen,
1345
+ including the smallest one used
1346
+ </li>
1347
+ <li>
1348
+ Unavailable days carry a visible treatment beyond low contrast
1349
+ </li>
1350
+ <li>
1351
+ The grid keeps a stable size between months, so the page does
1352
+ not shift under the reader
1353
+ </li>
1354
+ <li>
1355
+ Give the trigger a meaningful name with aria-label (for example,
1356
+ "Choose departure date") and name its calendar with calendar-label.
1357
+ </li>
1358
+ <li>
1359
+ Tab to the trigger and press Enter or Space to open the calendar.
1360
+ Use arrow keys to navigate dates and Enter or Space to select.
1361
+ In range mode, select the start and then the end date.
1362
+ </li>
1363
+ <li>
1364
+ Escape dismisses the calendar and returns focus to the trigger.
1365
+ By default, selecting a date or completing a range also closes
1366
+ the popover; setting close-on-select to false keeps it open.
1367
+ </li>
1368
+ </ul>
1369
+ </div>
1370
+
1371
+ <div class="flex flex-col gap-2">
1372
+ <h3 class="body-16-medium text-content-on-surface-primary">
1373
+ Enable accessibility theme
1374
+ </h3>
1375
+ <p class="body-16-regular text-content-on-surface-primary">
1376
+ When accessibility is required, enable our accessibility theme.
1377
+ This increases contrast and ensures there are no color contrast
1378
+ issues.
1379
+ </p>
1380
+ </div>
1381
+ </div>
1382
+
1383
+ <div class="grid gap-4 md:grid-cols-2">
1384
+ <div class="flex flex-col gap-3">
1385
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1386
+ Default
1387
+ </h3>
1388
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1389
+ <UiRangeCalendar
1390
+ :default-value="range"
1391
+ :default-placeholder="placeholder"
1392
+ fixed-weeks
1393
+ calendar-label="Stay dates"
1394
+ />
1395
+ </div>
1396
+ </div>
1397
+
1398
+ <div class="accessible-theme flex flex-col gap-3">
1399
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1400
+ Accessible
1401
+ </h3>
1402
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1403
+ <UiRangeCalendar
1404
+ :default-value="range"
1405
+ :default-placeholder="placeholder"
1406
+ fixed-weeks
1407
+ calendar-label="Stay dates"
1408
+ />
1409
+ </div>
1410
+ </div>
1411
+ </div>
1412
+ </section>
1413
+ `,
1414
+ }),
1415
+ };