@aleph-alpha/ui-library 7.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
  2. package/dist/system/components/UiSlider/types.d.ts +28 -0
  3. package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
  4. package/dist/system/icons/story-sidebar-icons.json +74 -17
  5. package/dist/system/lib.js +2026 -1912
  6. package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
  7. package/dist/system/story-sidebar-icons.json +74 -17
  8. package/package.json +15 -10
  9. package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
  10. package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
  11. package/src/components/UiAlert/UiAlert.guidance.md +66 -0
  12. package/src/components/UiAlert/UiAlert.stories.ts +167 -143
  13. package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
  14. package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
  15. package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
  17. package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
  18. package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
  19. package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
  20. package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
  21. package/src/components/UiBadge/UiBadge.guidance.md +65 -0
  22. package/src/components/UiBadge/UiBadge.stories.ts +325 -0
  23. package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
  24. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
  25. package/src/components/UiButton/UiButton.stories.ts +5 -2
  26. package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
  27. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
  28. package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
  29. package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
  30. package/src/components/UiCard/UiCard.guidance.md +65 -0
  31. package/src/components/UiCard/UiCard.stories.ts +393 -0
  32. package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
  33. package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
  34. package/src/components/UiChip/UiChip.guidance.md +64 -0
  35. package/src/components/UiChip/UiChip.stories.ts +162 -138
  36. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
  37. package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
  38. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
  39. package/src/components/UiDialog/UiDialog.guidance.md +66 -0
  40. package/src/components/UiDialog/UiDialog.stories.ts +90 -66
  41. package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
  42. package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
  43. package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
  44. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +127 -86
  45. package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
  46. package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
  47. package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
  48. package/src/components/UiField/UiField.guidance.md +63 -0
  49. package/src/components/UiField/UiField.stories.ts +90 -113
  50. package/src/components/UiFileType/UiFileType.stories.ts +254 -0
  51. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
  52. package/src/components/UiIcon/UiIcon.stories.ts +256 -1
  53. package/src/components/UiInput/UiInput.guidance.md +64 -0
  54. package/src/components/UiInput/UiInput.stories.ts +132 -80
  55. package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
  56. package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
  57. package/src/components/UiItem/UiItem.guidance.md +66 -0
  58. package/src/components/UiItem/UiItem.stories.ts +81 -28
  59. package/src/components/UiKbd/UiKbd.guidance.md +65 -0
  60. package/src/components/UiKbd/UiKbd.stories.ts +373 -3
  61. package/src/components/UiLabel/UiLabel.guidance.md +65 -0
  62. package/src/components/UiLabel/UiLabel.stories.ts +163 -139
  63. package/src/components/UiListbox/UiListbox.stories.ts +197 -195
  64. package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
  65. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
  66. package/src/components/UiPopover/UiPopover.guidance.md +65 -0
  67. package/src/components/UiPopover/UiPopover.stories.ts +115 -91
  68. package/src/components/UiProgress/UiProgress.guidance.md +65 -0
  69. package/src/components/UiProgress/UiProgress.stories.ts +300 -0
  70. package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
  71. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
  72. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
  73. package/src/components/UiResizable/UiResizable.guidance.md +65 -0
  74. package/src/components/UiResizable/UiResizable.stories.ts +176 -152
  75. package/src/components/UiSelect/UiSelect.guidance.md +66 -0
  76. package/src/components/UiSelect/UiSelect.stories.ts +150 -126
  77. package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
  78. package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
  79. package/src/components/UiSheet/UiSheet.guidance.md +66 -0
  80. package/src/components/UiSheet/UiSheet.stories.ts +194 -170
  81. package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
  82. package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
  83. package/src/components/UiSlider/UiSlider.guidance.md +66 -0
  84. package/src/components/UiSlider/UiSlider.stories.ts +885 -153
  85. package/src/components/UiSlider/UiSlider.vue +109 -1
  86. package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
  87. package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
  88. package/src/components/UiSlider/step-marks.ts +96 -0
  89. package/src/components/UiSlider/types.ts +32 -0
  90. package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
  91. package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
  92. package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
  93. package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
  94. package/src/components/UiStepper/UiStepper.guidance.md +66 -0
  95. package/src/components/UiStepper/UiStepper.stories.ts +142 -124
  96. package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
  97. package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
  98. package/src/components/UiTable/UiTable.guidance.md +66 -0
  99. package/src/components/UiTable/UiTable.stories.ts +530 -12
  100. package/src/components/UiTabs/UiTabs.guidance.md +66 -0
  101. package/src/components/UiTabs/UiTabs.stories.ts +174 -150
  102. package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
  103. package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
  104. package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
  105. package/src/components/UiToggle/UiToggle.guidance.md +66 -0
  106. package/src/components/UiToggle/UiToggle.stories.ts +183 -159
  107. package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
  108. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
  109. package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
  110. package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
  111. package/src/components/core/slider/Slider.vue +16 -6
  112. package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
  113. package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
  114. package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
  115. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
  116. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
  117. package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
  118. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
  119. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
  120. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
  121. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
  122. package/src/patterns/UiPlaceholder/types.ts +1 -0
  123. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +86 -84
  124. package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, within } from 'storybook/test';
