@aleph-alpha/ui-library 5.4.0 → 5.6.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 (59) hide show
  1. package/config.d.ts +9 -0
  2. package/config.js +12 -3
  3. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  4. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  5. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  6. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +8878 -8692
  13. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
  14. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
  15. package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
  16. package/dist/system/story-sidebar-icons.json +8 -1
  17. package/package.json +5 -3
  18. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
  19. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  20. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  21. package/src/components/UiButton/UiButton.stories.ts +9 -9
  22. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  23. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  24. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  25. package/src/components/UiButtonGroup/index.ts +2 -0
  26. package/src/components/UiButtonGroup/types.ts +21 -0
  27. package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
  28. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
  29. package/src/components/UiField/UiField.stories.ts +608 -1
  30. package/src/components/UiField/UiFieldDescription.vue +7 -2
  31. package/src/components/UiInput/UiInput.stories.ts +336 -2
  32. package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
  33. package/src/components/UiItem/UiItem.stories.ts +236 -1
  34. package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
  35. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  36. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  37. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  38. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  39. package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
  40. package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
  41. package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
  42. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  43. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  44. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  45. package/src/components/core/button-group/index.ts +25 -0
  46. package/src/components/core/checkbox/Checkbox.vue +0 -1
  47. package/src/components/core/select/SelectTrigger.vue +1 -1
  48. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  49. package/src/components/index.ts +1 -0
  50. package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
  51. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  52. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
  53. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
  54. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
  55. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
  56. package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
  57. package/src/patterns/UiFloatActions/types.ts +28 -1
  58. package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
  59. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
