@aleph-alpha/ui-library 6.3.3 → 6.4.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 (105) hide show
  1. package/config.js +2 -1
  2. package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
  3. package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
  4. package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
  5. package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
  6. package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
  7. package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
  8. package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
  9. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  10. package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
  11. package/dist/system/components/UiStepper/context.d.ts +8 -0
  12. package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
  13. package/dist/system/components/UiToggle/types.d.ts +10 -2
  14. package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
  15. package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
  16. package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
  17. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  18. package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
  19. package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
  20. package/dist/system/components/core/toggle/index.d.ts +47 -2
  21. package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
  22. package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
  23. package/dist/system/components/core/toggle-group/context.d.ts +1 -0
  24. package/dist/system/components/core/toggle-group/index.d.ts +10 -2
  25. package/dist/system/icons/story-sidebar-icons.json +7 -0
  26. package/dist/system/lib.js +14114 -13755
  27. package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
  28. package/dist/system/patterns/UiLayout/layout-shell.d.ts +379 -8
  29. package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
  30. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +232 -0
  31. package/dist/system/story-sidebar-icons.json +7 -0
  32. package/package.json +2 -2
  33. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  34. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  35. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  36. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
  37. package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
  38. package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
  39. package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
  40. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  41. package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
  42. package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
  43. package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
  44. package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
  45. package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
  46. package/src/components/UiDropdownMenu/types.ts +3 -0
  47. package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
  48. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  49. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  50. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  51. package/src/components/UiFileUploadBox/types.ts +8 -5
  52. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  53. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  54. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  55. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  56. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1089 -4
  57. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  58. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  59. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  60. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  61. package/src/components/UiStepper/UiStepper.vue +14 -1
  62. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  63. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  64. package/src/components/UiStepper/context.ts +10 -0
  65. package/src/components/UiToggle/UiToggle.stories.ts +386 -261
  66. package/src/components/UiToggle/UiToggle.vue +2 -0
  67. package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
  68. package/src/components/UiToggle/types.ts +10 -2
  69. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
  70. package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
  71. package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
  72. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
  73. package/src/components/UiToggleGroup/types.ts +12 -2
  74. package/src/components/core/calendar/Calendar.vue +234 -2
  75. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  76. package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
  77. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  78. package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
  79. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  80. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  81. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  82. package/src/components/core/toggle/Toggle.vue +12 -5
  83. package/src/components/core/toggle/index.ts +47 -19
  84. package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
  85. package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
  86. package/src/components/core/toggle-group/context.ts +1 -0
  87. package/src/components/core/toggle-group/index.ts +10 -24
  88. package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
  89. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  90. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  91. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  92. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  93. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  94. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  95. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  96. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  97. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  98. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  99. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  100. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  101. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  102. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
  103. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  104. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  105. package/src/patterns/UiTopBar/accessory-dropdown.ts +99 -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 { ref } from 'vue';
