@aleph-alpha/ui-library 5.5.0 → 5.7.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 (41) hide show
  1. package/config.js +5 -0
  2. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  3. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  5. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  6. package/dist/system/components/UiField/types.d.ts +2 -1
  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 +7855 -7732
  13. package/dist/system/story-sidebar-icons.json +3 -0
  14. package/package.json +5 -5
  15. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +619 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  17. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  18. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  19. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  20. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  21. package/src/components/UiButtonGroup/index.ts +2 -0
  22. package/src/components/UiButtonGroup/types.ts +21 -0
  23. package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
  24. package/src/components/UiField/UiField.stories.ts +1 -1
  25. package/src/components/UiField/types.ts +2 -1
  26. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
  27. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  28. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  29. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  30. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  31. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  32. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  33. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  34. package/src/components/core/button-group/index.ts +25 -0
  35. package/src/components/core/field/FieldDescription.vue +1 -1
  36. package/src/components/core/field/FieldLabel.vue +3 -2
  37. package/src/components/core/field/FieldTitle.vue +1 -1
  38. package/src/components/core/select/SelectTrigger.vue +1 -1
  39. package/src/components/index.ts +1 -0
  40. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
  41. package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
@@ -1,6 +1,16 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
2
  import { expect, fn, userEvent, within } from 'storybook/test';
3
3
  import UiCheckbox from './UiCheckbox.vue';
4
+ import {
5
+ UiField,
6
+ UiFieldContent,
7
+ UiFieldDescription,
8
+ UiFieldGroup,
9
+ UiFieldLabel,
10
+ UiFieldLegend,
11
+ UiFieldSet,
12
+ UiFieldTitle,
13
+ } from '../UiField';
4
14
  import { ref } from 'vue';
5
15
 
6
16
  /**
@@ -271,12 +281,17 @@ const checked = ref(true)
271
281
 
272
282
  <template>
273
283
  <div class="flex items-start gap-3">
274
- <UiCheckbox id="terms-2" name="terms-2" v-model="checked" />
284
+ <UiCheckbox
285
+ id="terms-2"
286
+ name="terms-2"
287
+ v-model="checked"
288
+ aria-describedby="terms-2-description"
289
+ />
275
290
  <div class="grid gap-2">
276
291
  <label for="terms-2" class="body-14-medium">
277
292
  Accept terms and conditions
278
293
  </label>
279
- <p class="body-14-regular text-content-on-surface-muted">
294
+ <p id="terms-2-description" class="body-14-regular text-content-on-surface-muted">
280
295
  By clicking this checkbox, you agree to the terms and conditions.
281
296
  </p>
282
297
  </div>
@@ -285,6 +300,8 @@ const checked = ref(true)
285
300
 
286
301
  /**
287
302
  * Checkbox with label and description text.
303
+ * The description is wired with `aria-describedby` so it is announced after the
304
+ * label instead of being visual-only.
288
305
  */