2
3
  import { ref, onMounted, onUnmounted } from 'vue';
3
4
  import UiKbd from './UiKbd.vue';
4
5
  import UiKbdGroup from './UiKbdGroup.vue';
@@ -18,6 +19,15 @@ import {
18
19
  UiDrawerHeader,
19
20
  UiDrawerTitle,
20
21
  } from '../UiDrawer';
22
+ import {
23
+ accessibilityStory,
24
+ designNotesStory,
25
+ guidanceLinks,
26
+ parseGuidance,
27
+ } from '../../../.storybook/guidance';
28
+ import guidanceMarkdown from './UiKbd.guidance.md?raw';
29
+
30
+ const guidance = parseGuidance(guidanceMarkdown);
21
31
 
22
32
  /**
23
33
  * UiKbd renders a keyboard key or shortcut combination (e.g. `⌘ K`, `Ctrl + S`).
@@ -37,12 +47,19 @@ const meta: Meta<typeof UiKbd> = {
37
47
  args: {
38
48
  size: 'default',
39
49
  },
50
+ parameters: {
51
+ docs: { links: guidanceLinks(guidance) },
52
+ },
40
53
  };
41
54
 
42
55
  export default meta;
43
56
 
44
57
  type Story = StoryObj<typeof UiKbd>;
45
58
 
59
+ const onAccept = fn();
60
+ const onCancel = fn();
61
+ const onSearch = fn();
62
+
46
63
  const defaultTemplateSource = `<script setup lang="ts">
47
64
  import { UiKbd, UiKbdGroup } from '@aleph-alpha/ui-library'
48
65
  </script>
@@ -100,6 +117,35 @@ export const Default: Story = {
100
117
  },
101
118
  };
102
119
 
120
+ /**
121
+ * Usage, guidelines, and do's and don'ts from the Figma documentation.
122
+ */
123
+ export const DesignNotes: Story = {
124
+ ...designNotesStory(guidance),
125
+ tags: ['!autodocs'],
126
+ };
127
+
128
+ /**
129
+ * Accessibility guidance from the Figma documentation, with the component in
130
+ * the default and accessible themes.
131
+ */
132
+ export const Accessibility: Story = {
133
+ ...accessibilityStory({
134
+ requirements: guidance.accessibility,
135
+ example: {
136
+ components: { UiKbd, UiKbdGroup },
137
+ template: `
138
+ <UiKbdGroup>
139
+ <UiKbd>Ctrl</UiKbd>
140
+ <span>+</span>
141
+ <UiKbd>K</UiKbd>
142
+ </UiKbdGroup>
143
+ `,
144
+ },
145
+ }),
146
+ tags: ['!autodocs'],
147
+ };
148
+
103
149
  const interactiveTemplateSource = `<script setup lang="ts">
104
150
  import { ref, onMounted, onUnmounted } from 'vue'
105
151
  import { UiKbd, UiKbdGroup, UiButton, UiDrawer, UiDrawerContent, UiDrawerHeader, UiDrawerTitle, UiDrawerDescription, UiDrawerFooter, UiDrawerClose } from '@aleph-alpha/ui-library'
@@ -406,14 +452,14 @@ export const Button: Story = {
406
452
  render: (args) => ({
407
453
  components: { UiKbd, UiButton },
408
454
  setup() {
409
- return { args };
455
+ return { args, onAccept, onCancel };
410
456
  },
411
457
  template: `