@@ -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 {
3
4
  UiField,
4
5
  UiFieldContent,
@@ -27,7 +28,7 @@ import {
27
28
  import { UiSwitch } from '../UiSwitch';
28
29
  import { UiTextarea } from '../UiTextarea';
29
30
  import { UiButton } from '../UiButton';
30
- import { ref } from 'vue';
31
+ import { ref, watch } from 'vue';
31
32
 
32
33
  /**
33
34
  * Field composes label, description, and error messaging into a consistent form-field layout. Use it to keep spacing, typography, and validation feedback consistent across inputs.
@@ -65,6 +66,13 @@ const meta: Meta<typeof UiField> = {
65
66
  export default meta;
66
67
  type Story = StoryObj<typeof UiField>;
67
68
 
69
+ // Event spies for the keyboard form-flow test story. They are bound in the
70
+ // story's `setup()` and asserted from the `play` function; each `play` clears
71
+ // them first so the shared spies stay safe to reuse.
72
+ const onSubmit = fn();
73
+ const onFormInvalid = fn();
74
+ const onCancel = fn();
75
+
68
76
  const defaultTemplateSource = `<script setup lang="ts">
69
77
  import { ref } from 'vue'
70
78
  import {
@@ -128,6 +136,20 @@ export const Default: Story = {
128
136
  parameters: {
129
137
  docs: { source: { code: defaultTemplateSource } },
130
138
  },
139
+ play: async ({ canvasElement, step }) => {
140
+ // Scenario (UiFieldLabel): the label's `for` wiring gives the input its
141
+ // accessible name so assistive tech announces the two together. Non-mutating
142
+ // so the primary snapshot stays stable.
143
+ const canvas = within(canvasElement);
144
+
145
+ await step(
146
+ 'screen-reader: UiFieldLabel names its associated input (WCAG 1.3.1 / 4.1.2)',
147
+ async () => {
148
+ const input = canvas.getByRole('textbox', { name: 'Email' });
149
+ await expect(input).toHaveAccessibleName('Email');
150
+ },
151
+ );
152
+ },
131
153
  };
132
154
 
133
155
  /**
@@ -497,6 +519,23 @@ export const WithLabelInfo: Story = {
497
519
  parameters: {
498
520
  docs: { source: { code: withLabelInfoTemplateSource } },
499
521
  },
522
+ play: async ({ canvasElement, step }) => {
523
+ // Scenario (UiFieldLabelInfo): the info trigger is a real button that
524
+ // exposes the tooltip copy as its accessible name via aria-label.
525
+ const canvas = within(canvasElement);
526
+
527
+ await step(
528
+ 'screen-reader: the label info trigger exposes an accessible name via aria-label (WCAG 4.1.2)',
529
+ async () => {
530
+ const info = canvas.getByRole('button', {
531
+ name: 'Your unique API key for authentication.',
532
+ });
533
+ await expect(info).toHaveAccessibleName(
534
+ 'Your unique API key for authentication.',
535
+ );
536
+ },
537
+ );
538
+ },
500
539
  };
501
540
 
502
541
  const withErrorTemplateSource = `<script setup lang="ts">
@@ -555,6 +594,19 @@ export const WithError: Story = {
555
594
  controls: { disable: true },
556
595
  docs: { source: { code: withErrorTemplateSource } },
557
596
  },
597
+ play: async ({ canvasElement, step }) => {
598
+ // Scenario (UiFieldError): a single error renders inside a role="alert" live
599
+ // region so screen readers announce it.
600
+ const canvas = within(canvasElement);
601
+
602
+ await step(
603
+ 'screen-reader: exposes an alert live region with the error message (WCAG 4.1.3)',
604
+ async () => {
605
+ const alert = canvas.getByRole('alert');
606
+ await expect(alert).toHaveTextContent('Email is required');
607
+ },
608
+ );
609
+ },
558
610
  };
559
611
 
560
612
  const groupTemplateSource = `<script setup lang="ts">
@@ -993,6 +1045,22 @@ export const WithMultipleErrors: Story = {
993
1045
  controls: { disable: true },
994
1046
  docs: { source: { code: multipleErrorsTemplateSource } },
995
1047
  },
1048
+ play: async ({ canvasElement, step }) => {
1049
+ // Scenario (UiFieldError): multiple errors are deduplicated and rendered as
1050
+ // a list inside the alert (3 provided, 1 duplicate -> 2 unique items).
1051
+ const canvas = within(canvasElement);
1052
+
1053
+ await step(
1054
+ 'screen-reader: alert lists the deduplicated errors (WCAG 4.1.3)',
1055
+ async () => {
1056
+ const alert = canvas.getByRole('alert');
1057
+ const items = within(alert).getAllByRole('listitem');
1058
+ await expect(items).toHaveLength(2);
1059
+ await expect(alert).toHaveTextContent('Must be a valid email address');
1060
+ await expect(alert).toHaveTextContent('Domain is not allowed');
1061
+ },
1062
+ );
1063
+ },
996
1064
  };
997
1065
 
998
1066
  const customErrorSlotTemplateSource = `<script setup lang="ts">
@@ -1055,6 +1123,20 @@ export const CustomErrorSlot: Story = {
1055
1123
  controls: { disable: true },
1056
1124
  docs: { source: { code: customErrorSlotTemplateSource } },
1057
1125
  },
1126
+ play: async ({ canvasElement, step }) => {
1127
+ // Scenario (UiFieldError): default slot content takes precedence over the
1128
+ // `errors` prop, and only the slot text is announced.
1129
+ const canvas = within(canvasElement);
1130
+
1131
+ await step(
1132
+ 'interaction: slot content overrides the errors prop inside the alert',
1133
+ async () => {
1134
+ const alert = canvas.getByRole('alert');
1135
+ await expect(alert).toHaveTextContent('Please provide a valid email.');
1136
+ await expect(alert).not.toHaveTextContent('Email is required');
1137
+ },
1138
+ );
1139
+ },
1058
1140
  };
1059
1141
 
1060
1142
  const textareaFieldTemplateSource = `<script setup lang="ts">
@@ -1643,6 +1725,19 @@ export const CheckboxGroup: Story = {
1643
1725
  controls: { disable: true },
1644
1726
  docs: { source: { code: checkboxGroupTemplateSource } },
1645
1727
  },
1728
+ play: async ({ canvasElement, step }) => {
1729
+ // Scenario (UiFieldSet + UiFieldLegend): the fieldset exposes a group whose
1730
+ // accessible name comes from the legend, grouping the related checkboxes.
1731
+ const canvas = within(canvasElement);
1732
+
1733
+ await step(
1734
+ 'screen-reader: the fieldset is a group labelled by its legend (WCAG 1.3.1)',
1735
+ async () => {
1736
+ const group = canvas.getByRole('group', { name: /Tasks/ });
1737
+ await expect(group).toBeInTheDocument();
1738
+ },
1739
+ );
1740
+ },
1646
1741
  };
1647
1742
 
1648
1743
  const responsiveProfileFormTemplateSource = `<script setup lang="ts">
@@ -2126,3 +2221,515 @@ export const PersonalInformationForm: Story = {
2126
2221
  controls: { disable: true },
2127
2222
  },
2128
2223
  };
2224
+
2225
+ /**
2226
+ * `UiFieldDescription` with `variant="input"` renders a real, operable checkbox
2227
+ * next to the description text. Hidden test-only story.
2228
+ */
2229
+ export const DescriptionCheckboxInteraction: Story = {
2230
+ name: 'test - Description Checkbox',
2231
+ tags: ['!dev', '!autodocs'],
2232
+ render: () => ({
2233
+ components: {
2234
+ UiField,
2235
+ UiFieldContent,
2236
+ UiFieldDescription,
2237
+ UiFieldLabel,
2238
+ UiInput,
2239
+ },
2240
+ setup() {
2241
+ const value = ref('');
2242
+ const subscribe = ref(false);
2243
+ return { value, subscribe };
2244
+ },
2245
+ template: `
2246
+ <UiField>
2247
+ <UiFieldLabel for="desc-email">Email</UiFieldLabel>
2248
+ <UiFieldContent>
2249
+ <UiInput id="desc-email" v-model="value" name="email" placeholder="name@company.com" />
2250
+ <UiFieldDescription variant="input" v-model="subscribe" name="newsletter">
2251
+ Subscribe to our newsletter
2252
+ </UiFieldDescription>
2253
+ </UiFieldContent>
2254
+ </UiField>
2255
+ `,
2256
+ }),
2257
+ parameters: {
2258
+ // Clicking toggles state and moves focus; skip the visual snapshot.
2259
+ chromatic: { disableSnapshot: true },
2260
+ docs: {
2261
+ description: {
2262
+ story:
2263
+ 'The input-variant description renders a checkbox that toggles when clicked.',
2264
+ },
2265
+ },
2266
+ },
2267
+ play: async ({ canvasElement, step }) => {
2268
+ // Scenario (UiFieldDescription): the description checkbox is an operable
2269
+ // checkbox that toggles its checked state. (The first checkbox role is the
2270
+ // interactive control; Radix also renders a hidden form input.)
2271
+ const canvas = within(canvasElement);
2272
+ const [checkbox] = canvas.getAllByRole('checkbox');
2273
+
2274
+ await step(
2275
+ 'interaction: renders the description checkbox in its unchecked state',
2276
+ async () => {
2277
+ await expect(checkbox).toHaveAttribute('aria-checked', 'false');
2278
+ },
2279
+ );
2280
+
2281
+ await step(
2282
+ 'interaction: clicking the description checkbox toggles it',
2283
+ async () => {
2284
+ await userEvent.click(checkbox);
2285
+ await expect(checkbox).toHaveAttribute('aria-checked', 'true');
2286
+ },
2287
+ );
2288
+ },
2289
+ };
2290
+
2291
+ /**
2292
+ * Field keyboard order: `Tab` moves through the field's interactive controls in
2293
+ * DOM order — the label info trigger, then the input. Hidden test-only story.
2294
+ */
2295
+ export const KeyboardNavigation: Story = {
2296
+ name: 'test - Keyboard Navigation',
2297
+ tags: ['!dev', '!autodocs'],
2298
+ render: () => ({
2299
+ components: {
2300
+ UiField,
2301
+ UiFieldContent,
2302
+ UiFieldLabel,
2303
+ UiInput,
2304
+ },
2305
+ setup() {
2306
+ const value = ref('');
2307
+ return { value };
2308
+ },
2309
+ template: `
2310
+ <UiField>
2311
+ <UiFieldLabel for="kbd-key" tooltip="Your unique API key.">API Key</UiFieldLabel>
2312
+ <UiFieldContent>
2313
+ <UiInput id="kbd-key" v-model="value" name="apiKey" placeholder="sk-..." />
2314
+ </UiFieldContent>
2315
+ </UiField>
2316
+ `,
2317
+ }),
2318
+ parameters: {
2319
+ // Focus moves during the play function; skip the visual snapshot.
2320
+ chromatic: { disableSnapshot: true },
2321
+ docs: {
2322
+ description: {
2323
+ story:
2324
+ 'Tab moves through the field controls in order: the label info trigger, then the input.',
2325
+ },
2326
+ },
2327
+ },
2328
+ play: async ({ canvasElement, step }) => {
2329
+ // Scenario (UiField): a keyboard user tabs through the field's controls in
2330
+ // DOM order — the label info trigger first, then the input.
2331
+ const canvas = within(canvasElement);
2332
+ const info = canvas.getByRole('button', { name: 'Your unique API key.' });
2333
+ const input = canvas.getByRole('textbox', { name: /API Key/ });
2334
+
2335
+ await step(
2336
+ 'keyboard: Tab reaches the label info trigger first (WCAG 2.1.1)',
2337
+ async () => {
2338
+ await userEvent.tab();
2339
+ await expect(info).toHaveFocus();
2340
+ },
2341
+ );
2342
+
2343
+ await step(
2344
+ 'keyboard: Tab then moves to the input in DOM order (WCAG 2.4.3)',
2345
+ async () => {
2346
+ await userEvent.tab();
2347
+ await expect(input).toHaveFocus();
2348
+ },
2349
+ );
2350
+ },
2351
+ };
2352
+
2353
+ /**
2354
+ * Full keyboard-only walkthrough of a form built from `UiField` primitives,
2355
+ * exercising every submission state — idle, invalid (validation errors),
2356
+ * editing, valid, submitting, success, and reset — without ever using the
2357
+ * mouse. Also asserts that each label is wired to its control and that the
2358
+ * `submit`, `invalid`, and `cancel` events fire. Hidden test-only story.
2359
+ */
2360
+ export const FormKeyboardFlow: Story = {
2361
+ name: 'test - Form Keyboard Flow',
2362
+ tags: ['!dev', '!autodocs'],
2363
+ render: () => ({
2364
+ components: {
2365
+ UiButton,
2366
+ UiCheckbox,
2367
+ UiField,
2368
+ UiFieldContent,
2369
+ UiFieldDescription,
2370
+ UiFieldError,
2371
+ UiFieldGroup,
2372
+ UiFieldLabel,
2373
+ UiFieldLegend,
2374
+ UiFieldSet,
2375
+ UiInput,
2376
+ },
2377
+ setup() {
2378
+ const name = ref('');
2379
+ const email = ref('');
2380
+ const agree = ref(false);
2381
+
2382
+ // Submission lifecycle: idle -> submitting -> success.
2383
+ const status = ref<'idle' | 'submitting' | 'success'>('idle');
2384
+ const attempted = ref(false);
2385
+ const errors = ref<{ name?: string; email?: string; agree?: string }>({});
2386
+
2387
+ function validate() {
2388
+ const next: { name?: string; email?: string; agree?: string } = {};
2389
+ if (!name.value) next.name = 'Name is required';
2390
+ if (!email.value) next.email = 'Email is required';
2391
+ else if (!email.value.includes('@'))
2392
+ next.email = 'Enter a valid email address';
2393
+ if (!agree.value) next.agree = 'You must accept the terms';
2394
+ errors.value = next;
2395
+ return Object.keys(next).length === 0;
2396
+ }
2397
+
2398
+ // After the first submit attempt, validate live so errors clear as the
2399
+ // user fixes each field.
2400
+ watch([name, email, agree], () => {
2401
+ if (attempted.value) validate();
2402
+ });
2403
+
2404
+ async function handleSubmit() {
2405
+ attempted.value = true;
2406
+ if (!validate()) {
2407
+ onFormInvalid({ ...errors.value });
2408
+ return;
2409
+ }
2410
+ status.value = 'submitting';
2411
+ // Simulate an async request so the "submitting" state is observable.
2412
+ await new Promise((resolve) => setTimeout(resolve, 0));
2413
+ status.value = 'success';
2414
+ onSubmit({
2415
+ name: name.value,
2416
+ email: email.value,
2417
+ agree: agree.value,
2418
+ });
2419
+ }
2420
+
2421
+ function handleCancel() {
2422
+ name.value = '';
2423
+ email.value = '';
2424
+ agree.value = false;
2425
+ errors.value = {};
2426
+ attempted.value = false;
2427
+ status.value = 'idle';
2428
+ onCancel();
2429
+ }
2430
+
2431
+ return {
2432
+ name,
2433
+ email,
2434
+ agree,
2435
+ status,
2436
+ errors,
2437
+ handleSubmit,
2438
+ handleCancel,
2439
+ };
2440
+ },
2441
+ template: `
2442
+ <form class="w-full max-w-md" novalidate @submit.prevent="handleSubmit">
2443
+ <UiFieldGroup>
2444
+ <UiFieldSet>
2445
+ <UiFieldLegend>Contact details</UiFieldLegend>
2446
+ <UiFieldDescription>All fields are required.</UiFieldDescription>
2447
+
2448
+ <UiField>
2449
+ <UiFieldLabel for="kbd-form-name">Full name</UiFieldLabel>
2450
+ <UiFieldContent>
2451
+ <UiInput
2452
+ id="kbd-form-name"
2453
+ v-model="name"
2454
+ name="name"
2455
+ placeholder="Ada Lovelace"
2456
+ :aria-invalid="Boolean(errors.name)"
2457
+ />
2458
+ <UiFieldError :errors="errors.name ? [errors.name] : []" />
2459
+ </UiFieldContent>
2460
+ </UiField>
2461
+
2462
+ <UiField>
2463
+ <UiFieldLabel for="kbd-form-email">Email</UiFieldLabel>
2464
+ <UiFieldContent>
2465
+ <UiInput
2466
+ id="kbd-form-email"
2467
+ v-model="email"
2468
+ name="email"
2469
+ type="email"
2470
+ placeholder="ada@company.com"
2471
+ :aria-invalid="Boolean(errors.email)"
2472
+ />
2473
+ <UiFieldError :errors="errors.email ? [errors.email] : []" />
2474
+ </UiFieldContent>
2475
+ </UiField>
2476
+
2477
+ <UiField orientation="responsive">
2478
+ <!--
2479
+ No native "name": inside a <form>, reka-ui renders a hidden
2480
+ submission <input> nested in the role="checkbox" button. That
2481
+ input isn't aria-hidden, so axe flags "label" (unlabeled control)
2482
+ and "nested-interactive". This form is driven entirely by v-model
2483
+ + @submit.prevent, so the native name is unused.
2484
+ -->
2485
+ <UiCheckbox
2486
+ id="kbd-form-terms"
2487
+ v-model="agree"
2488
+ :aria-invalid="Boolean(errors.agree)"
2489
+ />
2490
+ <UiFieldContent>
2491
+ <UiFieldLabel for="kbd-form-terms" class="font-normal">I accept the terms</UiFieldLabel>
2492
+ <UiFieldError :errors="errors.agree ? [errors.agree] : []" />
2493
+ </UiFieldContent>
2494
+ </UiField>
2495
+ </UiFieldSet>
2496
+
2497
+ <UiField orientation="responsive">
2498
+ <UiButton type="submit" :loading="status === 'submitting'">Submit</UiButton>
2499
+ <UiButton type="button" variant="outline" @click="handleCancel">Cancel</UiButton>
2500
+ </UiField>
2501
+
2502
+ <p
2503
+ v-if="status === 'success'"
2504
+ role="status"
2505
+ class="body-14-regular text-content-on-surface-primary"
2506
+ >
2507
+ Your details were saved.
2508
+ </p>
2509
+ </UiFieldGroup>
2510
+ </form>
2511
+ `,
2512
+ }),
2513
+ parameters: {
2514
+ // The play function types, toggles, and moves focus across every state, so
2515
+ // skip the visual snapshot.
2516
+ chromatic: { disableSnapshot: true },
2517
+ docs: {
2518
+ description: {
2519
+ story:
2520
+ 'Keyboard-only walkthrough covering the full submission lifecycle: ' +
2521
+ 'idle, invalid, editing, valid, submitting, success, and reset.',
2522
+ },
2523
+ },
2524
+ },
2525
+ play: async ({ canvasElement, step }) => {
2526
+ onSubmit.mockClear();
2527
+ onFormInvalid.mockClear();
2528
+ onCancel.mockClear();
2529
+ const canvas = within(canvasElement);
2530
+
2531
+ const nameInput = canvas.getByRole('textbox', { name: 'Full name' });
2532
+ const emailInput = canvas.getByRole('textbox', { name: 'Email' });
2533
+ const terms = canvas.getByRole('checkbox', { name: 'I accept the terms' });
2534
+ const submit = canvas.getByRole('button', { name: 'Submit' });
2535
+ const cancel = canvas.getByRole('button', { name: 'Cancel' });
2536
+
2537
+ await step(
2538
+ 'screen-reader: every control is labelled by its field label (WCAG 1.3.1 / 4.1.2)',
2539
+ async () => {
2540
+ await expect(nameInput).toHaveAccessibleName('Full name');
2541
+ await expect(emailInput).toHaveAccessibleName('Email');
2542
+ await expect(terms).toHaveAccessibleName('I accept the terms');
2543
+ },
2544
+ );
2545
+
2546
+ await step(
2547
+ 'keyboard: Tab moves through the form controls in DOM order (WCAG 2.4.3)',
2548
+ async () => {
2549
+ await userEvent.tab();
2550
+ await expect(nameInput).toHaveFocus();
2551
+ await userEvent.tab();
2552
+ await expect(emailInput).toHaveFocus();
2553
+ await userEvent.tab();
2554
+ await expect(terms).toHaveFocus();
2555
+ await userEvent.tab();
2556
+ await expect(submit).toHaveFocus();
2557
+ await userEvent.tab();
2558
+ await expect(cancel).toHaveFocus();
2559
+ },
2560
+ );
2561
+
2562
+ await step(
2563
+ 'keyboard: submitting the empty form surfaces validation errors (invalid state)',
2564
+ async () => {
2565
+ submit.focus();
2566
+ await userEvent.keyboard('{Enter}');
2567
+ await waitFor(() =>
2568
+ expect(canvas.getAllByRole('alert')).toHaveLength(3),
2569
+ );
2570
+ await expect(onSubmit).not.toHaveBeenCalled();
2571
+ await expect(onFormInvalid).toHaveBeenCalledTimes(1);
2572
+ await expect(nameInput).toHaveAttribute('aria-invalid', 'true');
2573
+ },
2574
+ );
2575
+
2576
+ await step(
2577
+ 'keyboard: typing valid values clears their errors (editing state)',
2578
+ async () => {
2579
+ await userEvent.type(nameInput, 'Ada Lovelace');
2580
+ await userEvent.type(emailInput, 'ada@company.com');
2581
+ await expect(nameInput).toHaveValue('Ada Lovelace');
2582
+ await expect(emailInput).toHaveValue('ada@company.com');
2583
+ // Name + email errors clear; only the terms error remains.
2584
+ await waitFor(() =>
2585
+ expect(canvas.getAllByRole('alert')).toHaveLength(1),
2586
+ );
2587
+ await expect(
2588
+ canvas.queryByText('Name is required'),
2589
+ ).not.toBeInTheDocument();
2590
+ },
2591
+ );
2592
+
2593
+ await step(
2594
+ 'keyboard: Space toggles the terms checkbox and clears the last error (valid state)',
2595
+ async () => {
2596
+ terms.focus();
2597
+ await userEvent.keyboard(' ');
2598
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
2599
+ await waitFor(() =>
2600
+ expect(canvas.queryAllByRole('alert')).toHaveLength(0),
2601
+ );
2602
+ },
2603
+ );
2604
+
2605
+ await step(
2606
+ 'keyboard: submitting the valid form fires submit and reaches the success state',
2607
+ async () => {
2608
+ submit.focus();
2609
+ await userEvent.keyboard('{Enter}');
2610
+ await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
2611
+ await expect(onSubmit).toHaveBeenCalledWith({
2612
+ name: 'Ada Lovelace',
2613
+ email: 'ada@company.com',
2614
+ agree: true,
2615
+ });
2616
+ const success = await canvas.findByRole('status');
2617
+ await expect(success).toHaveTextContent('Your details were saved.');
2618
+ },
2619
+ );
2620
+
2621
+ await step(
2622
+ 'keyboard: activating Cancel emits cancel and resets to the idle state',
2623
+ async () => {
2624
+ cancel.focus();
2625
+ await userEvent.keyboard('{Enter}');
2626
+ await expect(onCancel).toHaveBeenCalledTimes(1);
2627
+ await expect(nameInput).toHaveValue('');
2628
+ await waitFor(() =>
2629
+ expect(canvas.queryByRole('status')).not.toBeInTheDocument(),
2630
+ );
2631
+ },
2632
+ );
2633
+ },
2634
+ };
2635
+
2636
+ const mobileBreakpointTemplateSource = `<script setup lang="ts">
2637
+ import { ref } from 'vue'
2638
+ import {
2639
+ UiField,
2640
+ UiFieldLabel,
2641
+ UiFieldContent,
2642
+ UiFieldDescription,
2643
+ UiInput,
2644
+ } from '@aleph-alpha/ui-library'
2645
+
2646
+ const value = ref('')
2647
+ </script>
2648
+
2649
+ <template>
2650
+ <UiField class="w-full max-w-sm">
2651
+ <UiFieldLabel for="mobile-field-email">Email</UiFieldLabel>
2652
+ <UiFieldContent>
2653
+ <UiInput id="mobile-field-email" v-model="value" name="email" placeholder="name@company.com" />
2654
+ <UiFieldDescription>We'll never share your email.</UiFieldDescription>
2655
+ </UiFieldContent>
2656
+ </UiField>
2657
+ </template>`;
2658
+
2659
+ /**
2660
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
2661
+ * toolbar. The field keeps its label wired to the control and stays keyboard
2662
+ * operable and sized for touch at 320px. Hidden test-only story.
2663
+ */
2664
+ export const MobileBreakpoint: Story = {
2665
+ name: 'test - Mobile Breakpoint',
2666
+ tags: ['!dev', '!autodocs'],
2667
+ globals: { mediaBreakpoint: 'reflow' },
2668
+ render: () => ({
2669
+ components: {
2670
+ UiField,
2671
+ UiFieldContent,
2672
+ UiFieldDescription,
2673
+ UiFieldLabel,
2674
+ UiInput,
2675
+ },
2676
+ setup() {
2677
+ const value = ref('');
2678
+ return { value };
2679
+ },
2680
+ template: `
2681
+ <UiField class="w-full max-w-sm">
2682
+ <UiFieldLabel for="mobile-field-email">Email</UiFieldLabel>
2683
+ <UiFieldContent>
2684
+ <UiInput id="mobile-field-email" v-model="value" name="email" placeholder="name@company.com" />
2685
+ <UiFieldDescription>We'll never share your email.</UiFieldDescription>
2686
+ </UiFieldContent>
2687
+ </UiField>
2688
+ `,
2689
+ }),
2690
+ parameters: {
2691
+ // The play function focuses the input and types; skip the visual snapshot.
2692
+ chromatic: { disableSnapshot: true },
2693
+ docs: {
2694
+ description: {
2695
+ story:
2696
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
2697
+ },
2698
+ source: { code: mobileBreakpointTemplateSource },
2699
+ },
2700
+ },
2701
+ play: async ({ canvasElement, step }) => {
2702
+ // Scenario (UiFieldLabel): at the 320px mobile breakpoint the field label stays wired to
2703
+ // the input, which remains keyboard operable and sized for touch.
2704
+ const canvas = within(canvasElement);
2705
+ const input = canvas.getByRole('textbox', { name: 'Email' });
2706
+
2707
+ await step(
2708
+ 'mobile: UiFieldLabel still names its input at the 320px breakpoint (WCAG 1.3.1 / 4.1.2)',
2709
+ async () => {
2710
+ await expect(input).toBeVisible();
2711
+ await expect(input).toBeEnabled();
2712
+ await expect(input).toHaveAccessibleName('Email');
2713
+ },
2714
+ );
2715
+
2716
+ await step(
2717
+ 'mobile: stays keyboard operable — Tab focuses and typing updates the value (WCAG 2.1.1)',
2718
+ async () => {
2719
+ await userEvent.tab();
2720
+ await expect(input).toHaveFocus();
2721
+ await userEvent.type(input, 'ada@company.com');
2722
+ await expect(input).toHaveValue('ada@company.com');
2723
+ },
2724
+ );
2725
+
2726
+ await step(
2727
+ 'mobile: meets the minimum touch-target size (WCAG 2.5.8)',
2728
+ async () => {
2729
+ const { width, height } = input.getBoundingClientRect();
2730
+ await expect(width).toBeGreaterThanOrEqual(24);
2731
+ await expect(height).toBeGreaterThanOrEqual(24);
2732
+ },
2733
+ );
2734
+ },
2735
+ };
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, inject, ref } from 'vue';
2
+ import { computed, inject, ref, useId } from 'vue';
3
3
  import { FieldDescription as ShadcnFieldDescription } from '@/components/core/field';
4
4
  import { UiCheckbox } from '@/components/UiCheckbox';
5
5
  import type { UiFieldDescriptionProps } from './types';
@@ -22,6 +22,10 @@ const showCheckbox = computed(
22
22
  );
23
23
 
24
24
  const checked = defineModel<UiCheckboxModelValue>();
25
+
26
+ // Associate the slotted text with the checkbox so assistive tech derives the
27
+ // accessible name from the visible label (and clicking the text toggles it).
28
+ const checkboxId = useId();
25
29
  </script>
26
30
 
27
31
  <template>
@@ -31,10 +35,11 @@ const checked = defineModel<UiCheckboxModelValue>();
31
35
 
32
36
  <ShadcnFieldDescription v-else class="flex items-center gap-2">
33
37
  <UiCheckbox
38
+ :id="checkboxId"
34
39
  v-model="checked"
35
40
  :name="props.name ?? ''"
36
41
  :disabled="props.disabled"
37
42
  />
38
- <span><slot /></span>
43
+ <label :for="checkboxId"><slot /></label>
39
44
  </ShadcnFieldDescription>
40
45
  </template>