@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,5 +1,13 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { expect, userEvent, waitFor, within } from 'storybook/test';
3
+ import {
4
+ UiCard,
5
+ UiCardContent,
6
+ UiCardDescription,
7
+ UiCardHeader,
8
+ UiCardTitle,
9
+ } from '../../components/UiCard';
10
+ import { UiRadioGroup, UiRadioGroupItem } from '../../components/UiRadioGroup';
3
11
  import { renderShellWith } from './layout-shell';
4
12
  import UiLayoutContent from './UiLayoutContent.vue';
5
13
 
@@ -683,6 +691,357 @@ export const SidebarMax: Story = {
683
691
  play: sidebarViewPlay(6, 6),
684
692
  };
685
693
 
694
+ /**
695
+ * The switch that owns the arrangement. It sits on the content's own grid, so
696
+ * it rides the column split it is setting, and it writes to the same `layout`
697
+ * ref the bar's toolbar is bound to — picking a mode here moves the bar's
698
+ * pressed state, and pressing the bar moves the selection here.
699
+ *
700
+ * `sidebarMode` only applies while the `sidebar` slot is filled, so its options
701
+ * appear with that mode rather than sitting inert the rest of the time.
702
+ */
703
+ const MODE_SWITCH_CARD = `
704
+ <UiCard class="col-span-full mx-auto w-full max-w-sm bg-background-surface-secondary fixed bottom-10 right-10 z-50">
705
+ <UiCardHeader>
706
+ <UiCardTitle>Content mode</UiCardTitle>
707
+ <UiCardDescription>
708
+ The bar's layout switch and this card share one ref, so the two can
709
+ never disagree about what is rendered.
710
+ </UiCardDescription>
711
+ </UiCardHeader>
712
+ <UiCardContent class="flex flex-col gap-4">
713
+ <UiRadioGroup v-model="layout" name="content-mode" aria-label="Content mode">
714
+ <div class="flex items-center gap-x-2">
715
+ <UiRadioGroupItem id="mode-focus" value="focus" />
716
+ <label for="mode-focus" class="label-14-medium">Focus — twelve columns</label>
717
+ </div>
718
+ <div class="flex items-center gap-x-2">
719
+ <UiRadioGroupItem id="mode-split" value="split" />
720
+ <label for="mode-split" class="label-14-medium">Split — two six-column parts</label>
721
+ </div>
722
+ <div class="flex items-center gap-x-2">
723
+ <UiRadioGroupItem id="mode-sidebar" value="sidebar" />
724
+ <label for="mode-sidebar" class="label-14-medium">Sidebar — secondary content</label>
725
+ </div>
726
+ </UiRadioGroup>
727
+
728
+ <!-- The column split is a property of the sidebar view, so it is offered
729
+ with it instead of standing as a fourth mode. -->
730
+ <UiRadioGroup
731
+ v-if="layout === 'sidebar'"
732
+ v-model="sidebarMode"
733
+ name="sidebar-mode"
734
+ aria-label="Sidebar mode"
735
+ class="border-l border-border-surface-default pl-4"
736
+ >
737
+ <div class="flex items-center gap-x-2">
738
+ <UiRadioGroupItem id="sidebar-default" value="default" />
739
+ <label for="sidebar-default" class="label-14-medium">Default — 8 to 4</label>
740
+ </div>
741
+ <div class="flex items-center gap-x-2">
742
+ <UiRadioGroupItem id="sidebar-wide" value="wide" />
743
+ <label for="sidebar-wide" class="label-14-medium">Wide — 7 to 5</label>
744
+ </div>
745
+ <div class="flex items-center gap-x-2">
746
+ <UiRadioGroupItem id="sidebar-max" value="max" />
747
+ <label for="sidebar-max" class="label-14-medium">Max — 6 to 6</label>
748
+ </div>
749
+ </UiRadioGroup>
750
+
751
+ <!-- The region is replaced without focus moving, so the new arrangement
752
+ is announced rather than changing silently (WCAG 4.1.3). -->
753
+ <p role="status" class="body-12-regular text-content-on-surface-muted">
754
+ {{ layoutStatus }}
755
+ </p>
756
+ </UiCardContent>
757
+ </UiCard>
758
+ `;
759
+
760
+ /**
761
+ * The content column driven by that switch. `UiLayoutContent` reads the mode
762
+ * from which slots are filled, not from a prop, so the conditions sit on the
763
+ * `<template>` elements themselves: a `v-if` *inside* a slot would leave the
764
+ * slot present and the component stuck in that view, rendering an empty area.
765
+ *
766
+ * The overlay keeps drawing the columns of whichever area it is in, so the
767
+ * grid under the card changes with the mode.
768
+ */
769
+ const contentModesTemplate = `
770
+ <!-- the inline --spacing pins the theme's spacing base for the Vitest
771
+ browser project, which serves utilities without the theme preflight.
772
+ The sheet styling drops in the sidebar view, where the primary area
773
+ becomes the sheet and the sidebar stays on the base layer. -->
774
+ <UiLayoutContent
775
+ :id="contentRegionId"
776
+ :sidebar-mode="sidebarMode"
777
+ :class="[
778
+ 'relative min-h-0 min-w-0 flex-1',
779
+ layout === 'sidebar' ? '' : 'overflow-hidden rounded-md shadow-lg',
780
+ ]"
781
+ style="--spacing: 0.25rem"
782
+ >
783
+ <div class="relative h-full min-h-0">
784
+ <div
785
+ class="grid h-full min-h-0 content-center gap-6"
786
+ :class="primaryGridClass"
787
+ >
788
+ ${MODE_SWITCH_CARD}
789
+ </div>
790
+
791
+ <div
792
+ class="pointer-events-none absolute inset-0 grid gap-6"
793
+ :class="primaryGridClass"
794
+ data-layout-grid-columns
795
+ aria-hidden="true"
796
+ >
797
+ <div v-for="n in primaryColumnCount" :key="n" class="bg-red-500/10" />
798
+ </div>
799
+ </div>
800
+
801
+ <template v-if="layout === 'split'" #split>
802
+ ${splitPaneTemplate}
803
+ </template>
804
+
805
+ <template v-if="layout === 'sidebar'" #sidebar>
806
+ <div class="relative h-full min-h-0">
807
+ <div
808
+ class="grid h-full min-h-0 content-center gap-6"
809
+ :class="sidebarGridClass"
810
+ aria-hidden="true"
811
+ >
812
+ <div class="col-span-2 h-4 rounded-md bg-background-surface-muted" />
813
+ <div class="col-span-2 h-24 rounded-md bg-background-surface-muted" />
814
+ <div class="col-span-2 h-24 rounded-md bg-background-surface-muted" />
815
+ <div class="col-span-full h-40 rounded-md bg-background-surface-muted" />
816
+ </div>
817
+
818
+ <div
819
+ class="pointer-events-none absolute inset-0 grid gap-6"
820
+ :class="sidebarGridClass"
821
+ data-layout-grid-columns
822
+ aria-hidden="true"
823
+ >
824
+ <div v-for="n in sidebarColumnCount" :key="n" class="bg-[#00E1FF1A]" />
825
+ </div>
826
+ </div>
827
+ </template>
828
+ </UiLayoutContent>
829
+ `;
830
+
831
+ const contentModesTemplateSource = `<script setup lang="ts">
832
+ import { ref } from 'vue'
833
+ import { UiLayoutContent, UiTopBar } from '@aleph-alpha/ui-library'
834
+
835
+ // one ref for the arrangement; the bar and the content switch both write it
836
+ const layout = ref<'focus' | 'split' | 'sidebar'>('focus')
837
+ const sidebarMode = ref<'default' | 'wide' | 'max'>('default')
838
+ </script>
839
+
840
+ <template>
841
+ <UiTopBar>
842
+ <template #layout-actions>
843
+ <!-- aria-pressed comes from the toolbar once an item declares a value
844
+ inside a v-model group; aria-controls names the region it swaps -->
845
+ <UiFloatActionItems v-model="layout" aria-label="Layout actions">
846
+ <UiFloatActionItems
847
+ type="button"
848
+ value="focus"
849
+ aria-label="Focus layout"
850
+ aria-controls="layout-content"
851
+ >
852
+ <UiIcon name="scan" size="s" />
853
+ </UiFloatActionItems>
854
+ <UiFloatActionItems
855
+ type="button"
856
+ value="split"
857
+ aria-label="Split layout"
858
+ aria-controls="layout-content"
859
+ >
860
+ <UiIcon name="panel-right" size="s" />
861
+ </UiFloatActionItems>
862
+ </UiFloatActionItems>
863
+ </template>
864
+ </UiTopBar>
865
+
866
+ <!-- the mode decides which slots exist: the component reads slot presence,
867
+ so the v-if belongs on the <template>, never inside it -->
868
+ <UiLayoutContent
869
+ id="layout-content"
870
+ :sidebar-mode="sidebarMode"
871
+ class="relative min-h-0 min-w-0 flex-1"
872
+ >
873
+ <ModeSwitchCard v-model:layout="layout" v-model:sidebar-mode="sidebarMode" />
874
+
875
+ <template v-if="layout === 'split'" #split>
876
+ <SecondaryPane />
877
+ </template>
878
+
879
+ <template v-if="layout === 'sidebar'" #sidebar>
880
+ <SecondaryPane />
881
+ </template>
882
+ </UiLayoutContent>
883
+ </template>`;
884
+
885
+ /**
886
+ * Every content mode behind one switch, with the bar's layout actions wired to
887
+ * the same state: the card in the content area is the full list, the bar is a
888
+ * shortcut to the two modes the design puts there, and both read back whatever
889
+ * the other set.
890
+ */
891
+ export const AllContentModes: Story = {
892
+ globals: { mediaBreakpoint: 'default' },
893
+ render: renderShellWith(
894
+ contentModesTemplate,
895
+ {
896
+ UiCard,
897
+ UiCardContent,
898
+ UiCardDescription,
899
+ UiCardHeader,
900
+ UiCardTitle,
901
+ UiLayoutContent,
902
+ UiRadioGroup,
903
+ UiRadioGroupItem,
904
+ },
905
+ true,
906
+ ),
907
+ parameters: {
908
+ // The play switches modes, so the end state is whatever it last picked —
909
+ // the per-mode stories above carry the visual baseline instead.
910
+ chromatic: { disableSnapshot: true },
911
+ docs: {
912
+ description: {
913
+ story:
914
+ 'All content modes behind a single switch. The card in the content area owns the full list — focus, split, and the three sidebar splits — while the bar carries the two modes the design puts in it. Both write the same `layout` ref, so pressing one moves the other.\n\n`UiLayoutContent` decides its mode from which slots are filled rather than from a prop, so the mode conditions sit on the `<template #split>` and `<template #sidebar>` elements themselves. A `v-if` inside a slot would leave the slot present and the component stuck in that view.',
915
+ },
916
+ source: {
917
+ code: contentModesTemplateSource,
918
+ },
919
+ },
920
+ },
921
+ play: async ({ canvasElement, step }) => {
922
+ // Scenario (content modes): a user switches the arrangement from the card
923
+ // in the content area and from the bar, and the two stay in agreement.
924
+ const canvas = within(canvasElement);
925
+ const modeRadio = (name: string | RegExp) =>
926
+ canvas.getByRole('radio', { name });
927
+
928
+ /** The grid overlays on the canvas — one per area the mode renders. */
929
+ const grids = () =>
930
+ Array.from(
931
+ canvasElement.querySelectorAll<HTMLElement>(
932
+ '[data-layout-grid-columns]',
933
+ ),
934
+ );
935
+
936
+ /**
937
+ * Columns drawn by the nth overlay. Throws rather than returning
938
+ * `undefined`, so a missing area fails the step instead of passing it.
939
+ * @param index Which overlay to measure, in document order.
940
+ * @returns How many columns that overlay draws.
941
+ */
942
+ const columnsIn = (index: number) => {
943
+ const grid = grids().at(index);
944
+ if (!grid) throw new Error(`no grid overlay at index ${index}`);
945
+ return grid.children.length;
946
+ };
947
+
948
+ await step(
949
+ 'interaction: the card switches the content area between the three modes',
950
+ async () => {
951
+ // Focus: the twelve columns, and no second area.
952
+ await expect(modeRadio(/^Focus/)).toBeChecked();
953
+ await expect(grids()).toHaveLength(1);
954
+ await expect(columnsIn(0)).toBe(12);
955
+
956
+ // Split and sidebar each add a second area with its own grid.
957
+ await userEvent.click(modeRadio(/^Split/));
958
+ await waitFor(() => expect(grids()).toHaveLength(2));
959
+
960
+ await userEvent.click(modeRadio(/^Sidebar/));
961
+ await waitFor(() => expect(grids()).toHaveLength(2));
962
+ },
963
+ );
964
+
965
+ await step(
966
+ 'interaction: the sidebar split is offered with the sidebar view, and changes its columns',
967
+ async () => {
968
+ await expect(modeRadio(/^Default — 8 to 4/)).toBeChecked();
969
+ await waitFor(() => expect(columnsIn(0)).toBe(8));
970
+ await expect(columnsIn(1)).toBe(4);
971
+
972
+ await userEvent.click(modeRadio(/^Max — 6 to 6/));
973
+ await waitFor(() => {
974
+ expect(columnsIn(0)).toBe(6);
975
+ expect(columnsIn(1)).toBe(6);
976
+ });
977
+ },
978
+ );
979
+
980
+ await step(
981
+ 'interaction: the bar writes the same state, so the card reads back what it set',
982
+ async () => {
983
+ const barSplit = canvas.getByRole('button', { name: 'Split layout' });
984
+
985
+ await userEvent.click(barSplit);
986
+ await waitFor(() => expect(modeRadio(/^Split/)).toBeChecked());
987
+ await expect(barSplit).toHaveAttribute('aria-pressed', 'true');
988
+
989
+ // The sidebar split leaves the switch, since the mode no longer applies.
990
+ await expect(
991
+ canvas.queryByRole('radio', { name: /^Default — 8 to 4/ }),
992
+ ).toBeNull();
993
+ },
994
+ );
995
+
996
+ await step(
997
+ 'keyboard: arrow keys move through the modes and select on arrival',
998
+ async () => {
999
+ await userEvent.click(modeRadio(/^Focus/));
1000
+ await expect(modeRadio(/^Focus/)).toHaveFocus();
1001
+
1002
+ // A radio group is one tab stop with arrow keys inside it, so the whole
1003
+ // switch is operable without a pointer (WCAG 2.1.1). Selection follows
1004
+ // focus, so each arrow swaps the content while this group holds focus;
1005
+ // it keeps focus because the default slot stays in one place in the
1006
+ // DOM across the three modes, leaving the group patched, not remounted.
1007
+ await userEvent.keyboard('{ArrowDown>}');
1008
+ await expect(modeRadio(/^Split/)).toHaveFocus();
1009
+ await waitFor(async () => {
1010
+ await expect(modeRadio(/^Split/)).toBeChecked();
1011
+ });
1012
+
1013
+ await userEvent.keyboard('{ArrowDown>}');
1014
+ await expect(modeRadio(/^Sidebar/)).toHaveFocus();
1015
+ await waitFor(async () => {
1016
+ await expect(modeRadio(/^Sidebar/)).toBeChecked();
1017
+ });
1018
+ },
1019
+ );
1020
+
1021
+ await step(
1022
+ 'screen-reader: the bar names the region it swaps, and the new mode is announced',
1023
+ async () => {
1024
+ const main = canvas.getByRole('main');
1025
+
1026
+ for (const name of ['Focus layout', 'Split layout']) {
1027
+ await expect(canvas.getByRole('button', { name })).toHaveAttribute(
1028
+ 'aria-controls',
1029
+ main.id,
1030
+ );
1031
+ }
1032
+
1033
+ // The status region carries the arrangement, so the swap is not silent.
1034
+ await expect(canvas.getByRole('status')).toHaveTextContent(
1035
+ 'Sidebar view, 6 to 6',
1036
+ );
1037
+ await expect(
1038
+ canvas.getByRole('radiogroup', { name: 'Content mode' }),
1039
+ ).toBeVisible();
1040
+ },
1041
+ );
1042
+ },
1043
+ };
1044
+
686
1045
  /**
687
1046
  * The page of default content a modal demo opens over: the same skeleton the
688
1047
  * grid demo uses, sitting inside the content area behind the backdrop.
@@ -38,6 +38,28 @@ const SIDEBAR_MODE_SPANS: Record<
38
38
  };
39
39
 
40
40
  const sidebarSpans = computed(() => SIDEBAR_MODE_SPANS[props.sidebarMode]);
41
+
42
+ /*
43
+ * The two classes below are read from the render function rather than cached in
44
+ * a `computed`: they depend on slot presence, and `useSlots()` returns a plain
45
+ * object, so a computed would not invalidate when a slot appears or disappears.
46
+ */
47
+ function layoutClass(): string {
48
+ if (slots.sidebar) return 'grid h-full min-h-0 grid-cols-12';
49
+ if (slots.split) return 'grid h-full min-h-0 grid-cols-2';
50
+ return 'contents';
51
+ }
52
+
53
+ function primaryClass(): string {
54
+ if (slots.sidebar) {
55
+ return cn(
56
+ 'min-w-0 rounded-xl bg-background-surface-secondary px-8 lg-min:px-12',
57
+ sidebarSpans.value.content,
58
+ );
59
+ }
60
+ if (slots.split) return 'min-w-0 pr-7';
61
+ return 'contents';
62
+ }
41
63
  </script>