412
458
  <div class="flex flex-wrap items-center gap-4">
413
- <UiButton variant="outline" size="sm" class="pr-2">
459
+ <UiButton variant="outline" size="sm" class="pr-2" @click="onAccept">
414
460
  Accept <UiKbd v-bind="args">⏎</UiKbd>
415
461
  </UiButton>
416
- <UiButton variant="outline" size="sm" class="pr-2">
462
+ <UiButton variant="outline" size="sm" class="pr-2" @click="onCancel">
417
463
  Cancel <UiKbd v-bind="args">Esc</UiKbd>
418
464
  </UiButton>
419
465
  </div>
@@ -426,6 +472,32 @@ export const Button: Story = {
426
472
  },
427
473
  },
428
474
  },
475
+ play: async ({ canvasElement, step }) => {
476
+ // Scenario (UiKbd): a key hint sits inside its button as a label; the
477
+ // button, not the hint, is what the user activates.
478
+ onAccept.mockClear();
479
+ onCancel.mockClear();
480
+ const canvas = within(canvasElement);
481
+ const accept = canvas.getByRole('button', { name: /Accept/ });
482
+
483
+ await step(
484
+ 'interaction: the key hint is rendered inside its button',
485
+ async () => {
486
+ const hint = canvas.getByText('⏎');
487
+ await expect(hint.tagName).toBe('KBD');
488
+ await expect(accept).toContainElement(hint);
489
+ },
490
+ );
491
+
492
+ await step(
493
+ 'interaction: clicking the button activates only that action',
494
+ async () => {
495
+ await userEvent.click(accept);
496
+ await expect(onAccept).toHaveBeenCalledTimes(1);
497
+ await expect(onCancel).not.toHaveBeenCalled();
498
+ },
499
+ );
500
+ },
429
501
  };
430
502
 
