@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.
- package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
- package/dist/system/components/UiSlider/types.d.ts +28 -0
- package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
- package/dist/system/icons/story-sidebar-icons.json +74 -17
- package/dist/system/lib.js +2026 -1912
- package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +74 -17
- package/package.json +15 -10
- package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
- package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
- package/src/components/UiAlert/UiAlert.guidance.md +66 -0
- package/src/components/UiAlert/UiAlert.stories.ts +167 -143
- package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
- package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
- package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
- package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
- package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
- package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
- package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
- package/src/components/UiBadge/UiBadge.guidance.md +65 -0
- package/src/components/UiBadge/UiBadge.stories.ts +325 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
- package/src/components/UiButton/UiButton.stories.ts +5 -2
- package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
- package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
- package/src/components/UiCard/UiCard.guidance.md +65 -0
- package/src/components/UiCard/UiCard.stories.ts +393 -0
- package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
- package/src/components/UiChip/UiChip.guidance.md +64 -0
- package/src/components/UiChip/UiChip.stories.ts +162 -138
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
- package/src/components/UiDialog/UiDialog.guidance.md +66 -0
- package/src/components/UiDialog/UiDialog.stories.ts +90 -66
- package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
- package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
- package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +127 -86
- package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
- package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
- package/src/components/UiField/UiField.guidance.md +63 -0
- package/src/components/UiField/UiField.stories.ts +90 -113
- package/src/components/UiFileType/UiFileType.stories.ts +254 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
- package/src/components/UiIcon/UiIcon.stories.ts +256 -1
- package/src/components/UiInput/UiInput.guidance.md +64 -0
- package/src/components/UiInput/UiInput.stories.ts +132 -80
- package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
- package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
- package/src/components/UiItem/UiItem.guidance.md +66 -0
- package/src/components/UiItem/UiItem.stories.ts +81 -28
- package/src/components/UiKbd/UiKbd.guidance.md +65 -0
- package/src/components/UiKbd/UiKbd.stories.ts +373 -3
- package/src/components/UiLabel/UiLabel.guidance.md +65 -0
- package/src/components/UiLabel/UiLabel.stories.ts +163 -139
- package/src/components/UiListbox/UiListbox.stories.ts +197 -195
- package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
- package/src/components/UiPopover/UiPopover.guidance.md +65 -0
- package/src/components/UiPopover/UiPopover.stories.ts +115 -91
- package/src/components/UiProgress/UiProgress.guidance.md +65 -0
- package/src/components/UiProgress/UiProgress.stories.ts +300 -0
- package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
- package/src/components/UiResizable/UiResizable.guidance.md +65 -0
- package/src/components/UiResizable/UiResizable.stories.ts +176 -152
- package/src/components/UiSelect/UiSelect.guidance.md +66 -0
- package/src/components/UiSelect/UiSelect.stories.ts +150 -126
- package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
- package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
- package/src/components/UiSheet/UiSheet.guidance.md +66 -0
- package/src/components/UiSheet/UiSheet.stories.ts +194 -170
- package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
- package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
- package/src/components/UiSlider/UiSlider.guidance.md +66 -0
- package/src/components/UiSlider/UiSlider.stories.ts +885 -153
- package/src/components/UiSlider/UiSlider.vue +109 -1
- package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
- package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
- package/src/components/UiSlider/step-marks.ts +96 -0
- package/src/components/UiSlider/types.ts +32 -0
- package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
- package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
- package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
- package/src/components/UiStepper/UiStepper.guidance.md +66 -0
- package/src/components/UiStepper/UiStepper.stories.ts +142 -124
- package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
- package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
- package/src/components/UiTable/UiTable.guidance.md +66 -0
- package/src/components/UiTable/UiTable.stories.ts +530 -12
- package/src/components/UiTabs/UiTabs.guidance.md +66 -0
- package/src/components/UiTabs/UiTabs.stories.ts +174 -150
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
- package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
- package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
- package/src/components/UiToggle/UiToggle.guidance.md +66 -0
- package/src/components/UiToggle/UiToggle.stories.ts +183 -159
- package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
- package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
- package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
- package/src/components/core/slider/Slider.vue +16 -6
- package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
- package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
- package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
- package/src/patterns/UiPlaceholder/types.ts +1 -0
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +86 -84
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
2
3
|
import UiBadge from './UiBadge.vue';
|
|
3
4
|
import { BadgeSizes, BadgeVariants } from './constants';
|
|
4
5
|
import { UiIcon } from '../UiIcon';
|
|
5
6
|
import { BadgeCheckIcon, InfoIcon, XIcon } from '@/icons/lucide';
|
|
7
|
+
import {
|
|
8
|
+
accessibilityStory,
|
|
9
|
+
designNotesStory,
|
|
10
|
+
guidanceLinks,
|
|
11
|
+
parseGuidance,
|
|
12
|
+
} from '../../../.storybook/guidance';
|
|
13
|
+
import guidanceMarkdown from './UiBadge.guidance.md?raw';
|
|
14
|
+
|
|
15
|
+
const guidance = parseGuidance(guidanceMarkdown);
|
|
6
16
|
|
|
7
17
|
const variantLabels = {
|
|
8
18
|
default: 'Default',
|
|
@@ -52,6 +62,9 @@ const meta: Meta<typeof UiBadge> = {
|
|
|
52
62
|
size: 'default',
|
|
53
63
|
disabled: false,
|
|
54
64
|
},
|
|
65
|
+
parameters: {
|
|
66
|
+
docs: { links: guidanceLinks(guidance) },
|
|
67
|
+
},
|
|
55
68
|
};
|
|
56
69
|
|
|
57
70
|
export default meta;
|
|
@@ -87,6 +100,35 @@ import { UiBadge } from '@aleph-alpha/ui-library'
|
|
|
87
100
|
*/
|
|
88
101
|
export const Default: Story = createVariantStory('default');
|
|
89
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Usage, guidelines, and do's and don'ts from the Figma documentation.
|
|
105
|
+
*/
|
|
106
|
+
export const DesignNotes: Story = {
|
|
107
|
+
...designNotesStory(guidance),
|
|
108
|
+
tags: ['!autodocs'],
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Accessibility guidance from the Figma documentation, with the component in
|
|
113
|
+
* the default and accessible themes.
|
|
114
|
+
*/
|
|
115
|
+
export const Accessibility: Story = {
|
|
116
|
+
...accessibilityStory({
|
|
117
|
+
requirements: guidance.accessibility,
|
|
118
|
+
example: {
|
|
119
|
+
components: { UiBadge },
|
|
120
|
+
template: `
|
|
121
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
122
|
+
<UiBadge variant="success">Active</UiBadge>
|
|
123
|
+
<UiBadge variant="warning">Pending</UiBadge>
|
|
124
|
+
<UiBadge variant="destructive">Failed</UiBadge>
|
|
125
|
+
</div>
|
|
126
|
+
`,
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
tags: ['!autodocs'],
|
|
130
|
+
};
|
|
131
|
+
|
|
90
132
|
/**
|
|
91
133
|
* Neutral badge variant for secondary emphasis.
|
|
92
134
|
*/
|
|
@@ -139,6 +181,28 @@ export const Disabled: Story = {
|
|
|
139
181
|
return { variantLabels, badgeVariants: BadgeVariants };
|
|
140
182
|
},
|
|
141
183
|
}),
|
|
184
|
+
play: async ({ canvasElement, step }) => {
|
|
185
|
+
// Scenario (UiBadge): every variant renders disabled, keeps its label, and
|
|
186
|
+
// stays out of the tab order.
|
|
187
|
+
const canvas = within(canvasElement);
|
|
188
|
+
|
|
189
|
+
await step(
|
|
190
|
+
'interaction: disabled badges expose aria-disabled and keep their label',
|
|
191
|
+
async () => {
|
|
192
|
+
for (const label of Object.values(variantLabels)) {
|
|
193
|
+
const badge = canvas.getByText(label);
|
|
194
|
+
await expect(badge).toBeVisible();
|
|
195
|
+
await expect(badge).toHaveAttribute('aria-disabled', 'true');
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await step('interaction: disabled badges are not focusable', async () => {
|
|
201
|
+
for (const label of Object.values(variantLabels)) {
|
|
202
|
+
await expect(canvas.getByText(label)).not.toHaveAttribute('tabindex');
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
},
|
|
142
206
|
};
|
|
143
207
|
|
|
144
208
|
/**
|
|
@@ -258,6 +322,29 @@ export const Numbers: Story = {
|
|
|
258
322
|
}),
|
|
259
323
|
};
|
|
260
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Small badge for counts and tight layouts such as table cells and tabs.
|
|
327
|
+
*/
|
|
328
|
+
export const Small: Story = {
|
|
329
|
+
render: () => ({
|
|
330
|
+
components: { UiBadge },
|
|
331
|
+
template: `<UiBadge size="small">Small</UiBadge>`,
|
|
332
|
+
}),
|
|
333
|
+
parameters: {
|
|
334
|
+
docs: {
|
|
335
|
+
source: {
|
|
336
|
+
code: `<script setup lang="ts">
|
|
337
|
+
import { UiBadge } from '@aleph-alpha/ui-library'
|
|
338
|
+
</script>
|
|
339
|
+
|
|
340
|
+
<template>
|
|
341
|
+
<UiBadge size="small">Small</UiBadge>
|
|
342
|
+
</template>`,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
|
|
261
348
|
/**
|
|
262
349
|
* Available badge sizes across all variants.
|
|
263
350
|
*/
|
|
@@ -367,3 +454,241 @@ export const AllVariants: Story = {
|
|
|
367
454
|
`,
|
|
368
455
|
}),
|
|
369
456
|
};
|
|
457
|
+
|
|
458
|
+
const renderTestBadges = () => ({
|
|
459
|
+
components: { UiBadge },
|
|
460
|
+
setup() {
|
|
461
|
+
return { BadgeCheckIcon };
|
|
462
|
+
},
|
|
463
|
+
template: `
|
|
464
|
+
<div class="flex flex-col gap-4">
|
|
465
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
466
|
+
<UiBadge variant="success" :start-icon="BadgeCheckIcon">Active</UiBadge>
|
|
467
|
+
<UiBadge variant="destructive">Failed</UiBadge>
|
|
468
|
+
<UiBadge variant="secondary" disabled>Archived</UiBadge>
|
|
469
|
+
</div>
|
|
470
|
+
<p class="body-m-regular">
|
|
471
|
+
Inbox <UiBadge size="small">12 new</UiBadge>
|
|
472
|
+
</p>
|
|
473
|
+
</div>
|
|
474
|
+
`,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Badges are labels, not controls, so there is nothing to focus: the keyboard
|
|
479
|
+
* check asserts they stay out of the tab order. Hidden test-only story.
|
|
480
|
+
*/
|
|
481
|
+
export const KeyboardNavigation: Story = {
|
|
482
|
+
name: 'test - Keyboard Navigation',
|
|
483
|
+
tags: ['!dev', '!autodocs'],
|
|
484
|
+
parameters: {
|
|
485
|
+
// Focus moves during the play function.
|
|
486
|
+
chromatic: { disableSnapshot: true },
|
|
487
|
+
docs: {
|
|
488
|
+
description: {
|
|
489
|
+
story:
|
|
490
|
+
'Press `Tab`: focus skips the badges, which are not interactive.',
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
render: renderTestBadges,
|
|
495
|
+
play: async ({ canvasElement, step }) => {
|
|
496
|
+
// Scenario (UiBadge): a keyboard user tabs through the page and never lands
|
|
497
|
+
// on a badge, enabled or disabled.
|
|
498
|
+
await step('keyboard: badges are not tab stops', async () => {
|
|
499
|
+
await userEvent.tab();
|
|
500
|
+
await expect(canvasElement.contains(document.activeElement)).toBe(false);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
await step('keyboard: no badge carries a tabindex', async () => {
|
|
504
|
+
await expect(canvasElement.querySelectorAll('[tabindex]')).toHaveLength(
|
|
505
|
+
0,
|
|
506
|
+
);
|
|
507
|
+
});
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* What assistive technology reads for status, disabled, and count badges.
|
|
513
|
+
* Hidden test-only story.
|
|
514
|
+
*/
|
|
515
|
+
export const ScreenReader: Story = {
|
|
516
|
+
name: 'test - Screen Reader',
|
|
517
|
+
tags: ['!dev', '!autodocs'],
|
|
518
|
+
parameters: {
|
|
519
|
+
docs: {
|
|
520
|
+
description: {
|
|
521
|
+
story:
|
|
522
|
+
'Verifies that each badge carries its meaning in text and exposes no control role.',
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
render: renderTestBadges,
|
|
527
|
+
play: async ({ canvasElement, step }) => {
|
|
528
|
+
// Scenario (UiBadge): a screen-reader user hears the status in words, so
|
|
529
|
+
// the colour is never the only signal, and the badge reads as part of
|
|
530
|
+
// its surrounding text.
|
|
531
|
+
const canvas = within(canvasElement);
|
|
532
|
+
|
|
533
|
+
await step(
|
|
534
|
+
'screen-reader: status is carried in text, not only colour (WCAG 1.4.1)',
|
|
535
|
+
async () => {
|
|
536
|
+
for (const label of ['Active', 'Failed', 'Archived']) {
|
|
537
|
+
await expect(canvas.getByText(label)).toBeVisible();
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
await step(
|
|
543
|
+
'screen-reader: badges expose no control role or name of their own',
|
|
544
|
+
async () => {
|
|
545
|
+
await expect(canvas.queryAllByRole('button')).toHaveLength(0);
|
|
546
|
+
for (const badge of canvasElement.querySelectorAll(
|
|
547
|
+
'[data-slot="badge"]',
|
|
548
|
+
)) {
|
|
549
|
+
await expect(badge).not.toHaveAttribute('role');
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
await step(
|
|
555
|
+
'screen-reader: a disabled badge exposes aria-disabled',
|
|
556
|
+
async () => {
|
|
557
|
+
await expect(canvas.getByText('Archived')).toHaveAttribute(
|
|
558
|
+
'aria-disabled',
|
|
559
|
+
'true',
|
|
560
|
+
);
|
|
561
|
+
},
|
|
562
|
+
);
|
|
563
|
+
|
|
564
|
+
await step(
|
|
565
|
+
'screen-reader: the start icon is decorative, so only the text is read',
|
|
566
|
+
async () => {
|
|
567
|
+
const icon = canvas.getByText('Active').querySelector('svg');
|
|
568
|
+
await expect(icon).not.toBeNull();
|
|
569
|
+
await expect(icon).toHaveAttribute('aria-hidden', 'true');
|
|
570
|
+
},
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
await step(
|
|
574
|
+
'screen-reader: a count badge reads inline with its label',
|
|
575
|
+
async () => {
|
|
576
|
+
const paragraph = canvas.getByText(/Inbox/);
|
|
577
|
+
await expect(paragraph).toContainElement(canvas.getByText('12 new'));
|
|
578
|
+
await expect(paragraph.textContent?.replace(/\s+/g, ' ').trim()).toBe(
|
|
579
|
+
'Inbox 12 new',
|
|
580
|
+
);
|
|
581
|
+
},
|
|
582
|
+
);
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
588
|
+
* try 400% reflow (WCAG 1.4.10). Hidden test-only story.
|
|
589
|
+
*/
|
|
590
|
+
export const ZoomMagnification: Story = {
|
|
591
|
+
name: 'test - Zoom Magnification',
|
|
592
|
+
tags: ['!dev', '!autodocs'],
|
|
593
|
+
globals: { zoom: '200' },
|
|
594
|
+
parameters: {
|
|
595
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
596
|
+
// already covers magnified snapshots, so skip this one.
|
|
597
|
+
chromatic: { disableSnapshot: true },
|
|
598
|
+
docs: {
|
|
599
|
+
description: {
|
|
600
|
+
story:
|
|
601
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
render: renderTestBadges,
|
|
606
|
+
play: async ({ canvasElement, step }) => {
|
|
607
|
+
// Scenario (UiBadge): at 200% page zoom every label stays whole and the
|
|
608
|
+
// badges stay inside the viewport.
|
|
609
|
+
const canvas = within(canvasElement);
|
|
610
|
+
|
|
611
|
+
await step(
|
|
612
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
613
|
+
async () => {
|
|
614
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
615
|
+
},
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
await step(
|
|
619
|
+
'zoom: badge text stays whole, not clipped by the pill',
|
|
620
|
+
async () => {
|
|
621
|
+
for (const label of ['Active', 'Failed', 'Archived', '12 new']) {
|
|
622
|
+
const badge = canvas.getByText(label);
|
|
623
|
+
await expect(badge).toBeVisible();
|
|
624
|
+
await expect(badge.scrollWidth).toBeLessThanOrEqual(
|
|
625
|
+
badge.clientWidth + 1,
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
await step('zoom: badges stay inside the viewport', async () => {
|
|
632
|
+
for (const badge of canvasElement.querySelectorAll<HTMLElement>(
|
|
633
|
+
'[data-slot="badge"]',
|
|
634
|
+
)) {
|
|
635
|
+
const { left, right } = badge.getBoundingClientRect();
|
|
636
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
637
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
645
|
+
* toolbar. Hidden test-only story.
|
|
646
|
+
*/
|
|
647
|
+
export const MobileBreakpoint: Story = {
|
|
648
|
+
name: 'test - Mobile Breakpoint',
|
|
649
|
+
tags: ['!dev', '!autodocs'],
|
|
650
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
651
|
+
parameters: {
|
|
652
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
653
|
+
chromatic: { disableSnapshot: true },
|
|
654
|
+
docs: {
|
|
655
|
+
description: {
|
|
656
|
+
story:
|
|
657
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
render: renderTestBadges,
|
|
662
|
+
play: async ({ canvasElement, step }) => {
|
|
663
|
+
// Scenario (UiBadge): at the 320px mobile breakpoint the badges wrap
|
|
664
|
+
// inside the viewport and the small count badge stays legible.
|
|
665
|
+
const canvas = within(canvasElement);
|
|
666
|
+
|
|
667
|
+
await step('mobile: badges render at the 320px breakpoint', async () => {
|
|
668
|
+
await expect(canvas.getByText('Active')).toBeVisible();
|
|
669
|
+
await expect(canvas.getByText('12 new')).toBeVisible();
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
await step(
|
|
673
|
+
'mobile: badges wrap without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
674
|
+
async () => {
|
|
675
|
+
const { scrollWidth, clientWidth } = document.documentElement;
|
|
676
|
+
await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
|
|
677
|
+
|
|
678
|
+
for (const badge of canvasElement.querySelectorAll<HTMLElement>(
|
|
679
|
+
'[data-slot="badge"]',
|
|
680
|
+
)) {
|
|
681
|
+
const { right } = badge.getBoundingClientRect();
|
|
682
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
await step('mobile: badges add no touch targets of their own', async () => {
|
|
688
|
+
// The 2.5.8 target-size check applies to the control a badge sits in,
|
|
689
|
+
// not to the badge, which is never interactive.
|
|
690
|
+
await expect(canvas.queryAllByRole('button')).toHaveLength(0);
|
|
691
|
+
await expect(canvas.queryAllByRole('link')).toHaveLength(0);
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
figma: '29187:135'
|
|
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 Breadcrumb component shows where the current page sits in a hierarchy and gives the user a route back up it. It answers two questions at once: where am I, and how do I get out.
|
|
10
|
+
|
|
11
|
+
Use it when pages nest deeply enough that a user could lose their place. A flat structure needs no breadcrumb, and a single step back is better served by a back action.
|
|
12
|
+
|
|
13
|
+
### The trail mirrors the structure
|
|
14
|
+
|
|
15
|
+
A breadcrumb describes hierarchy, not history:
|
|
16
|
+
|
|
17
|
+
- Items reflect the product's structure, not the path the user took
|
|
18
|
+
- The last item is the current page, and is not a link
|
|
19
|
+
- Labels match the titles of the pages they point to
|
|
20
|
+
- The trail always starts at a stable root
|
|
21
|
+
|
|
22
|
+
### Shorten from the middle
|
|
23
|
+
|
|
24
|
+
When the trail outgrows its space, collapse it in this order:
|
|
25
|
+
|
|
26
|
+
1. Show every level while it fits
|
|
27
|
+
2. Replace the middle levels with the ellipsis item
|
|
28
|
+
3. Offer the collapsed levels through the dropdown item
|
|
29
|
+
4. Keep the root and the current page visible at all times
|
|
30
|
+
|
|
31
|
+
### Consistency
|
|
32
|
+
|
|
33
|
+
Every breadcrumb is built from the same parts:
|
|
34
|
+
|
|
35
|
+
- Breadcrumb, at md or sm size, holding up to five items
|
|
36
|
+
- Link item, for every level above the current page
|
|
37
|
+
- Link current item, for the page being viewed
|
|
38
|
+
- Ellipsis item, standing in for collapsed levels
|
|
39
|
+
- Dropdown item, revealing what the ellipsis hides
|
|
40
|
+
- Separator, the same mark throughout the product
|
|
41
|
+
|
|
42
|
+
## Do
|
|
43
|
+
|
|
44
|
+
- Mirror the product's structure, so the same page always shows the same trail
|
|
45
|
+
- Leave the current page unlinked and visually distinct
|
|
46
|
+
- Use the same separator everywhere
|
|
47
|
+
- Collapse the middle with the ellipsis rather than truncating every label
|
|
48
|
+
- Use the sm size inside dense headers and md on standalone pages
|
|
49
|
+
- Keep labels identical to the page titles they lead to
|
|
50
|
+
|
|
51
|
+
## Don't
|
|
52
|
+
|
|
53
|
+
- Show the user's click history instead of the hierarchy
|
|
54
|
+
- Make the current page a link
|
|
55
|
+
- Drop the root level to save space
|
|
56
|
+
- Truncate every label until nothing is readable
|
|
57
|
+
- Use a breadcrumb as the only navigation on a page
|
|
58
|
+
- Change separator style between sections
|
|
59
|
+
|
|
60
|
+
## Accessibility
|
|
61
|
+
|
|
62
|
+
- The current page differs from the links by weight and colour together, not colour alone
|
|
63
|
+
- Every link keeps a visible hover and focus state, and focus never rests on colour alone
|
|
64
|
+
- Separators read as marks between items rather than as items themselves
|
|
65
|
+
- Items and the ellipsis stay comfortable targets at the sm size, with space between them
|
|
66
|
+
- Labels stay legible when the trail wraps, rather than shrinking below the type's intended size
|
|
67
|
+
- The trail sits above the page title in reading order, so location is known before content
|