42
64
 
43
65
  <template>
@@ -63,36 +85,36 @@ const sidebarSpans = computed(() => SIDEBAR_MODE_SPANS[props.sidebarMode]);
63
85
  )
64
86
  "
65
87
  >
66
- <!-- The sidebar view: secondary content locked to the right edge, its
67
- share of the 12 columns set by `sidebarMode`. The primary area is the
68
- rounded sheet; the sidebar has no surface of its own. -->
69
- <div v-if="slots.sidebar" class="grid h-full min-h-0 grid-cols-12">
70
- <div
71
- :class="
72
- cn(
73
- 'min-w-0 rounded-xl bg-background-surface-secondary px-8 lg-min:px-12',
74
- sidebarSpans.content,
75
- )
76
- "
77
- >
88
+ <!-- The default slot keeps one position in the DOM across all three views,
89
+ so switching view mode patches the layout instead of remounting the
90
+ content, and scroll position, form state and focus survive the switch.
91
+ In the plain view both wrappers are `display: contents`, so they add
92
+ no layout box of their own. -->
93
+ <div :class="layoutClass()">
94
+ <!-- In the sidebar view the primary area is the rounded sheet; in the
95
+ split view it keeps a 28px margin from the divider. -->
96
+ <div :class="primaryClass()">
78
97
  <slot />