3
4
  import {
4
5
  UiResizableHandle,
@@ -6,6 +7,10 @@ import {
6
7
  UiResizablePanelGroup,
7
8
  } from './index';
8
9
 
10
+ // The group emits `layout` with no handler prop, so the plays bind a
11
+ // module-level spy via `@layout` rather than passing a handler through `args`.
12
+ const onLayout = fn();
13
+
9
14
  /**
10
15
  * UiResizable creates split-panel layouts whose panels can be resized by dragging
11
16
  * the handle between them.
@@ -45,6 +50,37 @@ const panelClasses =
45
50
  const sizeValueClasses =
46
51
  'font-mono label-12-regular text-content-on-surface-muted';
47
52
 
53
+ /**
54
+ * Pointer hit area the splitter registers around a handle on coarse pointers,
55
+ * in CSS pixels per side. Mirrors `hitAreaMargins.coarse`, which the stories
56
+ * leave at the library default.
57
+ */
58
+ const COARSE_HIT_AREA_MARGIN = 15;
59
+
60
+ /**
61
+ * Resolves the resize handles rendered inside a story canvas, in DOM order.
62
+ * @param canvasElement Story canvas to search.
63
+ */
64
+ function getHandles(canvasElement: HTMLElement): HTMLElement[] {
65
+ return [
66
+ ...canvasElement.querySelectorAll<HTMLElement>(
67
+ '[data-slot="resizable-handle"]',
68
+ ),
69
+ ];
70
+ }
71
+
72
+ /**
73
+ * Resolves the panels rendered inside a story canvas, in DOM order.
74
+ * @param canvasElement Story canvas to search.
75
+ */
76
+ function getPanels(canvasElement: HTMLElement): HTMLElement[] {
77
+ return [
78
+ ...canvasElement.querySelectorAll<HTMLElement>(
79
+ '[data-slot="resizable-panel"]',
80
+ ),
81
+ ];
82
+ }
83
+
48
84
  const defaultTemplateSource = `<script setup lang="ts">
49
85
  import { ref } from 'vue'
50
86
  import {
@@ -79,7 +115,8 @@ function updateContentWidth(size: number) {
79
115
  <span class="font-mono label-12-regular text-content-on-surface-muted">{{ sidebarWidth }}% wide</span>
80
116
  </div>
81
117
  </UiResizablePanel>
82
- <UiResizableHandle with-handle />
118
+ <!-- A focusable separator needs its own name; aria-valuenow alone says nothing. -->
119
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
83
120
  <UiResizablePanel
84
121
  :default-size="70"
85
122
  :min-size="30"
@@ -120,6 +157,7 @@ export const Default: Story = {
120
157
  return {
121
158
  args,
122
159
  contentWidth,
160
+ onLayout,
123
161
  panelClasses,
124
162
  sidebarWidth,
125
163
  sizeValueClasses,
@@ -131,6 +169,7 @@ export const Default: Story = {
131
169
  <UiResizablePanelGroup
132
170
  v-bind="args"
133
171
  class="min-h-64 border border-border-surface-focus-ring"
172
+ @layout="onLayout"
134
173
  >
135
174
  <UiResizablePanel
136
175
  :default-size="30"
@@ -144,7 +183,7 @@ export const Default: Story = {
144
183
  <span :class="sizeValueClasses">{{ sidebarWidth }}% wide</span>
145
184
  </div>
146
185
  </UiResizablePanel>
147
- <UiResizableHandle with-handle />
186
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
148
187
  <UiResizablePanel
149
188
  :default-size="70"
150
189
  :min-size="30"
@@ -167,6 +206,50 @@ export const Default: Story = {
167
206
  },
168
207
  },
169
208
  },
209
+ play: async ({ canvasElement, step }) => {
210
+ // Scenario (UiResizable): the split layout renders at its declared sizes,
211
+ // the handle between the panels is exposed as a labelled separator carrying
212
+ // the current size, and the group reports that layout back to the consumer.
213
+ const canvas = within(canvasElement);
214
+ const handle = canvas.getByRole('separator', { name: 'Resize sidebar' });
215
+ const [sidebar, content] = getPanels(canvasElement);
216
+
217
+ await step(
218
+ 'interaction: panels render at their declared default sizes',
219
+ async () => {
220
+ await expect(sidebar).toHaveAttribute('data-panel-size', '30.0');
221
+ await expect(content).toHaveAttribute('data-panel-size', '70.0');
222
+ },
223
+ );
224
+
225
+ await step(
226
+ 'interaction: the handle reports the current size through its separator values',
227
+ async () => {
228
+ // The splitter writes these imperatively after layout, so they settle a
229
+ // tick after the panels themselves.
230
+ await waitFor(async () => {
231
+ await expect(handle).toHaveAttribute('aria-valuenow', '30');
232
+ });
233
+ await expect(handle).toHaveAttribute('aria-valuemin', '20');
234
+ await expect(handle).toHaveAttribute('aria-valuemax', '70');
235
+ await expect(handle).toHaveAttribute(
236
+ 'aria-controls',
237
+ sidebar.getAttribute('data-panel-id'),
238
+ );
239
+ },
240
+ );
241
+
242
+ await step(
243
+ 'interaction: the group emits its layout and each panel emits its own size',
244
+ async () => {
245
+ const lastLayout = onLayout.mock.calls.at(-1)?.[0] as number[];
246
+ await expect(lastLayout).toEqual([30, 70]);
247
+ // `@resize` per panel drives the visible readouts.
248
+ await expect(canvas.getByText('30% wide')).toBeVisible();
249
+ await expect(canvas.getByText('70% wide')).toBeVisible();
250
+ },
251
+ );
252
+ },
170
253
  };
171
254
 
172
255
  const verticalTemplateSource = `<script setup lang="ts">
@@ -267,7 +350,7 @@ export const Vertical: Story = {
267
350
  <span :class="sizeValueClasses">{{ previewHeight }}% tall</span>
268
351
  </div>
269
352
  </UiResizablePanel>
270
- <UiResizableHandle with-handle />
353
+ <UiResizableHandle with-handle aria-label="Resize preview" />
271
354
  <UiResizablePanel
272
355
  :default-size="40"
273
356
  :min-size="20"
@@ -284,12 +367,52 @@ export const Vertical: Story = {
284
367
  `,
285
368
  }),
286
369
  parameters: {
370
+ // The play function focuses the handle to resize it with the keyboard.
371
+ chromatic: { disableSnapshot: true },
287
372
  docs: {
288
373
  source: {
289
374
  code: verticalTemplateSource,
290
375
  },
291
376
  },
292
377
  },
378
+ play: async ({ canvasElement, step }) => {
379
+ // Scenario (UiResizable): a vertical group stacks its panels, so the handle
380
+ // advertises a vertical orientation and answers to Up/Down instead of
381
+ // Left/Right.
382
+ const canvas = within(canvasElement);
383
+ const handle = canvas.getByRole('separator', { name: 'Resize preview' });
384
+ const [preview] = getPanels(canvasElement);
385
+
386
+ await step(
387
+ 'interaction: the group and its handle report a vertical orientation',
388
+ async () => {
389
+ await expect(handle).toHaveAttribute('data-orientation', 'vertical');
390
+ await expect(preview).toHaveAttribute('data-panel-size', '60.0');
391
+ },
392
+ );
393
+
394
+ await step(
395
+ 'keyboard: ArrowDown grows the panel above the handle (WCAG 2.1.1)',
396
+ async () => {
397
+ handle.focus();
398
+ await expect(handle).toHaveFocus();
399
+ await userEvent.keyboard('{ArrowDown}');
400
+ await waitFor(async () => {
401
+ await expect(canvas.getByText('70% tall')).toBeVisible();
402
+ });
403
+ },
404
+ );
405
+
406
+ await step(
407
+ 'keyboard: ArrowUp shrinks it again, so the gesture is reversible',
408
+ async () => {
409
+ await userEvent.keyboard('{ArrowUp}');
410
+ await waitFor(async () => {
411
+ await expect(canvas.getByText('60% tall')).toBeVisible();
412
+ });
413
+ },
414
+ );
415
+ },
293
416
  };
294
417
 
295
418
  const collapsibleTemplateSource = `<script setup lang="ts">
@@ -342,7 +465,7 @@ export const Collapsible: Story = {
342
465
  >
343
466
  <div :class="[panelClasses, 'h-full']">Collapsible</div>
344
467
  </UiResizablePanel>
345
- <UiResizableHandle with-handle />
468
+ <UiResizableHandle with-handle aria-label="Resize or collapse sidebar" />
346
469
  <UiResizablePanel :default-size="75" :min-size="30">
347
470
  <div :class="[panelClasses, 'h-full']">Main panel</div>
348
471
  </UiResizablePanel>
@@ -350,12 +473,58 @@ export const Collapsible: Story = {
350
473
  `,
351
474
  }),
352
475
  parameters: {
476
+ // The play function focuses the handle to toggle the panel with Enter.
477
+ chromatic: { disableSnapshot: true },
353
478
  docs: {
354
479
  source: {
355
480
  code: collapsibleTemplateSource,
356
481
  },
357
482
  },
358
483
  },
484
+ play: async ({ canvasElement, step }) => {
485
+ // Scenario (UiResizable): a collapsible sidebar can be stowed and brought
486
+ // back without a pointer — Enter on the handle toggles it, and the panel's
487
+ // state is readable from the DOM rather than inferred from its width.
488
+ const canvas = within(canvasElement);
489
+ const handle = canvas.getByRole('separator', {
490
+ name: 'Resize or collapse sidebar',
491
+ });
492
+ const [sidebar] = getPanels(canvasElement);
493
+
494
+ await step(
495
+ 'interaction: the collapsible panel starts expanded at its default size',
496
+ async () => {
497
+ await expect(sidebar).toHaveAttribute('data-panel-collapsible', 'true');
498
+ await expect(sidebar).toHaveAttribute('data-state', 'expanded');
499
+ await expect(sidebar).toHaveAttribute('data-panel-size', '25.0');
500
+ },
501
+ );
502
+
503
+ await step(
504
+ 'keyboard: Enter collapses the panel to its collapsed size (WCAG 2.1.1)',
505
+ async () => {
506
+ handle.focus();
507
+ await expect(handle).toHaveFocus();
508
+ await userEvent.keyboard('{Enter}');
509
+ // The rendered size is the source of truth here: reka-ui 2.9.2 applies
510
+ // the keyboard toggle through `setLayout` only, so `data-state` lags
511
+ // behind until a pointer-driven resize re-syncs it.
512
+ await waitFor(async () => {
513
+ await expect(sidebar).toHaveAttribute('data-panel-size', '8.0');
514
+ });
515
+ },
516
+ );
517
+
518
+ await step(
519
+ 'keyboard: Enter expands it again, back to its minimum size',
520
+ async () => {
521
+ await userEvent.keyboard('{Enter}');
522
+ await waitFor(async () => {
523
+ await expect(sidebar).toHaveAttribute('data-panel-size', '20.0');
524
+ });
525
+ },
526
+ );
527
+ },
359
528
  };
360
529
 
361
530
  const pixelSizingTemplateSource = `<script setup lang="ts">
@@ -408,7 +577,7 @@ export const PixelSizing: Story = {
408
577
  >
409
578
  <div :class="[panelClasses, 'h-full']">Fixed sidebar</div>
410
579
  </UiResizablePanel>
411
- <UiResizableHandle with-handle />
580
+ <UiResizableHandle with-handle aria-label="Resize fixed sidebar" />
412
581
  <UiResizablePanel>
413
582
  <div :class="[panelClasses, 'h-full']">Flexible content</div>
414
583
  </UiResizablePanel>
@@ -422,4 +591,1045 @@ export const PixelSizing: Story = {
422
591
  },
423
592
  },
424
593
  },
594
+ play: async ({ canvasElement, step }) => {
595
+ // Scenario (UiResizable): with `size-unit="px"` the sidebar is laid out at a
596
+ // real pixel width rather than a share of the group, and its min/max are
597
+ // honoured in the same unit.
598
+ const canvas = within(canvasElement);
599
+ const handle = canvas.getByRole('separator', {
600
+ name: 'Resize fixed sidebar',
601
+ });
602
+ const [sidebar] = getPanels(canvasElement);
603
+
604
+ await step(
605
+ 'interaction: the pixel-sized panel is laid out at roughly its default pixel width',
606
+ async () => {
607
+ // The group converts the px request into a share of its own content
608
+ // box, so the painted width lands a handful of pixels off the nominal
609
+ // 240 once the handle and the group padding are taken out.
610
+ const { width } = sidebar.getBoundingClientRect();
611
+ await expect(width).toBeGreaterThan(220);
612
+ await expect(width).toBeLessThan(250);
613
+ },
614
+ );
615
+
616
+ await step(
617
+ 'interaction: the separator still reports a percentage to assistive tech',
618
+ async () => {
619
+ // Pixel constraints are converted to percentages for `aria-value*`, so
620
+ // the reported value stays inside the 160–320px window.
621
+ await waitFor(async () => {
622
+ await expect(handle).toHaveAttribute('aria-valuenow');
623
+ });
624
+ const groupWidth = canvasElement.querySelector<HTMLElement>(
625
+ '[data-slot="resizable-panel-group"]',
626
+ )!.clientWidth;
627
+ const valueNow = Number(handle.getAttribute('aria-valuenow'));
628
+ await expect((valueNow / 100) * groupWidth).toBeGreaterThanOrEqual(160);
629
+ await expect((valueNow / 100) * groupWidth).toBeLessThanOrEqual(320);
630
+ },
631
+ );
632
+ },
633
+ };
634
+
635
+ const plainHandleTemplateSource = `<script setup lang="ts">
636
+ import {
637
+ UiResizableHandle,
638
+ UiResizablePanel,
639
+ UiResizablePanelGroup,
640
+ } from '@aleph-alpha/ui-library'
641
+ </script>
642
+
643
+ <template>
644
+ <UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
645
+ <UiResizablePanel :default-size="50">
646
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
647
+ Left
648
+ </div>
649
+ </UiResizablePanel>
650
+ <UiResizableHandle aria-label="Resize left panel" />
651
+ <UiResizablePanel :default-size="50">
652
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
653
+ Right
654
+ </div>
655
+ </UiResizablePanel>
656
+ </UiResizablePanelGroup>
657
+ </template>`;
658
+
659
+ /**
660
+ * Without `with-handle` the divider is a bare hairline. Use it in dense layouts
661
+ * where the grip would be visual noise — the drag and keyboard affordances are
662
+ * unchanged, only the grip is gone.
663
+ */
664
+ export const PlainHandle: Story = {
665
+ render: () => ({
666
+ components: {
667
+ UiResizableHandle,
668
+ UiResizablePanel,
669
+ UiResizablePanelGroup,
670
+ },
671
+ setup() {
672
+ return { panelClasses };
673
+ },
674
+ template: `
675
+ <UiResizablePanelGroup
676
+ direction="horizontal"
677
+ class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
678
+ >
679
+ <UiResizablePanel :default-size="50">
680
+ <div :class="[panelClasses, 'h-full']">Left</div>
681
+ </UiResizablePanel>
682
+ <UiResizableHandle aria-label="Resize left panel" />
683
+ <UiResizablePanel :default-size="50">
684
+ <div :class="[panelClasses, 'h-full']">Right</div>
685
+ </UiResizablePanel>
686
+ </UiResizablePanelGroup>
687
+ `,
688
+ }),
689
+ parameters: {
690
+ docs: {
691
+ source: {
692
+ code: plainHandleTemplateSource,
693
+ },
694
+ },
695
+ },
696
+ play: async ({ canvasElement, step }) => {
697
+ // Scenario (UiResizable): dropping the grip is a purely visual choice — the
698
+ // divider keeps its separator semantics and stays in the tab order.
699
+ const canvas = within(canvasElement);
700
+ const handle = canvas.getByRole('separator', {
701
+ name: 'Resize left panel',
702
+ });
703
+
704
+ await step(
705
+ 'interaction: the grip affordance is omitted but the separator remains',
706
+ async () => {
707
+ await expect(handle.querySelector('svg')).toBeNull();
708
+ await expect(handle).toHaveAttribute('tabindex', '0');
709
+ },
710
+ );
711
+
712
+ await step(
713
+ 'interaction: it still carries the live size for assistive tech',
714
+ async () => {
715
+ await waitFor(async () => {
716
+ await expect(handle).toHaveAttribute('aria-valuenow', '50');
717
+ });
718
+ },
719
+ );
720
+ },
721
+ };
722
+
723
+ const disabledHandleTemplateSource = `<script setup lang="ts">
724
+ import {
725
+ UiResizableHandle,
726
+ UiResizablePanel,
727
+ UiResizablePanelGroup,
728
+ } from '@aleph-alpha/ui-library'
729
+ </script>
730
+
731
+ <template>
732
+ <UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
733
+ <UiResizablePanel :default-size="40">
734
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
735
+ Locked sidebar
736
+ </div>
737
+ </UiResizablePanel>
738
+ <!--
739
+ disabled only stops the drag and key handlers; the handle keeps
740
+ tabindex="0", so pass :tabindex="-1" to take it out of the tab order
741
+ as well.
742
+ -->
743
+ <UiResizableHandle disabled :tabindex="-1" aria-label="Resize locked sidebar" />
744
+ <UiResizablePanel :default-size="60">
745
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
746
+ Content
747
+ </div>
748
+ </UiResizablePanel>
749
+ </UiResizablePanelGroup>
750
+ </template>`;
751
+
752
+ /**
753
+ * A locked split: the handle is rendered for continuity but neither drag nor
754
+ * arrow keys change the layout. Pair `disabled` with `:tabindex="-1"` so the
755
+ * inert handle is not a dead stop in the tab order.
756
+ */
757
+ export const DisabledHandle: Story = {
758
+ render: () => ({
759
+ components: {
760
+ UiResizableHandle,
761
+ UiResizablePanel,
762
+ UiResizablePanelGroup,
763
+ },
764
+ setup() {
765
+ return { panelClasses };
766
+ },
767
+ template: `
768
+ <UiResizablePanelGroup
769
+ direction="horizontal"
770
+ class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
771
+ >
772
+ <UiResizablePanel :default-size="40">
773
+ <div :class="[panelClasses, 'h-full']">Locked sidebar</div>
774
+ </UiResizablePanel>
775
+ <UiResizableHandle
776
+ disabled
777
+ :tabindex="-1"
778
+ aria-label="Resize locked sidebar"
779
+ />
780
+ <UiResizablePanel :default-size="60">
781
+ <div :class="[panelClasses, 'h-full']">Content</div>
782
+ </UiResizablePanel>
783
+ </UiResizablePanelGroup>
784
+ `,
785
+ }),
786
+ parameters: {
787
+ // The play function focuses the handle to prove the key handler is gone.
788
+ chromatic: { disableSnapshot: true },
789
+ docs: {
790
+ source: {
791
+ code: disabledHandleTemplateSource,
792
+ },
793
+ },
794
+ },
795
+ play: async ({ canvasElement, step }) => {
796
+ // Scenario (UiResizable): a locked split must not move. The handle reports
797
+ // its disabled state, is skipped by Tab, and swallows both arrow keys and
798
+ // forced pointer presses.
799
+ const canvas = within(canvasElement);
800
+ const handle = canvas.getByRole('separator', {
801
+ name: 'Resize locked sidebar',
802
+ });
803
+ const [sidebar] = getPanels(canvasElement);
804
+
805
+ await step(
806
+ 'interaction: the handle reports its disabled state',
807
+ async () => {
808
+ await expect(handle).toHaveAttribute('data-disabled');
809
+ await expect(handle).toHaveAttribute(
810
+ 'data-panel-resize-handle-enabled',
811
+ 'false',
812
+ );
813
+ },
814
+ );
815
+
816
+ await step(
817
+ 'keyboard: removed from the tab order — not reachable via Tab (WCAG 2.1.1)',
818
+ async () => {
819
+ await userEvent.tab();
820
+ await expect(handle).not.toHaveFocus();
821
+ },
822
+ );
823
+
824
+ await step(
825
+ 'interaction: arrow keys leave the layout untouched',
826
+ async () => {
827
+ handle.focus();
828
+ await userEvent.keyboard('{ArrowRight}{ArrowRight}');
829
+ await expect(sidebar).toHaveAttribute('data-panel-size', '40.0');
830
+ },
831
+ );
832
+ },
833
+ };
834
+
835
+ const threePanelsTemplateSource = `<script setup lang="ts">
836
+ import {
837
+ UiResizableHandle,
838
+ UiResizablePanel,
839
+ UiResizablePanelGroup,
840
+ } from '@aleph-alpha/ui-library'
841
+ </script>
842
+
843
+ <template>
844
+ <UiResizablePanelGroup direction="horizontal" class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
845
+ <UiResizablePanel :default-size="25" :min-size="15">
846
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
847
+ Navigation
848
+ </div>
849
+ </UiResizablePanel>
850
+ <UiResizableHandle with-handle aria-label="Resize navigation" />
851
+ <UiResizablePanel :default-size="50" :min-size="20">
852
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
853
+ Editor
854
+ </div>
855
+ </UiResizablePanel>
856
+ <UiResizableHandle with-handle aria-label="Resize editor" />
857
+ <UiResizablePanel :default-size="25" :min-size="15">
858
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
859
+ Inspector
860
+ </div>
861
+ </UiResizablePanel>
862
+ </UiResizablePanelGroup>
863
+ </template>`;
864
+
865
+ /**
866
+ * Three panels and two handles — the shape of an editor layout. Give each
867
+ * handle its own name so the two separators can be told apart by voice control
868
+ * and in a screen reader's element list.
869
+ */
870
+ export const ThreePanels: Story = {
871
+ render: () => ({
872
+ components: {
873
+ UiResizableHandle,
874
+ UiResizablePanel,
875
+ UiResizablePanelGroup,
876
+ },
877
+ setup() {
878
+ return { onLayout, panelClasses };
879
+ },
880
+ template: `
881
+ <UiResizablePanelGroup
882
+ direction="horizontal"
883
+ class="min-h-64 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
884
+ @layout="onLayout"
885
+ >
886
+ <UiResizablePanel :default-size="25" :min-size="15">
887
+ <div :class="[panelClasses, 'h-full']">Navigation</div>
888
+ </UiResizablePanel>
889
+ <UiResizableHandle with-handle aria-label="Resize navigation" />
890
+ <UiResizablePanel :default-size="50" :min-size="20">
891
+ <div :class="[panelClasses, 'h-full']">Editor</div>
892
+ </UiResizablePanel>
893
+ <UiResizableHandle with-handle aria-label="Resize editor" />
894
+ <UiResizablePanel :default-size="25" :min-size="15">
895
+ <div :class="[panelClasses, 'h-full']">Inspector</div>
896
+ </UiResizablePanel>
897
+ </UiResizablePanelGroup>
898
+ `,
899
+ }),
900
+ parameters: {
901
+ docs: {
902
+ source: {
903
+ code: threePanelsTemplateSource,
904
+ },
905
+ },
906
+ },
907
+ play: async ({ canvasElement, step }) => {
908
+ // Scenario (UiResizable): a three-way split wires one separator per seam,
909
+ // each controlling the panel before it, and the group reports the whole
910
+ // layout as a single array.
911
+ const canvas = within(canvasElement);
912
+ const panels = getPanels(canvasElement);
913
+ const handles = getHandles(canvasElement);
914
+
915
+ await step(
916
+ 'interaction: every seam gets its own separator, controlling the panel before it',
917
+ async () => {
918
+ await expect(handles).toHaveLength(2);
919
+ await waitFor(async () => {
920
+ await expect(handles[0]).toHaveAttribute(
921
+ 'aria-controls',
922
+ panels[0].getAttribute('data-panel-id'),
923
+ );
924
+ });
925
+ await expect(handles[1]).toHaveAttribute(
926
+ 'aria-controls',
927
+ panels[1].getAttribute('data-panel-id'),
928
+ );
929
+ },
930
+ );
931
+
932
+ await step(
933
+ 'interaction: the group reports the full layout in one emit',
934
+ async () => {
935
+ const lastLayout = onLayout.mock.calls.at(-1)?.[0] as number[];
936
+ await expect(lastLayout).toEqual([25, 50, 25]);
937
+ },
938
+ );
939
+
940
+ await step(
941
+ 'screen-reader: the two separators have distinct accessible names',
942
+ async () => {
943
+ await expect(
944
+ canvas.getByRole('separator', { name: 'Resize navigation' }),
945
+ ).toBeInTheDocument();
946
+ await expect(
947
+ canvas.getByRole('separator', { name: 'Resize editor' }),
948
+ ).toBeInTheDocument();
949
+ },
950
+ );
951
+ },
952
+ };
953
+
954
+ /**
955
+ * Accessibility guidance for naming, operating, and announcing resizable splits.
956
+ */
957
+ export const Accessibility: Story = {
958
+ render: () => ({
959
+ components: {
960
+ UiResizableHandle,
961
+ UiResizablePanel,
962
+ UiResizablePanelGroup,
963
+ },
964
+ setup() {
965
+ return { panelClasses };
966
+ },
967
+ template: `
968
+ <section class="flex flex-col gap-6 p-4">
969
+ <div>
970
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
971
+ Accessibility
972
+ </h2>
973
+ </div>
974
+
975
+ <div class="flex flex-col gap-6">
976
+ <div class="flex flex-col gap-2">
977
+ <h3 class="body-16-medium text-content-on-surface-primary">
978
+ Name every handle
979
+ </h3>
980
+ <p class="body-16-regular text-content-on-surface-primary">
981
+ A handle renders as a focusable <code>separator</code>. Nothing inside it
982
+ is read out, because a separator makes its children presentational, so
983
+ without an <code>aria-label</code> a screen reader announces a bare
984
+ "separator" with a number attached. Name it after the panel it sizes
985
+ ("Resize sidebar"), and give each seam in a multi-panel layout its own
986
+ name so the two can be told apart in an element list or by voice control.
987
+ <br />
988
+ WCAG 2.2:
989
+ <a
990
+ href="https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html"
991
+ target="_blank"
992
+ rel="noopener noreferrer"
993
+ class="text-content-link-default underline"
994
+ >
995
+ 4.1.2 Name, Role, Value
996
+ </a>
997
+ </p>
998
+ </div>
999
+
1000
+ <div class="flex flex-col gap-2">
1001
+ <h3 class="body-16-medium text-content-on-surface-primary">
1002
+ Resizing must never require a pointer
1003
+ </h3>
1004
+ <p class="body-16-regular text-content-on-surface-primary">
1005
+ Tab moves focus onto the handle. Arrow keys along the group's axis then
1006
+ resize by <code>keyboardResizeBy</code> percent per press (hold Shift to
1007
+ jump the full range), Home and End drive the split to either extreme, and
1008
+ F6 cycles between the handles of the same group. On a
1009
+ <code>collapsible</code> panel, Enter toggles collapsed and expanded. Keep
1010
+ <code>keyboardResizeBy</code> coarse enough that a user is not asked to
1011
+ press an arrow thirty times to get anywhere.
1012
+ <br />
1013
+ WCAG 2.2:
1014
+ <a
1015
+ href="https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html"
1016
+ target="_blank"
1017
+ rel="noopener noreferrer"
1018
+ class="text-content-link-default underline"
1019
+ >
1020
+ 2.1.1 Keyboard
1021
+ </a>
1022
+ </p>
1023
+ </div>
1024
+
1025
+ <div class="flex flex-col gap-2">
1026
+ <h3 class="body-16-medium text-content-on-surface-primary">
1027
+ Let the split announce its own state
1028
+ </h3>
1029
+ <p class="body-16-regular text-content-on-surface-primary">
1030
+ The group keeps <code>aria-valuenow</code>, <code>aria-valuemin</code> and
1031
+ <code>aria-valuemax</code> on each handle in sync with the layout, and points
1032
+ <code>aria-controls</code> at the panel being sized, so every resize is
1033
+ announced without a live region of your own. Two things are worth adding
1034
+ by hand: <code>aria-orientation="vertical"</code> on the handles of a
1035
+ horizontal group (a separator is assumed horizontal otherwise), and
1036
+ <code>:tabindex="-1"</code> alongside <code>disabled</code>, since a disabled
1037
+ handle otherwise stays a focusable stop that does nothing.
1038
+ </p>
1039
+ </div>
1040
+
1041
+ <div class="flex flex-col gap-2">
1042
+ <h3 class="body-16-medium text-content-on-surface-primary">
1043
+ Enable accessibility theme
1044
+ </h3>
1045
+ <p class="body-16-regular text-content-on-surface-primary">
1046
+ A hairline divider is the thinnest thing in any layout, so it is the first
1047
+ to disappear against a low-contrast surface and the first place a focus
1048
+ ring gets lost. When accessibility is required, enable our accessibility
1049
+ theme: it raises the contrast of both the divider and its focus ring.
1050
+ </p>
1051
+ </div>
1052
+ </div>
1053
+
1054
+ <div class="grid gap-4 md:grid-cols-2">
1055
+ <div class="flex flex-col gap-3">
1056
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1057
+ Default
1058
+ </h3>
1059
+ <div class="border border-border-surface-default p-4">
1060
+ <UiResizablePanelGroup direction="horizontal" class="min-h-40">
1061
+ <UiResizablePanel :default-size="40">
1062
+ <div :class="[panelClasses, 'h-full']">Sidebar</div>
1063
+ </UiResizablePanel>
1064
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
1065
+ <UiResizablePanel :default-size="60">
1066
+ <div :class="[panelClasses, 'h-full']">Content</div>
1067
+ </UiResizablePanel>
1068
+ </UiResizablePanelGroup>
1069
+ </div>
1070
+ </div>
1071
+
1072
+ <div class="accessible-theme flex flex-col gap-3">
1073
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1074
+ Accessible
1075
+ </h3>
1076
+ <div class="border border-border-surface-default p-4">
1077
+ <UiResizablePanelGroup direction="horizontal" class="min-h-40">
1078
+ <UiResizablePanel :default-size="40">
1079
+ <div :class="[panelClasses, 'h-full']">Sidebar</div>
1080
+ </UiResizablePanel>
1081
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
1082
+ <UiResizablePanel :default-size="60">
1083
+ <div :class="[panelClasses, 'h-full']">Content</div>
1084
+ </UiResizablePanel>
1085
+ </UiResizablePanelGroup>
1086
+ </div>
1087
+ </div>
1088
+ </div>
1089
+ </section>
1090
+ `,
1091
+ }),
1092
+ tags: ['!autodocs'],
1093
+ parameters: {
1094
+ a11y: { test: 'off' },
1095
+ chromatic: {
1096
+ disableSnapshot: true,
1097
+ },
1098
+ docs: {
1099
+ canvas: {
1100
+ sourceState: 'none',
1101
+ },
1102
+ },
1103
+ },
1104
+ };
1105
+
1106
+ const keyboardNavigationTemplateSource = `<script setup lang="ts">
1107
+ import {
1108
+ UiResizableHandle,
1109
+ UiResizablePanel,
1110
+ UiResizablePanelGroup,
1111
+ } from '@aleph-alpha/ui-library'
1112
+ </script>
1113
+
1114
+ <template>
1115
+ <UiResizablePanelGroup
1116
+ direction="horizontal"
1117
+ :keyboard-resize-by="10"
1118
+ class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
1119
+ >
1120
+ <UiResizablePanel :default-size="30" :min-size="10">
1121
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1122
+ Navigation
1123
+ </div>
1124
+ </UiResizablePanel>
1125
+ <UiResizableHandle with-handle aria-label="Resize navigation" />
1126
+ <UiResizablePanel :default-size="40" :min-size="10">
1127
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1128
+ Editor
1129
+ </div>
1130
+ </UiResizablePanel>
1131
+ <UiResizableHandle with-handle aria-label="Resize editor" />
1132
+ <UiResizablePanel :default-size="30" :min-size="10">
1133
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1134
+ Inspector
1135
+ </div>
1136
+ </UiResizablePanel>
1137
+ </UiResizablePanelGroup>
1138
+ </template>`;
1139
+
1140
+ /**
1141
+ * The full keyboard contract of a multi-panel split: Tab reaches each handle,
1142
+ * arrow keys resize by `keyboardResizeBy`, Home and End drive the split to its
1143
+ * limits, and F6 cycles between the handles of the group.
1144
+ */
1145
+ export const KeyboardNavigation: Story = {
1146
+ name: 'test - Keyboard Navigation',
1147
+ tags: ['!dev', '!autodocs'],
1148
+ parameters: {
1149
+ // Focus moves during the play function; skip the visual snapshot so the
1150
+ // focus ring doesn't register as a Chromatic diff.
1151
+ chromatic: { disableSnapshot: true },
1152
+ controls: { disable: true },
1153
+ docs: {
1154
+ description: {
1155
+ story:
1156
+ 'Tab to a handle, then resize with the arrow keys, Home / End, and move between handles with F6.',
1157
+ },
1158
+ source: {
1159
+ code: keyboardNavigationTemplateSource,
1160
+ },
1161
+ },
1162
+ },
1163
+ render: () => ({
1164
+ components: {
1165
+ UiResizableHandle,
1166
+ UiResizablePanel,
1167
+ UiResizablePanelGroup,
1168
+ },
1169
+ setup() {
1170
+ return { onLayout, panelClasses };
1171
+ },
1172
+ template: `
1173
+ <UiResizablePanelGroup
1174
+ direction="horizontal"
1175
+ :keyboard-resize-by="10"
1176
+ class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
1177
+ @layout="onLayout"
1178
+ >
1179
+ <UiResizablePanel :default-size="30" :min-size="10">
1180
+ <div :class="[panelClasses, 'h-full']">Navigation</div>
1181
+ </UiResizablePanel>
1182
+ <UiResizableHandle with-handle aria-label="Resize navigation" />
1183
+ <UiResizablePanel :default-size="40" :min-size="10">
1184
+ <div :class="[panelClasses, 'h-full']">Editor</div>
1185
+ </UiResizablePanel>
1186
+ <UiResizableHandle with-handle aria-label="Resize editor" />
1187
+ <UiResizablePanel :default-size="30" :min-size="10">
1188
+ <div :class="[panelClasses, 'h-full']">Inspector</div>
1189
+ </UiResizablePanel>
1190
+ </UiResizablePanelGroup>
1191
+ `,
1192
+ }),
1193
+ play: async ({ canvasElement, step }) => {
1194
+ // Scenario (UiResizable): a keyboard-only user rebalances an editor layout —
1195
+ // tabbing onto a seam, nudging it with the arrow keys, snapping it to the
1196
+ // extremes, and hopping to the next seam without ever touching a pointer.
1197
+ onLayout.mockClear();
1198
+ const canvas = within(canvasElement);
1199
+ const first = canvas.getByRole('separator', { name: 'Resize navigation' });
1200
+ const second = canvas.getByRole('separator', { name: 'Resize editor' });
1201
+ const [navigation] = getPanels(canvasElement);
1202
+
1203
+ await step(
1204
+ 'keyboard: each handle is reachable via Tab in DOM order (WCAG 2.1.1, 2.4.3)',
1205
+ async () => {
1206
+ await userEvent.tab();
1207
+ await expect(first).toHaveFocus();
1208
+ await userEvent.tab();
1209
+ await expect(second).toHaveFocus();
1210
+ },
1211
+ );
1212
+
1213
+ await step(
1214
+ 'keyboard: ArrowRight grows the panel before the handle by keyboardResizeBy',
1215
+ async () => {
1216
+ first.focus();
1217
+ await userEvent.keyboard('{ArrowRight}');
1218
+ await waitFor(async () => {
1219
+ await expect(navigation).toHaveAttribute('data-panel-size', '40.0');
1220
+ });
1221
+ },
1222
+ );
1223
+
1224
+ await step('keyboard: ArrowLeft shrinks it by the same step', async () => {
1225
+ await userEvent.keyboard('{ArrowLeft}');
1226
+ await waitFor(async () => {
1227
+ await expect(navigation).toHaveAttribute('data-panel-size', '30.0');
1228
+ });
1229
+ });
1230
+
1231
+ await step(
1232
+ 'keyboard: Home and End drive the split to its declared limits',
1233
+ async () => {
1234
+ await userEvent.keyboard('{Home}');
1235
+ await waitFor(async () => {
1236
+ await expect(navigation).toHaveAttribute('data-panel-size', '10.0');
1237
+ });
1238
+ // End pushes every panel after the handle down to its own minimum, so
1239
+ // the first panel takes whatever is left: 100 − 10 − 10.
1240
+ await userEvent.keyboard('{End}');
1241
+ await waitFor(async () => {
1242
+ await expect(navigation).toHaveAttribute('data-panel-size', '80.0');
1243
+ });
1244
+ },
1245
+ );
1246
+
1247
+ await step('keyboard: F6 moves focus to the next handle', async () => {
1248
+ await userEvent.keyboard('{F6}');
1249
+ await expect(second).toHaveFocus();
1250
+ });
1251
+
1252
+ await step(
1253
+ 'interaction: every keyboard resize emits the new layout',
1254
+ async () => {
1255
+ await expect(onLayout).toHaveBeenCalled();
1256
+ const lastLayout = onLayout.mock.calls.at(-1)?.[0] as number[];
1257
+ await expect(lastLayout[0]).toBe(80);
1258
+ await expect(lastLayout.reduce((a, b) => a + b, 0)).toBeCloseTo(100, 5);
1259
+ },
1260
+ );
1261
+ },
1262
+ };
1263
+
1264
+ const screenReaderTemplateSource = `<script setup lang="ts">
1265
+ import {
1266
+ UiResizableHandle,
1267
+ UiResizablePanel,
1268
+ UiResizablePanelGroup,
1269
+ } from '@aleph-alpha/ui-library'
1270
+ </script>
1271
+
1272
+ <template>
1273
+ <UiResizablePanelGroup direction="horizontal" class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
1274
+ <UiResizablePanel :default-size="35" :min-size="20" :max-size="60">
1275
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1276
+ Filters
1277
+ </div>
1278
+ </UiResizablePanel>
1279
+ <!--
1280
+ A separator is assumed horizontal, so the divider of a side-by-side split
1281
+ has to say that it is vertical.
1282
+ -->
1283
+ <UiResizableHandle
1284
+ with-handle
1285
+ aria-label="Resize filters"
1286
+ aria-orientation="vertical"
1287
+ />
1288
+ <UiResizablePanel :default-size="65" :min-size="40">
1289
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1290
+ Results
1291
+ </div>
1292
+ </UiResizablePanel>
1293
+ </UiResizablePanelGroup>
1294
+ </template>`;
1295
+
1296
+ /**
1297
+ * Screen-reader semantics of a split: the handle is a named separator that
1298
+ * carries the live size and its bounds, points at the panel it controls, and
1299
+ * states its own orientation (WCAG 4.1.2).
1300
+ */
1301
+ export const ScreenReader: Story = {
1302
+ name: 'test - Screen Reader',
1303
+ tags: ['!dev', '!autodocs'],
1304
+ parameters: {
1305
+ // The play function focuses the handle and resizes it.
1306
+ chromatic: { disableSnapshot: true },
1307
+ controls: { disable: true },
1308
+ docs: {
1309
+ description: {
1310
+ story:
1311
+ 'Verifies the role, name, orientation, and value that assistive technology announces for a resize handle.',
1312
+ },
1313
+ source: {
1314
+ code: screenReaderTemplateSource,
1315
+ },
1316
+ },
1317
+ },
1318
+ render: () => ({
1319
+ components: {
1320
+ UiResizableHandle,
1321
+ UiResizablePanel,
1322
+ UiResizablePanelGroup,
1323
+ },
1324
+ setup() {
1325
+ return { panelClasses };
1326
+ },
1327
+ template: `
1328
+ <UiResizablePanelGroup
1329
+ direction="horizontal"
1330
+ class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
1331
+ >
1332
+ <UiResizablePanel :default-size="35" :min-size="20" :max-size="60">
1333
+ <div :class="[panelClasses, 'h-full']">Filters</div>
1334
+ </UiResizablePanel>
1335
+ <UiResizableHandle
1336
+ with-handle
1337
+ aria-label="Resize filters"
1338
+ aria-orientation="vertical"
1339
+ />
1340
+ <UiResizablePanel :default-size="65" :min-size="40">
1341
+ <div :class="[panelClasses, 'h-full']">Results</div>
1342
+ </UiResizablePanel>
1343
+ </UiResizablePanelGroup>
1344
+ `,
1345
+ }),
1346
+ play: async ({ canvasElement, step }) => {
1347
+ // Scenario (UiResizable): assistive tech reads the handle as a named
1348
+ // separator with a percentage, hears that percentage change as the user
1349
+ // resizes, and is told which panel the handle belongs to.
1350
+ const canvas = within(canvasElement);
1351
+ const handle = canvas.getByRole('separator', { name: 'Resize filters' });
1352
+ const [filters] = getPanels(canvasElement);
1353
+
1354
+ await step(
1355
+ 'screen-reader: exposes a separator role with an accessible name',
1356
+ async () => {
1357
+ await expect(handle).toHaveAccessibleName('Resize filters');
1358
+ },
1359
+ );
1360
+
1361
+ await step(
1362
+ 'screen-reader: states the orientation of the divider',
1363
+ async () => {
1364
+ await expect(handle).toHaveAttribute('aria-orientation', 'vertical');
1365
+ },
1366
+ );
1367
+
1368
+ await step(
1369
+ 'screen-reader: reports the current size and its bounds (WCAG 4.1.2)',
1370
+ async () => {
1371
+ await waitFor(async () => {
1372
+ await expect(handle).toHaveAttribute('aria-valuenow', '35');
1373
+ });
1374
+ await expect(handle).toHaveAttribute('aria-valuemin', '20');
1375
+ await expect(handle).toHaveAttribute('aria-valuemax', '60');
1376
+ },
1377
+ );
1378
+
1379
+ await step(
1380
+ 'screen-reader: names the panel the handle resizes via aria-controls',
1381
+ async () => {
1382
+ await expect(handle).toHaveAttribute(
1383
+ 'aria-controls',
1384
+ filters.getAttribute('data-panel-id'),
1385
+ );
1386
+ },
1387
+ );
1388
+
1389
+ await step(
1390
+ 'screen-reader: the announced value tracks the resize',
1391
+ async () => {
1392
+ handle.focus();
1393
+ await userEvent.keyboard('{ArrowRight}');
1394
+ await waitFor(async () => {
1395
+ await expect(handle).toHaveAttribute('aria-valuenow', '45');
1396
+ });
1397
+ },
1398
+ );
1399
+ },
1400
+ };
1401
+
1402
+ const zoomMagnificationTemplateSource = `<script setup lang="ts">
1403
+ import {
1404
+ UiResizableHandle,
1405
+ UiResizablePanel,
1406
+ UiResizablePanelGroup,
1407
+ } from '@aleph-alpha/ui-library'
1408
+ </script>
1409
+
1410
+ <template>
1411
+ <UiResizablePanelGroup direction="horizontal" class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
1412
+ <UiResizablePanel :default-size="50" :min-size="20">
1413
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1414
+ Sidebar
1415
+ </div>
1416
+ </UiResizablePanel>
1417
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
1418
+ <UiResizablePanel :default-size="50" :min-size="20">
1419
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1420
+ Content
1421
+ </div>
1422
+ </UiResizablePanel>
1423
+ </UiResizablePanelGroup>
1424
+ </template>`;
1425
+
1426
+ /**
1427
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1428
+ * try 400% reflow (WCAG 1.4.10); the handle must stay visible and resizable.
1429
+ */
1430
+ export const ZoomMagnification: Story = {
1431
+ name: 'test - Zoom Magnification',
1432
+ tags: ['!dev', '!autodocs'],
1433
+ globals: { zoom: '200' },
1434
+ parameters: {
1435
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
1436
+ // already covers magnified snapshots, so skip this one.
1437
+ chromatic: { disableSnapshot: true },
1438
+ controls: { disable: true },
1439
+ docs: {
1440
+ description: {
1441
+ story:
1442
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1443
+ },
1444
+ source: {
1445
+ code: zoomMagnificationTemplateSource,
1446
+ },
1447
+ },
1448
+ },
1449
+ render: () => ({
1450
+ components: {
1451
+ UiResizableHandle,
1452
+ UiResizablePanel,
1453
+ UiResizablePanelGroup,
1454
+ },
1455
+ setup() {
1456
+ return { panelClasses };
1457
+ },
1458
+ template: `
1459
+ <UiResizablePanelGroup
1460
+ direction="horizontal"
1461
+ class="min-h-48 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
1462
+ >
1463
+ <UiResizablePanel :default-size="50" :min-size="20">
1464
+ <div :class="[panelClasses, 'h-full']">Sidebar</div>
1465
+ </UiResizablePanel>
1466
+ <UiResizableHandle with-handle aria-label="Resize sidebar" />
1467
+ <UiResizablePanel :default-size="50" :min-size="20">
1468
+ <div :class="[panelClasses, 'h-full']">Content</div>
1469
+ </UiResizablePanel>
1470
+ </UiResizablePanelGroup>
1471
+ `,
1472
+ }),
1473
+ play: async ({ canvasElement, step }) => {
1474
+ // Scenario (UiResizable): at 200% page zoom the divider is still on screen,
1475
+ // still named, and still answers to the arrow keys — a magnified user must
1476
+ // not lose the only way to rebalance the layout.
1477
+ const canvas = within(canvasElement);
1478
+ const handle = canvas.getByRole('separator', { name: 'Resize sidebar' });
1479
+ const [sidebar] = getPanels(canvasElement);
1480
+
1481
+ await step(
1482
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1483
+ async () => {
1484
+ await expect(document.documentElement.style.zoom).toBe('200%');
1485
+ },
1486
+ );
1487
+
1488
+ await step(
1489
+ 'zoom: both panels and the named handle stay visible',
1490
+ async () => {
1491
+ await expect(canvas.getByText('Sidebar')).toBeVisible();
1492
+ await expect(canvas.getByText('Content')).toBeVisible();
1493
+ await expect(handle).toBeVisible();
1494
+ await expect(handle).toHaveAccessibleName('Resize sidebar');
1495
+ },
1496
+ );
1497
+
1498
+ await step('zoom: remains resizable when magnified', async () => {
1499
+ handle.focus();
1500
+ await userEvent.keyboard('{ArrowLeft}');
1501
+ await waitFor(async () => {
1502
+ await expect(sidebar).toHaveAttribute('data-panel-size', '40.0');
1503
+ });
1504
+ });
1505
+ },
1506
+ };
1507
+
1508
+ const mobileBreakpointTemplateSource = `<script setup lang="ts">
1509
+ import {
1510
+ UiResizableHandle,
1511
+ UiResizablePanel,
1512
+ UiResizablePanelGroup,
1513
+ } from '@aleph-alpha/ui-library'
1514
+ </script>
1515
+
1516
+ <template>
1517
+ <UiResizablePanelGroup direction="vertical" class="h-96 rounded-lg bg-background-surface-secondary p-2 shadow-lg">
1518
+ <UiResizablePanel :default-size="50" :min-size="20">
1519
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1520
+ Map
1521
+ </div>
1522
+ </UiResizablePanel>
1523
+ <UiResizableHandle with-handle aria-label="Resize map" />
1524
+ <UiResizablePanel :default-size="50" :min-size="20">
1525
+ <div class="flex h-full items-center justify-center rounded-md bg-background-surface-muted p-6 body-14-regular">
1526
+ List
1527
+ </div>
1528
+ </UiResizablePanel>
1529
+ </UiResizablePanelGroup>
1530
+ </template>`;
1531
+
1532
+ /**
1533
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1534
+ * toolbar. A narrow screen is where a vertical split earns its keep, so the
1535
+ * group must fit without sideways scrolling and stay operable by touch and key.
1536
+ */
1537
+ export const MobileBreakpoint: Story = {
1538
+ name: 'test - Mobile Breakpoint',
1539
+ tags: ['!dev', '!autodocs'],
1540
+ globals: { mediaBreakpoint: 'reflow' },
1541
+ parameters: {
1542
+ // The play function focuses the handle; reflow snapshots are already
1543
+ // covered by the accessible-reflow mode.
1544
+ chromatic: { disableSnapshot: true },
1545
+ controls: { disable: true },
1546
+ docs: {
1547
+ description: {
1548
+ story:
1549
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1550
+ },
1551
+ source: {
1552
+ code: mobileBreakpointTemplateSource,
1553
+ },
1554
+ },
1555
+ },
1556
+ render: () => ({
1557
+ components: {
1558
+ UiResizableHandle,
1559
+ UiResizablePanel,
1560
+ UiResizablePanelGroup,
1561
+ },
1562
+ setup() {
1563
+ return { panelClasses };
1564
+ },
1565
+ template: `
1566
+ <UiResizablePanelGroup
1567
+ direction="vertical"
1568
+ class="h-96 rounded-lg bg-background-surface-secondary p-2 shadow-lg"
1569
+ >
1570
+ <UiResizablePanel :default-size="50" :min-size="20">
1571
+ <div :class="[panelClasses, 'h-full']">Map</div>
1572
+ </UiResizablePanel>
1573
+ <UiResizableHandle with-handle aria-label="Resize map" />
1574
+ <UiResizablePanel :default-size="50" :min-size="20">
1575
+ <div :class="[panelClasses, 'h-full']">List</div>
1576
+ </UiResizablePanel>
1577
+ </UiResizablePanelGroup>
1578
+ `,
1579
+ }),
1580
+ play: async ({ canvasElement, step }) => {
1581
+ // Scenario (UiResizable): on a 320px screen the split stacks vertically, the
1582
+ // divider is a hairline that is only tappable thanks to the splitter's hit
1583
+ // area, and the keyboard path still works for anyone who cannot hit it.
1584
+ const canvas = within(canvasElement);
1585
+ const handle = canvas.getByRole('separator', { name: 'Resize map' });
1586
+ const [map] = getPanels(canvasElement);
1587
+
1588
+ await step(
1589
+ 'mobile: the story renders at the 320px breakpoint (WCAG 1.4.10 Reflow)',
1590
+ async () => {
1591
+ await expect(document.documentElement.dataset.aaMediaBreakpoint).toBe(
1592
+ 'reflow',
1593
+ );
1594
+ },
1595
+ );
1596
+
1597
+ await step(
1598
+ 'mobile: the split fits without sideways scrolling',
1599
+ async () => {
1600
+ const { scrollWidth, clientWidth } = document.documentElement;
1601
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
1602
+ await expect(handle).toBeVisible();
1603
+ },
1604
+ );
1605
+
1606
+ await step(
1607
+ 'mobile: the effective touch target clears 24px (WCAG 2.5.8)',
1608
+ async () => {
1609
+ // The handle itself is a 1px hairline by design. The splitter registers
1610
+ // a `hitAreaMargins.coarse` band around it for coarse pointers, so the
1611
+ // area a finger can actually hit is the hairline plus that margin on
1612
+ // each side — that is what has to clear 24px, not the painted divider.
1613
+ const { width, height } = handle.getBoundingClientRect();
1614
+ await expect(width + 2 * COARSE_HIT_AREA_MARGIN).toBeGreaterThanOrEqual(
1615
+ 24,
1616
+ );
1617
+ await expect(
1618
+ height + 2 * COARSE_HIT_AREA_MARGIN,
1619
+ ).toBeGreaterThanOrEqual(24);
1620
+ },
1621
+ );
1622
+
1623
+ await step(
1624
+ 'mobile: stays keyboard operable at the narrow breakpoint (WCAG 2.1.1)',
1625
+ async () => {
1626
+ await userEvent.tab();
1627
+ await expect(handle).toHaveFocus();
1628
+ await userEvent.keyboard('{ArrowDown}');
1629
+ await waitFor(async () => {
1630
+ await expect(map).toHaveAttribute('data-panel-size', '60.0');
1631
+ });
1632
+ },
1633
+ );
1634
+ },
425
1635
  };