289
306
  export const WithDescription: Story = {
290
307
  render: (args) => ({
@@ -294,12 +311,12 @@ export const WithDescription: Story = {
294
311
  return { args, checked };
295
312
  },
296
313
  template: `<div class="flex items-start gap-3">
297
- <UiCheckbox id="terms-2" name="terms-2" v-model="checked" :disabled="args.disabled" :required="args.required" />
314
+ <UiCheckbox id="terms-2" name="terms-2" v-model="checked" :disabled="args.disabled" :required="args.required" aria-describedby="terms-2-description" />
298
315
  <div class="grid gap-2">
299
316
  <label for="terms-2" class="body-14-medium">
300
317
  Accept terms and conditions
301
318
  </label>
302
- <p class="body-14-regular text-content-on-surface-muted">
319
+ <p id="terms-2-description" class="body-14-regular text-content-on-surface-muted">
303
320
  By clicking this checkbox, you agree to the terms and conditions.
304
321
  </p>
305
322
  </div>
@@ -312,6 +329,30 @@ export const WithDescription: Story = {
312
329
  },
313
330
  },
314
331
  },
332
+ play: async ({ canvasElement, step }) => {
333
+ // Scenario (UiCheckbox): the label names the control and the helper text is
334
+ // announced as its description. Non-mutating so the snapshot stays stable.
335
+ const canvas = within(canvasElement);
336
+ const checkbox = canvas.getByRole('checkbox', {
337
+ name: 'Accept terms and conditions',
338
+ });
339
+
340
+ await step(
341
+ 'screen-reader: the helper text is announced as the accessible description (WCAG 1.3.1)',
342
+ async () => {
343
+ await expect(checkbox).toHaveAccessibleDescription(
344
+ 'By clicking this checkbox, you agree to the terms and conditions.',
345
+ );
346
+ },
347
+ );
348
+
349
+ await step(
350
+ 'screen-reader: the checked state is announced (WCAG 4.1.2)',
351
+ async () => {
352
+ await expect(checkbox).toHaveAttribute('aria-checked', 'true');
353
+ },
354
+ );
355
+ },
315
356
  };
316
357
 
317
358
  const disabledTemplateSource = `<script setup lang="ts">
@@ -355,7 +396,8 @@ export const Disabled: Story = {
355
396
  },
356
397
  play: async ({ canvasElement, step }) => {
357
398
  // Scenario (UiCheckbox): a disabled checkbox reports its disabled state to assistive
358
- // tech (a disabled control is inherently out of the tab order).
399
+ // tech (a disabled control is inherently out of the tab order) and refuses
400
+ // activation. The forced click is a no-op, so the snapshot stays stable.
359
401
  const canvas = within(canvasElement);
360
402
  const checkbox = canvas.getByRole('checkbox', {
361
403
  name: 'Enable notifications',
@@ -367,73 +409,300 @@ export const Disabled: Story = {
367
409
  await expect(checkbox).toBeDisabled();
368
410
  },
369
411
  );
412
+
413
+ await step(
414
+ 'interaction: a disabled checkbox cannot be toggled',
415
+ async () => {
416
+ // Disabled controls render with pointer-events: none, so bypass the
417
+ // check and assert the click is still a no-op.
418
+ await userEvent.click(checkbox, { pointerEventsCheck: 0 });
419
+ await expect(checkbox).toHaveAttribute('aria-checked', 'false');
420
+ },
421
+ );
422
+
423
+ await step(
424
+ 'keyboard: a disabled checkbox is skipped by Tab (WCAG 2.1.1)',
425
+ async () => {
426
+ await userEvent.tab();
427
+ await expect(checkbox).not.toHaveFocus();
428
+ },
429
+ );
370
430
  },
371
431
  };
372
432
 
373
- const cardTemplateSource = `<script setup lang="ts">
433
+ const withFieldTemplateSource = `<script setup lang="ts">
374
434
  import { ref } from 'vue'
375
- import { UiCheckbox } from '@aleph-alpha/ui-library'
435
+ import {
436
+ UiCheckbox,
437
+ UiField,
438
+ UiFieldContent,
439
+ UiFieldDescription,
440
+ UiFieldGroup,
441
+ UiFieldLabel,
442
+ UiFieldLegend,
443
+ UiFieldSet,
444
+ UiFieldTitle,
445
+ } from '@aleph-alpha/ui-library'
376
446
 
377
- const enabled = ref(true)
447
+ const push = ref(true)
448
+ const email = ref(false)
378
449
  </script>
379
450
 
380
451
  <template>
381
- <label
382
- class="hover:bg-accent/50 flex items-start gap-3 rounded-lg border p-3 has-[[aria-checked=true]]:border-border-input-default has-[[aria-checked=true]]:bg-background-surface-secondary dark:has-[[aria-checked=true]]:border-blue-900 dark:has-[[aria-checked=true]]:bg-blue-950"
383
- >
384
- <UiCheckbox
385
- id="notifications"
386
- name="notifications"
387
- v-model="enabled"
388
- />
389
- <div class="grid gap-1.5 font-normal">
390
- <p class="body-14-medium leading-none">
391
- Enable notifications
392
- </p>
393
- <p class="body-14-regular text-content-on-surface-muted">
394
- You can enable or disable notifications at any time.
395
- </p>
396
- </div>
397
- </label>
452
+ <!-- Control at the end: text first, checkbox trailing. -->
453
+ <UiFieldGroup>
454
+ <UiFieldSet>
455
+ <UiFieldLegend variant="label">Notifications</UiFieldLegend>
456
+ <UiFieldDescription>
457
+ Choose how you want to hear about activity.
458
+ </UiFieldDescription>
459
+
460
+ <UiFieldGroup data-slot="checkbox-group">
461
+ <UiFieldLabel for="end-push">
462
+ <UiField orientation="horizontal">
463
+ <UiFieldContent>
464
+ <UiFieldTitle>Push notifications</UiFieldTitle>
465
+ <UiFieldDescription>
466
+ Get alerts on your device as soon as something happens.
467
+ </UiFieldDescription>
468
+ </UiFieldContent>
469
+ <UiCheckbox id="end-push" name="push" v-model="push" />
470
+ </UiField>
471
+ </UiFieldLabel>
472
+
473
+ <UiFieldLabel for="end-email">
474
+ <UiField orientation="horizontal">
475
+ <UiFieldContent>
476
+ <UiFieldTitle>Email digest</UiFieldTitle>
477
+ <UiFieldDescription>
478
+ Receive a single summary of activity every morning.
479
+ </UiFieldDescription>
480
+ </UiFieldContent>
481
+ <UiCheckbox id="end-email" name="email" v-model="email" />
482
+ </UiField>
483
+ </UiFieldLabel>
484
+ </UiFieldGroup>
485
+ </UiFieldSet>
486
+ </UiFieldGroup>
487
+
488
+ <!-- Control at the start: checkbox leading, text after. -->
489
+ <UiFieldGroup>
490
+ <UiFieldSet>
491
+ <UiFieldLegend variant="label">Notifications</UiFieldLegend>
492
+ <UiFieldDescription>
493
+ Choose how you want to hear about activity.
494
+ </UiFieldDescription>
495
+
496
+ <UiFieldGroup data-slot="checkbox-group">
497
+ <UiFieldLabel for="start-push">
498
+ <UiField orientation="horizontal">
499
+ <UiCheckbox id="start-push" name="push" v-model="push" />
500
+ <UiFieldContent>
501
+ <UiFieldTitle>Push notifications</UiFieldTitle>
502
+ <UiFieldDescription>
503
+ Get alerts on your device as soon as something happens.
504
+ </UiFieldDescription>
505
+ </UiFieldContent>
506
+ </UiField>
507
+ </UiFieldLabel>
508
+
509
+ <UiFieldLabel for="start-email">
510
+ <UiField orientation="horizontal">
511
+ <UiCheckbox id="start-email" name="email" v-model="email" />
512
+ <UiFieldContent>
513
+ <UiFieldTitle>Email digest</UiFieldTitle>
514
+ <UiFieldDescription>
515
+ Receive a single summary of activity every morning.
516
+ </UiFieldDescription>
517
+ </UiFieldContent>
518
+ </UiField>
519
+ </UiFieldLabel>
520
+ </UiFieldGroup>
521
+ </UiFieldSet>
522
+ </UiFieldGroup>
398
523
  </template>`;
399
524
 
400
525
  /**
401
- * Styled card checkbox with custom colors.
402
- * The label wraps the checkbox for better click target.
526
+ * Checkboxes composed with `UiField` as selectable cards, in both control placements.
527
+ * Wrapping a horizontal `UiField` in a `UiFieldLabel` turns the whole row into a
528
+ * bordered, clickable option that highlights while its checkbox is checked. Put the
529
+ * `UiCheckbox` after `UiFieldContent` to trail the text, or before it to lead.
530
+ * Mark the wrapping `UiFieldGroup` with `data-slot="checkbox-group"` so the cards
531
+ * sit at the tighter group spacing. Unlike a radio group, each card toggles
532
+ * independently, so any number of them can be checked at once.
403
533
  */
404
- export const Card: Story = {
405
- render: (args) => ({
406
- components: { UiCheckbox },
534
+ export const WithField: Story = {
535
+ render: () => ({
536
+ components: {
537
+ UiCheckbox,
538
+ UiField,
539
+ UiFieldContent,
540
+ UiFieldDescription,
541
+ UiFieldGroup,
542
+ UiFieldLabel,
543
+ UiFieldLegend,
544
+ UiFieldSet,
545
+ UiFieldTitle,
546
+ },
407
547
  setup() {
408
- const enabled = ref(true);
409
- return { args, enabled };
548
+ const pushEnd = ref(true);
549
+ const emailEnd = ref(false);
550
+ const pushStart = ref(true);
551
+ const emailStart = ref(false);
552
+ return { pushEnd, emailEnd, pushStart, emailStart };
410
553
  },
411
- template: `<label
412
- class="flex items-start gap-3 rounded-lg border p-3 has-[[aria-checked=true]]:border-border-input-default has-[[aria-checked=true]]:bg-background-surface-muted dark:has-[[aria-checked=true]]:border-blue-900 dark:has-[[aria-checked=true]]:bg-blue-950"
413
- >
414
- <UiCheckbox
415
- id="notifications"
416
- name="notifications"
417
- v-model="enabled"
418
- :disabled="args.disabled"
419
- />
420
- <div class="grid gap-1.5 font-normal">
421
- <p class="body-14-medium leading-none text-content-on-surface-primary">
422
- Enable notifications
423
- </p>
424
- <p class="body-14-regular text-content-on-surface-muted">
425
- You can enable or disable notifications at any time.
426
- </p>
554
+ template: `
555
+ <div class="grid w-full max-w-3xl gap-6 md:grid-cols-2">
556
+ <UiFieldGroup>
557
+ <UiFieldSet>
558
+ <UiFieldLegend variant="label">Notifications (control at end)</UiFieldLegend>
559
+ <UiFieldDescription>
560
+ Choose how you want to hear about activity.
561
+ </UiFieldDescription>
562
+
563
+ <UiFieldGroup data-slot="checkbox-group">
564
+ <UiFieldLabel for="end-push">
565
+ <UiField orientation="horizontal">
566
+ <UiFieldContent>
567
+ <UiFieldTitle>Push notifications</UiFieldTitle>
568
+ <UiFieldDescription>
569
+ Get alerts on your device as soon as something happens.
570
+ </UiFieldDescription>
571
+ </UiFieldContent>
572
+ <UiCheckbox id="end-push" name="push-end" v-model="pushEnd" />
573
+ </UiField>
574
+ </UiFieldLabel>
575
+
576
+ <UiFieldLabel for="end-email">
577
+ <UiField orientation="horizontal">
578
+ <UiFieldContent>
579
+ <UiFieldTitle>Email digest</UiFieldTitle>
580
+ <UiFieldDescription>
581
+ Receive a single summary of activity every morning.
582
+ </UiFieldDescription>
583
+ </UiFieldContent>
584
+ <UiCheckbox id="end-email" name="email-end" v-model="emailEnd" />
585
+ </UiField>
586
+ </UiFieldLabel>
587
+ </UiFieldGroup>
588
+ </UiFieldSet>
589
+ </UiFieldGroup>
590
+
591
+ <UiFieldGroup>
592
+ <UiFieldSet>
593
+ <UiFieldLegend variant="label">Notifications (control at start)</UiFieldLegend>
594
+ <UiFieldDescription>
595
+ Choose how you want to hear about activity.
596
+ </UiFieldDescription>
597
+
598
+ <UiFieldGroup data-slot="checkbox-group">
599
+ <UiFieldLabel for="start-push">
600
+ <UiField orientation="horizontal">
601
+ <UiCheckbox id="start-push" name="push-start" v-model="pushStart" />
602
+ <UiFieldContent>
603
+ <UiFieldTitle>Push notifications</UiFieldTitle>
604
+ <UiFieldDescription>
605
+ Get alerts on your device as soon as something happens.
606
+ </UiFieldDescription>
607
+ </UiFieldContent>
608
+ </UiField>
609
+ </UiFieldLabel>
610
+
611
+ <UiFieldLabel for="start-email">
612
+ <UiField orientation="horizontal">
613
+ <UiCheckbox id="start-email" name="email-start" v-model="emailStart" />
614
+ <UiFieldContent>
615
+ <UiFieldTitle>Email digest</UiFieldTitle>
616
+ <UiFieldDescription>
617
+ Receive a single summary of activity every morning.
618
+ </UiFieldDescription>
619
+ </UiFieldContent>
620
+ </UiField>
621
+ </UiFieldLabel>
622
+ </UiFieldGroup>
623
+ </UiFieldSet>
624
+ </UiFieldGroup>
427
625
  </div>
428
- </label>`,
626
+ `,
429
627
  }),
430
628
  parameters: {
629
+ controls: { disable: true },
431
630
  docs: {
432
631
  source: {
433
- code: cardTemplateSource,
632
+ code: withFieldTemplateSource,
434
633
  },
435
634
  },
436
635
  },
636
+ play: async ({ canvasElement, step }) => {
637
+ // Scenario (UiCheckbox): each card is a label wired to its checkbox, so the
638
+ // title and description become the checkbox's accessible name regardless of
639
+ // whether the control leads or trails. The one toggle is undone before the
640
+ // play ends, so the primary snapshot stays stable.
641
+ const canvas = within(canvasElement);
642
+
643
+ await step(
644
+ 'screen-reader: each fieldset is a group named by its legend (WCAG 1.3.1)',
645
+ async () => {
646
+ const groups = canvas.getAllByRole('group', { name: /Notifications/ });
647
+ await expect(groups).toHaveLength(2);
648
+ },
649
+ );
650
+
651
+ await step(
652
+ 'screen-reader: card labels name their checkboxes in both placements (WCAG 1.3.1 / 4.1.2)',
653
+ async () => {
654
+ const push = canvas.getAllByRole('checkbox', {
655
+ name: /Push notifications/,
656
+ });
657
+ const email = canvas.getAllByRole('checkbox', {
658
+ name: /Email digest/,
659
+ });
660
+ await expect(push).toHaveLength(2);
661
+ await expect(email).toHaveLength(2);
662
+ for (const checkbox of push) await expect(checkbox).toBeChecked();
663
+ for (const checkbox of email) await expect(checkbox).not.toBeChecked();
664
+ },
665
+ );
666
+
667
+ await step(
668
+ 'interaction: the selected card is distinguished by more than colour alone (WCAG 1.4.1)',
669
+ async () => {
670
+ // The card highlight is driven by `data-state`, which the label styles
671
+ // key off — so the checked state is exposed in the DOM, not only in the
672
+ // rendered colour.
673
+ for (const checkbox of canvas.getAllByRole('checkbox', {
674
+ name: /Push notifications/,
675
+ })) {
676
+ await expect(checkbox).toHaveAttribute('data-state', 'checked');
677
+ }
678
+ for (const checkbox of canvas.getAllByRole('checkbox', {
679
+ name: /Email digest/,
680
+ })) {
681
+ await expect(checkbox).toHaveAttribute('data-state', 'unchecked');
682
+ }
683
+ },
684
+ );
685
+
686
+ await step(
687
+ 'interaction: cards toggle independently, so several can be checked at once',
688
+ async () => {
689
+ const [push] = canvas.getAllByRole('checkbox', {
690
+ name: /Push notifications/,
691
+ });
692
+ const [email] = canvas.getAllByRole('checkbox', {
693
+ name: /Email digest/,
694
+ });
695
+
696
+ await userEvent.click(email);
697
+ await expect(email).toBeChecked();
698
+ await expect(push).toBeChecked();
699
+
700
+ // Restore the initial state so the snapshot is unaffected.
701
+ await userEvent.click(email);
702
+ await expect(email).not.toBeChecked();
703
+ },
704
+ );
705
+ },
437
706
  };
438
707
 
439
708
  const indeterminateTemplateSource = `<script setup lang="ts">
@@ -492,6 +761,137 @@ export const Indeterminate: Story = {
492
761
  },
493
762
  };
494
763
 
764
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
765
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
766
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
767
+ // in the automated report under their `test - …` name. `name`/`tags` must be
768
+ // literal properties so Storybook's static CSF indexer can read them.
769
+
770
+ // Shared render for the test scenarios: a required checkbox with a described
771
+ // label, a disabled one, and one starting in the mixed state — a single fixture
772
+ // covering naming, description, every checked state, and the disabled guard.
773
+ function renderTestCheckboxes() {
774
+ return {
775
+ components: { UiCheckbox },
776
+ setup() {
777
+ const terms = ref(false);
778
+ const newsletter = ref(false);
779
+ const selectAll = ref<'indeterminate' | boolean>('indeterminate');
780
+ return { terms, newsletter, selectAll, onUpdate };
781
+ },
782
+ template: `
783
+ <div class="flex flex-col gap-4">
784
+ <div class="flex items-start gap-3">
785
+ <UiCheckbox
786
+ id="t-terms"
787
+ name="terms"
788
+ v-model="terms"
789
+ required
790
+ aria-describedby="t-terms-description"
791
+ @update:model-value="onUpdate"
792
+ />
793
+ <div class="grid gap-1">
794
+ <label for="t-terms" class="body-14-medium">Accept terms and conditions</label>
795
+ <p id="t-terms-description" class="body-14-regular text-content-on-surface-muted">
796
+ You can withdraw your consent at any time.
797
+ </p>
798
+ </div>
799
+ </div>
800
+
801
+ <div class="flex items-center gap-3">
802
+ <UiCheckbox id="t-newsletter" name="newsletter" v-model="newsletter" disabled />
803
+ <label for="t-newsletter" class="body-14-medium text-content-on-surface-muted">
804
+ Subscribe to the newsletter
805
+ </label>
806
+ </div>
807
+
808
+ <div class="flex items-center gap-3">
809
+ <UiCheckbox id="t-select-all" name="select-all" v-model="selectAll" />
810
+ <label for="t-select-all" class="body-14-medium">Select all</label>
811
+ </div>
812
+ </div>
813
+ `,
814
+ };
815
+ }
816
+
817
+ /**
818
+ * Toggle behaviour: clicking flips the state and emits, the label is part of the
819
+ * hit area, a mixed checkbox resolves to checked, and a disabled checkbox
820
+ * refuses activation.
821
+ */
822
+ export const ToggleBehavior: Story = {
823
+ name: 'test - Toggle Behavior',
824
+ tags: ['!dev', '!autodocs'],
825
+ render: renderTestCheckboxes,
826
+ parameters: {
827
+ // The play toggles state; skip the visual snapshot.
828
+ chromatic: { disableSnapshot: true },
829
+ docs: {
830
+ description: {
831
+ story:
832
+ 'Toggle the checkbox on and off, activate it through its label, and confirm the disabled guard holds.',
833
+ },
834
+ },
835
+ },
836
+ play: async ({ canvasElement, step }) => {
837
+ // Scenario (UiCheckbox): a pointer user toggles a checkbox on and off,
838
+ // activates another through its label, advances the mixed checkbox, and
839
+ // finds the disabled one unresponsive.
840
+ onUpdate.mockClear();
841
+ const canvas = within(canvasElement);
842
+ const terms = canvas.getByRole('checkbox', {
843
+ name: 'Accept terms and conditions',
844
+ });
845
+
846
+ await step(
847
+ 'interaction: clicking toggles the checked state and emits the new value',
848
+ async () => {
849
+ await userEvent.click(terms);
850
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
851
+ await expect(onUpdate).toHaveBeenCalledWith(true);
852
+ },
853
+ );
854
+
855
+ await step('interaction: clicking again toggles it back off', async () => {
856
+ await userEvent.click(terms);
857
+ await expect(terms).toHaveAttribute('aria-checked', 'false');
858
+ await expect(onUpdate).toHaveBeenLastCalledWith(false);
859
+ });
860
+
861
+ await step(
862
+ 'interaction: the associated label is part of the activation target (WCAG 2.5.8)',
863
+ async () => {
864
+ await userEvent.click(canvas.getByText('Accept terms and conditions'));
865
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
866
+ },
867
+ );
868
+
869
+ await step(
870
+ 'interaction: a mixed checkbox resolves to checked when activated',
871
+ async () => {
872
+ const selectAll = canvas.getByRole('checkbox', { name: 'Select all' });
873
+ await expect(selectAll).toHaveAttribute('aria-checked', 'mixed');
874
+ await userEvent.click(selectAll);
875
+ await expect(selectAll).toHaveAttribute('aria-checked', 'true');
876
+ },
877
+ );
878
+
879
+ await step(
880
+ 'interaction: a disabled checkbox cannot be toggled (WCAG 4.1.2)',
881
+ async () => {
882
+ const newsletter = canvas.getByRole('checkbox', {
883
+ name: 'Subscribe to the newsletter',
884
+ });
885
+ await expect(newsletter).toBeDisabled();
886
+ // Disabled controls render with pointer-events: none, so bypass the
887
+ // check and assert the click is still a no-op.
888
+ await userEvent.click(newsletter, { pointerEventsCheck: 0 });
889
+ await expect(newsletter).toHaveAttribute('aria-checked', 'false');
890
+ },
891
+ );
892
+ },
893
+ };
894
+
495
895
  /**
496
896
  * `UiCheckbox` is keyboard operable: `Tab` moves focus to it and `Space`
497
897
  * toggles the checked state. Hidden test-only story.
@@ -499,19 +899,7 @@ export const Indeterminate: Story = {
499
899
  export const KeyboardNavigation: Story = {
500
900
  name: 'test - Keyboard Navigation',
501
901
  tags: ['!dev', '!autodocs'],
502
- render: () => ({
503
- components: { UiCheckbox },
504
- setup() {
505
- const checked = ref(false);
506
- return { checked, onUpdate };
507
- },
508
- template: `<div class="flex items-center gap-3">
509
- <UiCheckbox id="subscribe" name="subscribe" v-model="checked" @update:model-value="onUpdate" />
510
- <label for="subscribe" class="body-14-medium">
511
- Subscribe to updates
512
- </label>
513
- </div>`,
514
- }),
902
+ render: renderTestCheckboxes,
515
903
  parameters: {
516
904
  // Focus moves during the play function; skip the visual snapshot so the
517
905
  // focus ring doesn't register as a Chromatic diff.
@@ -524,19 +912,24 @@ export const KeyboardNavigation: Story = {
524
912
  },
525
913
  },
526
914
  play: async ({ canvasElement, step }) => {
527
- // Scenario (UiCheckbox): a keyboard user tabs to the checkbox and toggles it with Space,
528
- // which flips aria-checked and emits update:modelValue.
915
+ // Scenario (UiCheckbox): a keyboard user tabs through the enabled
916
+ // checkboxes in DOM order, toggles with Space, and never lands on the
917
+ // disabled one.
529
918
  onUpdate.mockClear();
530
919
  const canvas = within(canvasElement);
531
- const checkbox = canvas.getByRole('checkbox', {
532
- name: 'Subscribe to updates',
920
+ const terms = canvas.getByRole('checkbox', {
921
+ name: 'Accept terms and conditions',
922
+ });
923
+ const newsletter = canvas.getByRole('checkbox', {
924
+ name: 'Subscribe to the newsletter',
533
925
  });
926
+ const selectAll = canvas.getByRole('checkbox', { name: 'Select all' });
534
927
 
535
928
  await step(
536
929
  'keyboard: checkbox is reachable via Tab (WCAG 2.1.1)',
537
930
  async () => {
538
931
  await userEvent.tab();
539
- await expect(checkbox).toHaveFocus();
932
+ await expect(terms).toHaveFocus();
540
933
  },
541
934
  );
542
935
 
@@ -544,10 +937,163 @@ export const KeyboardNavigation: Story = {
544
937
  'keyboard: Space toggles the checked state (WCAG 2.1.1)',
545
938
  async () => {
546
939
  await userEvent.keyboard(' ');
547
- await expect(checkbox).toHaveAttribute('aria-checked', 'true');
940
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
548
941
  await expect(onUpdate).toHaveBeenCalledWith(true);
549
942
  },
550
943
  );
944
+
945
+ await step('keyboard: Space toggles it back off', async () => {
946
+ await userEvent.keyboard(' ');
947
+ await expect(terms).toHaveAttribute('aria-checked', 'false');
948
+ await expect(onUpdate).toHaveBeenLastCalledWith(false);
949
+ });
950
+
951
+ await step(
952
+ 'keyboard: Tab follows DOM order and skips the disabled checkbox (WCAG 2.4.3 Focus Order)',
953
+ async () => {
954
+ await userEvent.tab();
955
+ await expect(newsletter).not.toHaveFocus();
956
+ await expect(selectAll).toHaveFocus();
957
+ },
958
+ );
959
+
960
+ await step(
961
+ 'keyboard: Space advances the mixed checkbox to checked (WCAG 2.1.1)',
962
+ async () => {
963
+ await userEvent.keyboard(' ');
964
+ await expect(selectAll).toHaveAttribute('aria-checked', 'true');
965
+ },
966
+ );
967
+ },
968
+ };
969
+
970
+ /**
971
+ * Screen-reader semantics: the checkbox exposes its role, the label as its
972
+ * accessible name, the helper text as its description, and its checked,
973
+ * mixed, required, and disabled states.
974
+ */
975
+ export const ScreenReader: Story = {
976
+ name: 'test - Screen Reader',
977
+ tags: ['!dev', '!autodocs'],
978
+ render: renderTestCheckboxes,
979
+ parameters: {
980
+ // The play toggles state; skip the visual snapshot.
981
+ chromatic: { disableSnapshot: true },
982
+ docs: {
983
+ description: {
984
+ story:
985
+ 'Verifies the roles, names, descriptions, and states that assistive technology announces.',
986
+ },
987
+ },
988
+ },
989
+ play: async ({ canvasElement, step }) => {
990
+ // Scenario (UiCheckbox): assistive tech reads each control as a checkbox
991
+ // named by its label, hears the helper text as a description, and is told
992
+ // which are checked, mixed, required, or unavailable.
993
+ const canvas = within(canvasElement);
994
+ const terms = canvas.getByRole('checkbox', {
995
+ name: 'Accept terms and conditions',
996
+ });
997
+ const selectAll = canvas.getByRole('checkbox', { name: 'Select all' });
998
+
999
+ await step(
1000
+ 'screen-reader: the label supplies the accessible name (WCAG 1.3.1 / 4.1.2)',
1001
+ async () => {
1002
+ await expect(terms).toHaveAccessibleName('Accept terms and conditions');
1003
+ },
1004
+ );
1005
+
1006
+ await step(
1007
+ 'screen-reader: the helper text is announced as the description (WCAG 1.3.1)',
1008
+ async () => {
1009
+ await expect(terms).toHaveAccessibleDescription(
1010
+ 'You can withdraw your consent at any time.',
1011
+ );
1012
+ },
1013
+ );
1014
+
1015
+ await step(
1016
+ 'screen-reader: a required checkbox announces aria-required (WCAG 3.3.2)',
1017
+ async () => {
1018
+ await expect(terms).toHaveAttribute('aria-required', 'true');
1019
+ },
1020
+ );
1021
+
1022
+ await step(
1023
+ 'screen-reader: the unchecked, mixed, and disabled states are announced (WCAG 4.1.2)',
1024
+ async () => {
1025
+ await expect(terms).toHaveAttribute('aria-checked', 'false');
1026
+ await expect(selectAll).toHaveAttribute('aria-checked', 'mixed');
1027
+ await expect(
1028
+ canvas.getByRole('checkbox', {
1029
+ name: 'Subscribe to the newsletter',
1030
+ }),
1031
+ ).toBeDisabled();
1032
+ },
1033
+ );
1034
+
1035
+ await step(
1036
+ 'screen-reader: the announced state follows the selection (WCAG 4.1.2)',
1037
+ async () => {
1038
+ await userEvent.click(terms);
1039
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
1040
+ },
1041
+ );
1042
+ },
1043
+ };
1044
+
1045
+ /**
1046
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1047
+ * try 400% reflow (WCAG 1.4.10); every checkbox must stay visible, readable,
1048
+ * and operable. Hidden test-only story.
1049
+ */
1050
+ export const ZoomMagnification: Story = {
1051
+ name: 'test - Zoom Magnification',
1052
+ tags: ['!dev', '!autodocs'],
1053
+ globals: { zoom: '200' },
1054
+ render: renderTestCheckboxes,
1055
+ parameters: {
1056
+ // The accessible-reflow Chromatic mode already covers magnified snapshots.
1057
+ chromatic: { disableSnapshot: true },
1058
+ docs: {
1059
+ description: {
1060
+ story:
1061
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1062
+ },
1063
+ },
1064
+ },
1065
+ play: async ({ canvasElement, step }) => {
1066
+ // Scenario (UiCheckbox): at 200% page zoom every checkbox keeps its label
1067
+ // on screen and still toggles.
1068
+ const canvas = within(canvasElement);
1069
+ const terms = canvas.getByRole('checkbox', {
1070
+ name: 'Accept terms and conditions',
1071
+ });
1072
+
1073
+ await step(
1074
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1075
+ async () => {
1076
+ await expect(document.documentElement.style.zoom).toBe('200%');
1077
+ },
1078
+ );
1079
+
1080
+ await step(
1081
+ 'zoom: every checkbox stays visible with a readable label when magnified',
1082
+ async () => {
1083
+ for (const checkbox of canvas.getAllByRole('checkbox')) {
1084
+ await expect(checkbox).toBeVisible();
1085
+ await expect(checkbox).toHaveAccessibleName();
1086
+ }
1087
+ },
1088
+ );
1089
+
1090
+ await step(
1091
+ 'zoom: the checkbox remains operable when magnified',
1092
+ async () => {
1093
+ await userEvent.click(terms);
1094
+ await expect(terms).toHaveAttribute('aria-checked', 'true');
1095
+ },
1096
+ );
551
1097
  },
552
1098
  };
553
1099
 
@@ -632,12 +1178,17 @@ export const MobileBreakpoint: Story = {
632
1178
  );
633
1179
 
634
1180
  await step(
635
- 'mobile: the checkbox control stays visible and rendered at the mobile breakpoint',
1181
+ 'mobile: the label extends the activation target for touch (WCAG 2.5.8)',
636
1182
  async () => {
637
- await expect(checkbox).toBeVisible();
638
- const { width, height } = checkbox.getBoundingClientRect();
639
- await expect(width).toBeGreaterThan(0);
640
- await expect(height).toBeGreaterThan(0);
1183
+ // The control itself is 16px, so it relies on its associated label to
1184
+ // enlarge the tap area — tapping the text must toggle it.
1185
+ await userEvent.click(canvas.getByText('Accept terms and conditions'));
1186
+ await expect(checkbox).toHaveAttribute('aria-checked', 'false');
1187
+
1188
+ const row = checkbox.parentElement as HTMLElement;
1189
+ const { width, height } = row.getBoundingClientRect();
1190
+ await expect(width).toBeGreaterThanOrEqual(24);
1191
+ await expect(height).toBeGreaterThanOrEqual(16);
641
1192
  },
642
1193
  );
643
1194
  },