79
98
  </div>
80
- <div :class="cn('min-w-0 px-8 lg-min:px-12', sidebarSpans.sidebar)">
99
+
100
+ <!-- The sidebar view: secondary content locked to the right edge, its
101
+ share of the 12 columns set by `sidebarMode`, with no surface or
102
+ radius of its own. -->
103
+ <div
104
+ v-if="slots.sidebar"
105
+ :class="cn('min-w-0 px-8 lg-min:px-12', sidebarSpans.sidebar)"
106
+ >
81
107
  <slot name="sidebar" />
82
108
  </div>
83
- </div>
84
109
 
85
- <!-- The split view: a border divides the content box into two equal
86
- parts, and each part keeps a 28px margin from it. -->
87
- <div v-else-if="slots.split" class="grid h-full min-h-0 grid-cols-2">
88
- <div class="min-w-0 pr-7">
89
- <slot />
90
- </div>
91
- <div class="min-w-0 border-l border-background-surface-primary pl-7">
110
+ <!-- The split view: a border divides the content box into two equal
111
+ parts, and each part keeps a 28px margin from it. -->
112
+ <div
113
+ v-else-if="slots.split"
114
+ class="min-w-0 border-l border-background-surface-primary pl-7"
115
+ >
92
116
  <slot name="split" />