431
503
  const withTooltipTemplateSource = `<script setup lang="ts">
@@ -553,3 +625,301 @@ export const Sizes: Story = {
553
625
  },
554
626
  },
555
627
  };
628
+
629
+ const smallTemplateSource = `<script setup lang="ts">
630
+ import { UiKbd, UiKbdGroup } from '@aleph-alpha/ui-library'
631
+ </script>
632
+
633
+ <template>
634
+ <UiKbdGroup>
635
+ <UiKbd size="sm">Ctrl</UiKbd>
636
+ <UiKbd size="sm">S</UiKbd>
637
+ </UiKbdGroup>
638
+ </template>`;
639
+
640
+ /**
641
+ * Small keys for dense menus and compact tooltips.
642
+ */
643
+ export const Small: Story = {
644
+ render: () => ({
645
+ components: { UiKbd, UiKbdGroup },
646
+ template: `
647
+ <UiKbdGroup>
648
+ <UiKbd size="sm">Ctrl</UiKbd>
649
+ <UiKbd size="sm">S</UiKbd>
650
+ </UiKbdGroup>
651
+ `,
652
+ }),
653
+ parameters: {
654
+ docs: {
655
+ source: {
656
+ code: smallTemplateSource,
657
+ },
658
+ },
659
+ },
660
+ };
661
+
662
+ const largeTemplateSource = `<script setup lang="ts">
663
+ import { UiKbd, UiKbdGroup } from '@aleph-alpha/ui-library'
664
+ </script>
665
+
666
+ <template>
667
+ <UiKbdGroup>
668
+ <UiKbd size="lg">Ctrl</UiKbd>
669
+ <UiKbd size="lg">S</UiKbd>
670
+ </UiKbdGroup>
671
+ </template>`;
672
+
673
+ /**
674
+ * Large keys for onboarding hints and empty states.
675
+ */
676
+ export const Large: Story = {
677
+ render: () => ({
678
+ components: { UiKbd, UiKbdGroup },
679
+ template: `
680
+ <UiKbdGroup>
681
+ <UiKbd size="lg">Ctrl</UiKbd>
682
+ <UiKbd size="lg">S</UiKbd>
683
+ </UiKbdGroup>
684
+ `,
685
+ }),
686
+ parameters: {
687
+ docs: {
688
+ source: {
689
+ code: largeTemplateSource,
690
+ },
691
+ },
692
+ },
693
+ };
694
+
695
+ const renderTestShortcuts = () => ({
696
+ components: { UiButton, UiKbd, UiKbdGroup },
697
+ setup() {
698
+ return { onSearch };
699
+ },
700
+ template: `
701
+ <div class="flex flex-col items-start gap-4">
702
+ <p class="body-m-regular">
703
+ Press
704
+ <UiKbdGroup>
705
+ <UiKbd>Ctrl</UiKbd>
706
+ <span>+</span>
707
+ <UiKbd>K</UiKbd>
708
+ </UiKbdGroup>
709
+ to search.
710
+ </p>
711
+ <UiButton variant="outline" size="sm" class="pr-2" @click="onSearch">
712
+ Search <UiKbd size="sm">/</UiKbd>
713
+ </UiButton>
714
+ </div>
715
+ `,
716
+ });
717
+
718
+ /**
719
+ * Key hints describe a shortcut; they are not controls, so focus skips them
720
+ * and lands on the real button. Hidden test-only story.
721
+ */
722
+ export const KeyboardNavigation: Story = {
723
+ name: 'test - Keyboard Navigation',
724
+ tags: ['!dev', '!autodocs'],
725
+ parameters: {
726
+ // Focus moves during the play function.
727
+ chromatic: { disableSnapshot: true },
728
+ docs: {
729
+ description: {
730
+ story:
731
+ 'Press `Tab`: focus skips the key hints and lands on the button, which `Enter` activates.',
732
+ },
733
+ },
734
+ },
735
+ render: renderTestShortcuts,
736
+ play: async ({ canvasElement, step }) => {
737
+ // Scenario (UiKbd): a keyboard user tabs past the inline shortcut hint to
738
+ // the only real control, then leaves the example.
739
+ onSearch.mockClear();
740
+ const canvas = within(canvasElement);
741
+ const search = canvas.getByRole('button', { name: /Search/ });
742
+
743
+ await step(
744
+ 'keyboard: Tab skips the key hints and lands on the button',
745
+ async () => {
746
+ await userEvent.tab();
747
+ await expect(search).toHaveFocus();
748
+ },
749
+ );
750
+
751
+ await step('keyboard: Enter activates the focused button', async () => {
752
+ await userEvent.keyboard('{Enter}');
753
+ await expect(onSearch).toHaveBeenCalledTimes(1);
754
+ });
755
+
756
+ await step('keyboard: no key hint carries a tabindex', async () => {
757
+ for (const key of canvasElement.querySelectorAll('kbd')) {
758
+ await expect(key).not.toHaveAttribute('tabindex');
759
+ }
760
+ await userEvent.tab();
761
+ await expect(canvasElement.contains(document.activeElement)).toBe(false);
762
+ });
763
+ },
764
+ };
765
+
766
+ /**
767
+ * What assistive technology reads for a shortcut: each key as `<kbd>` text,
768
+ * in order, inline with the sentence around it. Hidden test-only story.
769
+ */
770
+ export const ScreenReader: Story = {
771
+ name: 'test - Screen Reader',
772
+ tags: ['!dev', '!autodocs'],
773
+ parameters: {
774
+ docs: {
775
+ description: {
776
+ story:
777
+ 'Verifies the keyboard-input semantics and reading order of shortcut hints.',
778
+ },
779
+ },
780
+ },
781
+ render: renderTestShortcuts,
782
+ play: async ({ canvasElement, step }) => {
783
+ // Scenario (UiKbd): a screen-reader user hears "Press Ctrl+K to search"
784
+ // as one sentence, and the hint never poses as a control.
785
+ const canvas = within(canvasElement);
786
+
787
+ await step(
788
+ 'screen-reader: each key is marked up as keyboard input (<kbd>)',
789
+ async () => {
790
+ for (const label of ['Ctrl', 'K', '/']) {
791
+ await expect(canvas.getByText(label).tagName).toBe('KBD');
792
+ }
793
+ },
794
+ );
795
+
796
+ await step(
797
+ 'screen-reader: the shortcut reads inline, in order, with its sentence',
798
+ async () => {
799
+ const sentence = canvas.getByText(/Press/);
800
+ await expect(sentence.textContent?.replace(/\s+/g, ' ').trim()).toBe(
801
+ 'Press Ctrl+K to search.',
802
+ );
803
+ },
804
+ );
805
+
806
+ await step(
807
+ 'screen-reader: key hints expose no control role of their own',
808
+ async () => {
809
+ await expect(canvas.getAllByRole('button')).toHaveLength(1);
810
+ for (const key of canvasElement.querySelectorAll('kbd')) {
811
+ await expect(key).not.toHaveAttribute('role');
812
+ }
813
+ },
814
+ );
815
+
816
+ await step(
817
+ 'screen-reader: a hint inside a button joins the button name',
818
+ async () => {
819
+ await expect(
820
+ canvas.getByRole('button', { name: /Search/ }),
821
+ ).toHaveAccessibleName('Search /');
822
+ },
823
+ );
824
+ },
825
+ };
826
+
827
+ /**
828
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
829
+ * try 400% reflow (WCAG 1.4.10). Hidden test-only story.
830
+ */
831
+ export const ZoomMagnification: Story = {
832
+ name: 'test - Zoom Magnification',
833
+ tags: ['!dev', '!autodocs'],
834
+ globals: { zoom: '200' },
835
+ parameters: {
836
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
837
+ // already covers magnified snapshots, so skip this one.
838
+ chromatic: { disableSnapshot: true },
839
+ docs: {
840
+ description: {
841
+ story:
842
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
843
+ },
844
+ },
845
+ },
846
+ render: renderTestShortcuts,
847
+ play: async ({ canvasElement, step }) => {
848
+ // Scenario (UiKbd): at 200% page zoom every key label stays readable and
849
+ // inside the viewport, and the button with a hint still works.
850
+ onSearch.mockClear();
851
+ const canvas = within(canvasElement);
852
+
853
+ await step(
854
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
855
+ async () => {
856
+ await expect(document.documentElement.style.zoom).toBe('200%');
857
+ },
858
+ );
859
+
860
+ await step('zoom: key labels stay readable and in view', async () => {
861
+ for (const key of canvasElement.querySelectorAll<HTMLElement>('kbd')) {
862
+ await expect(key).toBeVisible();
863
+ const { left, right } = key.getBoundingClientRect();
864
+ await expect(left).toBeGreaterThanOrEqual(0);
865
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
866
+ }
867
+ });
868
+
869
+ await step('zoom: the button remains operable when magnified', async () => {
870
+ await userEvent.click(canvas.getByRole('button', { name: /Search/ }));
871
+ await expect(onSearch).toHaveBeenCalledTimes(1);
872
+ });
873
+ },
874
+ };
875
+
876
+ /**
877
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
878
+ * toolbar. Hidden test-only story.
879
+ */
880
+ export const MobileBreakpoint: Story = {
881
+ name: 'test - Mobile Breakpoint',
882
+ tags: ['!dev', '!autodocs'],
883
+ globals: { mediaBreakpoint: 'reflow' },
884
+ parameters: {
885
+ // Reflow snapshots are already covered by the accessible-reflow mode.
886
+ chromatic: { disableSnapshot: true },
887
+ docs: {
888
+ description: {
889
+ story:
890
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
891
+ },
892
+ },
893
+ },
894
+ render: renderTestShortcuts,
895
+ play: async ({ canvasElement, step }) => {
896
+ // Scenario (UiKbd): at the 320px mobile breakpoint the hint sentence wraps
897
+ // without sideways scrolling, and the button stays big enough to tap.
898
+ const canvas = within(canvasElement);
899
+
900
+ await step('mobile: key hints render at the 320px breakpoint', async () => {
901
+ await expect(canvas.getByText('Ctrl')).toBeVisible();
902
+ await expect(canvas.getByText('K')).toBeVisible();
903
+ });
904
+
905
+ await step(
906
+ 'mobile: the layout fits without sideways scrolling (WCAG 1.4.10 Reflow)',
907
+ async () => {
908
+ const { scrollWidth, clientWidth } = document.documentElement;
909
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
910
+ },
911
+ );
912
+
913
+ await step(
914
+ 'mobile: the control holding a hint meets the target size (WCAG 2.5.8)',
915
+ async () => {
916
+ // Key hints are never targets themselves; the button they sit in is.
917
+ const { width, height } = canvas
918
+ .getByRole('button', { name: /Search/ })
919
+ .getBoundingClientRect();
920
+ await expect(width).toBeGreaterThanOrEqual(24);
921
+ await expect(height).toBeGreaterThanOrEqual(24);
922
+ },
923
+ );
924
+ },
925
+ };
@@ -0,0 +1,65 @@
1
+ ---
2
+ figma: '29199:70732'
3
+ ---
4
+
5
+ <!-- Synced from Figma by scripts/sync-figma-docs.mjs. Edit the copy in Figma: changes made here are overwritten. -->
6
+
7
+ ## Usage
8
+
9
+ The Label component names the control it belongs to. It stays visible while the control is used, so a user who looks away and back can tell what they were entering.
10
+
11
+ Every control gets one. Field owns the layout that puts label, control, description and error together; Label is the naming itself.
12
+
13
+ ### Name the thing, not the action
14
+
15
+ A label describes what the value is:
16
+
17
+ - A noun or a short noun phrase, not an instruction
18
+ - The same wording the product uses elsewhere for the same thing
19
+ - Sentence case, with no trailing colon
20
+ - Short enough to read at a glance, with detail moved to the description
21
+
22
+ ### Always visible, always attached
23
+
24
+ Placement is what makes a label work:
25
+
26
+ 1. Above the control, so it survives once the field is filled
27
+ 2. Beside the control for a checkbox, switch or radio
28
+ 3. Never inside the control as a placeholder
29
+ 4. Close enough to its own control that the pairing is unambiguous
30
+
31
+ ### Consistency
32
+
33
+ Every label follows the same rules:
34
+
35
+ - One label per control, always present
36
+ - Position: above for text controls, beside for choice controls
37
+ - Optional and required marked the same way throughout
38
+ - Description carrying anything the label cannot
39
+
40
+ ## Do
41
+
42
+ - Give every control a visible label
43
+ - Write labels as short noun phrases in sentence case
44
+ - Keep the label above text controls, and beside choice controls
45
+ - Use the same word for the same thing across the product
46
+ - Move guidance to the description rather than lengthening the label
47
+ - Mark optional or required consistently
48
+
49
+ ## Don't
50
+
51
+ - Use a placeholder in place of a label
52
+ - Write a label as an instruction or a question
53
+ - Hide the label once the control is filled
54
+ - End labels with a colon in some places and not others
55
+ - Put two controls under one label
56
+ - Rely on proximity alone where several controls sit close together
57
+
58
+ ## Accessibility
59
+
60
+ - Every control has a visible label; a placeholder is never a substitute
61
+ - The label sits close enough to its control that the pairing is unambiguous, even at wide widths
62
+ - The label is part of the control's target where the system allows it, so it is easier to hit
63
+ - Label text holds its contrast against the surface behind it, including inside cards and panels
64
+ - Required and optional are stated in words or a consistent mark, not by colour
65
+ - The label stays legible when it wraps, and never truncates