93
117
  </div>
94
118
  </div>
95
-
96
- <slot v-else />
97
119
  </component>
98
120
  </template>
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { expect, userEvent, waitFor, within } from 'storybook/test';
3
3
  import { mobileTemplateSource, renderMobileShell } from './layout-shell';
4
+ import { ACCESSORY_TRIGGER_NAME } from '../UiTopBar/accessory-dropdown';
4
5
 
5
6
  const meta = {
6
7
  title: 'Patterns/UiLayout/Mobile',
@@ -60,6 +61,18 @@ export const Default: Story = {
60
61
  },
61
62
  );
62
63
 
64
+ await step(
65
+ 'mobile: the accessibility menu the wide bar carries is deliberately absent at 320px (WCAG 1.4.10)',
66
+ async () => {
67
+ // The bar prefers its `mobile-` slots, so the desktop layout-actions
68
+ // region does not reflow onto the phone: it is the pill and the menu
69
+ // button here, and nothing else.
70
+ await expect(
71
+ canvas.queryByRole('button', { name: ACCESSORY_TRIGGER_NAME }),
72
+ ).toBeNull();
73
+ },
74
+ );
75
+
63
76
  await step(
64
77
  'mobile: the menu button meets the minimum touch-target size (WCAG 2.5.8)',
65
78
  async () => {