@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
|
@@ -9,6 +9,17 @@ import {
|
|
|
9
9
|
} from 'storybook/test';
|
|
10
10
|
import { ref, watch } from 'vue';
|
|
11
11
|
import { UiSlider } from '.';
|
|
12
|
+
import type { UiSliderProps } from './types';
|
|
13
|
+
import {
|
|
14
|
+
accessibilityRequirementsTemplate,
|
|
15
|
+
designNotesStory,
|
|
16
|
+
guidanceLinks,
|
|
17
|
+
guidanceSectionClass,
|
|
18
|
+
parseGuidance,
|
|
19
|
+
} from '../../../.storybook/guidance';
|
|
20
|
+
import guidanceMarkdown from './UiSlider.guidance.md?raw';
|
|
21
|
+
|
|
22
|
+
const guidance = parseGuidance(guidanceMarkdown);
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
25
|
* UiSlider lets users pick a numeric value (single thumb) or a range (multiple thumbs) by dragging.
|
|
@@ -50,6 +61,21 @@ const meta: Meta<typeof UiSlider> = {
|
|
|
50
61
|
description:
|
|
51
62
|
'Whether the slider direction is visually inverted (low/high swapped).',
|
|
52
63
|
},
|
|
64
|
+
showValue: {
|
|
65
|
+
control: 'boolean',
|
|
66
|
+
description:
|
|
67
|
+
"Shows each handle's value above it (beside it when vertical), moving with the handle.",
|
|
68
|
+
},
|
|
69
|
+
showSteps: {
|
|
70
|
+
control: 'boolean',
|
|
71
|
+
description:
|
|
72
|
+
'Shows a dot on the track for every value the handle can reach.',
|
|
73
|
+
},
|
|
74
|
+
stepsInterval: {
|
|
75
|
+
control: { type: 'number' },
|
|
76
|
+
description:
|
|
77
|
+
"Gap between two dots, in the slider's own units. Defaults to every step, but no closer than a tenth of the range. A gap finer than a hundredth of the range falls back to that default.",
|
|
78
|
+
},
|
|
53
79
|
},
|
|
54
80
|
args: {
|
|
55
81
|
modelValue: [50],
|
|
@@ -59,6 +85,11 @@ const meta: Meta<typeof UiSlider> = {
|
|
|
59
85
|
step: 1,
|
|
60
86
|
orientation: 'horizontal',
|
|
61
87
|
inverted: false,
|
|
88
|
+
showValue: false,
|
|
89
|
+
showSteps: false,
|
|
90
|
+
},
|
|
91
|
+
parameters: {
|
|
92
|
+
docs: { links: guidanceLinks(guidance) },
|
|
62
93
|
},
|
|
63
94
|
};
|
|
64
95
|
|
|
@@ -114,6 +145,9 @@ export const Default: Story = {
|
|
|
114
145
|
:step="args.step"
|
|
115
146
|
:orientation="args.orientation"
|
|
116
147
|
:inverted="args.inverted"
|
|
148
|
+
:show-value="args.showValue"
|
|
149
|
+
:show-steps="args.showSteps"
|
|
150
|
+
:steps-interval="args.stepsInterval"
|
|
117
151
|
/>
|
|
118
152
|
<div class="body-s-regular text-content-on-surface-muted my-4">Value: {{ value }}</div>
|
|
119
153
|
</div>
|
|
@@ -155,6 +189,150 @@ export const Default: Story = {
|
|
|
155
189
|
},
|
|
156
190
|
};
|
|
157
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Usage, guidelines, and do's and don'ts from the Figma documentation.
|
|
194
|
+
*/
|
|
195
|
+
export const DesignNotes: Story = {
|
|
196
|
+
...designNotesStory(guidance),
|
|
197
|
+
tags: ['!autodocs'],
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Accessibility guidance for labelling the slider, exposing its value as text,
|
|
202
|
+
* and keeping it operable from the keyboard.
|
|
203
|
+
*/
|
|
204
|
+
export const Accessibility: Story = {
|
|
205
|
+
render: () => ({
|
|
206
|
+
components: { UiSlider },
|
|
207
|
+
setup() {
|
|
208
|
+
const defaultValue = ref([60]);
|
|
209
|
+
const accessibleValue = ref([60]);
|
|
210
|
+
return { defaultValue, accessibleValue };
|
|
211
|
+
},
|
|
212
|
+
template: `
|
|
213
|
+
<section class="${guidanceSectionClass}">
|
|
214
|
+
<div>
|
|
215
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
216
|
+
Accessibility
|
|
217
|
+
</h2>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
${accessibilityRequirementsTemplate(guidance.accessibility, 'Requirements')}
|
|
221
|
+
|
|
222
|
+
<div class="flex flex-col gap-6">
|
|
223
|
+
<div class="flex flex-col gap-2">
|
|
224
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
225
|
+
Label what the slider controls
|
|
226
|
+
</h3>
|
|
227
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
228
|
+
Each handle is announced as a slider named <code>Value</code>
|
|
229
|
+
(<code>Value 1</code> / <code>Value 2</code> for a range), which
|
|
230
|
+
says nothing about what is being adjusted. Put a visible heading
|
|
231
|
+
or <code>label</code> next to the slider so the surrounding
|
|
232
|
+
context supplies the meaning.
|
|
233
|
+
</p>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<div class="flex flex-col gap-2">
|
|
237
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
238
|
+
Show the current value as text
|
|
239
|
+
</h3>
|
|
240
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
241
|
+
Handle position alone is not perceivable for everyone. Render the
|
|
242
|
+
value next to the slider so it can be read, magnified, and
|
|
243
|
+
translated — the same number assistive technology gets from
|
|
244
|
+
<code>aria-valuenow</code>.
|
|
245
|
+
</p>
|
|
246
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
247
|
+
<code>showValue</code> does this above the handle. The text is
|
|
248
|
+
hidden from assistive technology, which reads the value from the
|
|
249
|
+
handle instead; with <code>formatValue</code> the handle announces
|
|
250
|
+
the same text, such as <code>70%</code>, as its
|
|
251
|
+
<code>aria-valuetext</code>.
|
|
252
|
+
</p>
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<div class="flex flex-col gap-2">
|
|
256
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
257
|
+
Keep it keyboard operable
|
|
258
|
+
</h3>
|
|
259
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
260
|
+
Every handle is a Tab stop and moves with the arrow keys.
|
|
261
|
+
<code>Home</code> and <code>End</code> jump to the minimum and
|
|
262
|
+
maximum, and <code>Page Up</code> / <code>Page Down</code> (or
|
|
263
|
+
<code>Shift</code> + arrow) move in larger jumps — so a long
|
|
264
|
+
range never needs hundreds of key presses.
|
|
265
|
+
</p>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
<div class="flex flex-col gap-2">
|
|
269
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
270
|
+
Give small handles room
|
|
271
|
+
</h3>
|
|
272
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
273
|
+
The handle is smaller than the 24px minimum target size, so it
|
|
274
|
+
relies on the WCAG 2.5.8 spacing exception: keep other controls
|
|
275
|
+
at least 24px away, and don't crowd several sliders together.
|
|
276
|
+
</p>
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
<div class="flex flex-col gap-2">
|
|
280
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
281
|
+
Enable accessibility theme
|
|
282
|
+
</h3>
|
|
283
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
284
|
+
When accessibility is required, enable our accessibility theme.
|
|
285
|
+
This increases contrast and makes sure there are no color
|
|
286
|
+
contrast issues.
|
|
287
|
+
</p>
|
|
288
|
+
</div>
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
292
|
+
<div class="flex flex-col gap-3">
|
|
293
|
+
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
294
|
+
Default
|
|
295
|
+
</h3>
|
|
296
|
+
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
297
|
+
<p class="label-s-medium text-content-on-surface-primary">Volume</p>
|
|
298
|
+
<div class="my-3">
|
|
299
|
+
<UiSlider v-model="defaultValue" />
|
|
300
|
+
</div>
|
|
301
|
+
<p class="body-s-regular text-content-on-surface-muted">Value: {{ defaultValue[0] }}</p>
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
306
|
+
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
307
|
+
Accessible
|
|
308
|
+
</h3>
|
|
309
|
+
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
310
|
+
<p class="label-s-medium text-content-on-surface-primary">Volume</p>
|
|
311
|
+
<div class="my-3">
|
|
312
|
+
<UiSlider v-model="accessibleValue" />
|
|
313
|
+
</div>
|
|
314
|
+
<p class="body-s-regular text-content-on-surface-muted">Value: {{ accessibleValue[0] }}</p>
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
</section>
|
|
319
|
+
`,
|
|
320
|
+
}),
|
|
321
|
+
tags: ['!autodocs'],
|
|
322
|
+
parameters: {
|
|
323
|
+
surface: 'primary',
|
|
324
|
+
a11y: { test: 'off' },
|
|
325
|
+
chromatic: {
|
|
326
|
+
disableSnapshot: true,
|
|
327
|
+
},
|
|
328
|
+
docs: {
|
|
329
|
+
canvas: {
|
|
330
|
+
sourceState: 'none',
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
|
|
158
336
|
const rangeTemplateSource = `<script setup lang="ts">
|
|
159
337
|
import { ref } from 'vue'
|
|
160
338
|
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
@@ -299,177 +477,546 @@ export const Disabled: Story = {
|
|
|
299
477
|
render: () => ({
|
|
300
478
|
components: { UiSlider },
|
|
301
479
|
setup() {
|
|
302
|
-
const value = ref([50]);
|
|
303
|
-
return { value };
|
|
480
|
+
const value = ref([50]);
|
|
481
|
+
return { value };
|
|
482
|
+
},
|
|
483
|
+
template: `
|
|
484
|
+
<div class="w-72 gap-y-3">
|
|
485
|
+
<UiSlider v-model="value" disabled />
|
|
486
|
+
<div class="body-s-regular text-content-on-surface-muted my-4">Value: {{ value[0] }}</div>
|
|
487
|
+
</div>
|
|
488
|
+
`,
|
|
489
|
+
}),
|
|
490
|
+
parameters: {
|
|
491
|
+
controls: { disable: true },
|
|
492
|
+
docs: { source: { code: disabledTemplateSource } },
|
|
493
|
+
},
|
|
494
|
+
play: async ({ canvasElement, step }) => {
|
|
495
|
+
// Scenario (UiSlider): a disabled slider reports its state, is skipped by
|
|
496
|
+
// Tab, and refuses to move even when a step key reaches it.
|
|
497
|
+
const canvas = within(canvasElement);
|
|
498
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
499
|
+
|
|
500
|
+
await step(
|
|
501
|
+
'interaction: exposes the disabled state (WCAG 4.1.2)',
|
|
502
|
+
async () => {
|
|
503
|
+
await expect(handle).toHaveAttribute('data-disabled');
|
|
504
|
+
await expect(canvas.getByText('Value: 50')).toBeInTheDocument();
|
|
505
|
+
},
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
await step(
|
|
509
|
+
'keyboard: removed from the tab order — not reachable via Tab (WCAG 2.1.1)',
|
|
510
|
+
async () => {
|
|
511
|
+
await expect(handle).not.toHaveAttribute('tabindex');
|
|
512
|
+
await userEvent.tab();
|
|
513
|
+
await expect(handle).not.toHaveFocus();
|
|
514
|
+
},
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
await step('interaction: a disabled slider does not change', async () => {
|
|
518
|
+
// The handle can't be focused, so dispatch the step key on the slider
|
|
519
|
+
// itself — that is the listener a focused handle would bubble to. A
|
|
520
|
+
// pointer drag is covered by the enabled stories.
|
|
521
|
+
await fireEvent.keyDown(handle, { key: 'ArrowRight' });
|
|
522
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
523
|
+
await expect(canvas.getByText('Value: 50')).toBeInTheDocument();
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const STEP_MARK = '[data-slot="slider-step-mark"]';
|
|
529
|
+
const SHOWN_VALUE = '[data-slot="slider-value"]';
|
|
530
|
+
// The vendor positions the handle with calc(); sub-pixel rounding stays
|
|
531
|
+
// within this.
|
|
532
|
+
const ALIGNMENT_TOLERANCE_PX = 1;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* The step dots a story rendered, in track order.
|
|
536
|
+
* @param root The story's root element.
|
|
537
|
+
* @returns Every step dot inside it.
|
|
538
|
+
*/
|
|
539
|
+
function stepMarksIn(root: HTMLElement): HTMLElement[] {
|
|
540
|
+
return [...root.querySelectorAll<HTMLElement>(STEP_MARK)];
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* The value text shown on the first handle.
|
|
545
|
+
* @param root The story's root element.
|
|
546
|
+
* @returns The shown value element.
|
|
547
|
+
*/
|
|
548
|
+
function shownValueIn(root: HTMLElement): HTMLElement {
|
|
549
|
+
const shownValue = root.querySelector<HTMLElement>(SHOWN_VALUE);
|
|
550
|
+
if (!shownValue) throw new Error('No shown value: is showValue on?');
|
|
551
|
+
return shownValue;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Centre of an element on screen.
|
|
556
|
+
* @param element Any rendered element.
|
|
557
|
+
* @returns Its centre in CSS pixels.
|
|
558
|
+
*/
|
|
559
|
+
function centreOf(element: Element): { x: number; y: number } {
|
|
560
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
561
|
+
return { x: left + width / 2, y: top + height / 2 };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Waits until `element` is centred on the handle along one axis. Awaited
|
|
566
|
+
* because reka-ui pulls the handle in from the ends only once it has measured
|
|
567
|
+
* it, a moment after the first render.
|
|
568
|
+
* @param handle A `role="slider"` handle.
|
|
569
|
+
* @param element The dot or shown value that should line up with it.
|
|
570
|
+
* @param axis `x` along a horizontal slider, `y` along a vertical one.
|
|
571
|
+
*/
|
|
572
|
+
async function expectCentredOnHandle(
|
|
573
|
+
handle: HTMLElement,
|
|
574
|
+
element: Element,
|
|
575
|
+
axis: 'x' | 'y' = 'x',
|
|
576
|
+
) {
|
|
577
|
+
await waitFor(async () => {
|
|
578
|
+
await expect(
|
|
579
|
+
Math.abs(centreOf(element)[axis] - centreOf(handle)[axis]),
|
|
580
|
+
).toBeLessThanOrEqual(ALIGNMENT_TOLERANCE_PX);
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const withValueTemplateSource = `<script setup lang="ts">
|
|
585
|
+
import { ref } from 'vue'
|
|
586
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
587
|
+
|
|
588
|
+
const value = ref([70])
|
|
589
|
+
</script>
|
|
590
|
+
|
|
591
|
+
<template>
|
|
592
|
+
<div class="w-72">
|
|
593
|
+
<UiSlider v-model="value" show-value :format-value="(value) => \`\${value}%\`" />
|
|
594
|
+
</div>
|
|
595
|
+
</template>`;
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Shows the current value above the handle, moving with it while dragging.
|
|
599
|
+
* `formatValue` decides how it is written, and screen readers hear the same
|
|
600
|
+
* text; without it the plain number shows.
|
|
601
|
+
*/
|
|
602
|
+
export const WithValue: Story = {
|
|
603
|
+
render: () => ({
|
|
604
|
+
components: { UiSlider },
|
|
605
|
+
setup() {
|
|
606
|
+
const value = ref([70]);
|
|
607
|
+
const formatValue = (value: number) => `${value}%`;
|
|
608
|
+
return { value, formatValue };
|
|
609
|
+
},
|
|
610
|
+
template: `
|
|
611
|
+
<div class="w-72">
|
|
612
|
+
<UiSlider v-model="value" show-value :format-value="formatValue" />
|
|
613
|
+
</div>
|
|
614
|
+
`,
|
|
615
|
+
}),
|
|
616
|
+
parameters: {
|
|
617
|
+
controls: { disable: true },
|
|
618
|
+
docs: { source: { code: withValueTemplateSource } },
|
|
619
|
+
},
|
|
620
|
+
play: async ({ canvasElement, step }) => {
|
|
621
|
+
// Scenario (UiSlider): "70%" reads right above the handle, and screen
|
|
622
|
+
// readers hear "70%" from the handle. Non-mutating.
|
|
623
|
+
const canvas = within(canvasElement);
|
|
624
|
+
const handle = canvas.getByRole('slider', { name: 'Value' });
|
|
625
|
+
const shownValue = shownValueIn(canvasElement);
|
|
626
|
+
|
|
627
|
+
await step(
|
|
628
|
+
'interaction: the value sits above the handle, centred on it',
|
|
629
|
+
async () => {
|
|
630
|
+
await expect(shownValue).toHaveTextContent('70%');
|
|
631
|
+
await expectCentredOnHandle(handle, shownValue);
|
|
632
|
+
await expect(
|
|
633
|
+
shownValue.getBoundingClientRect().bottom,
|
|
634
|
+
).toBeLessThanOrEqual(handle.getBoundingClientRect().top);
|
|
635
|
+
},
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
await step(
|
|
639
|
+
'screen-reader: the handle announces the formatted value, the shown text is hidden (WCAG 4.1.2)',
|
|
640
|
+
async () => {
|
|
641
|
+
await expect(shownValue).toHaveAttribute('aria-hidden', 'true');
|
|
642
|
+
await expect(handle).toHaveAccessibleName('Value');
|
|
643
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '70');
|
|
644
|
+
await expect(handle).toHaveAttribute('aria-valuetext', '70%');
|
|
645
|
+
},
|
|
646
|
+
);
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
const withStepsTemplateSource = `<script setup lang="ts">
|
|
651
|
+
import { ref } from 'vue'
|
|
652
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
653
|
+
|
|
654
|
+
const value = ref([50])
|
|
655
|
+
</script>
|
|
656
|
+
|
|
657
|
+
<template>
|
|
658
|
+
<div class="w-72">
|
|
659
|
+
<UiSlider v-model="value" :step="10" show-steps />
|
|
660
|
+
</div>
|
|
661
|
+
</template>`;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Shows a dot for every value the handle can reach. A slider with many steps
|
|
665
|
+
* gets a dot every tenth of its range unless `stepsInterval` says otherwise.
|
|
666
|
+
*/
|
|
667
|
+
export const WithSteps: Story = {
|
|
668
|
+
render: () => ({
|
|
669
|
+
components: { UiSlider },
|
|
670
|
+
setup() {
|
|
671
|
+
const value = ref([50]);
|
|
672
|
+
return { value };
|
|
673
|
+
},
|
|
674
|
+
template: `
|
|
675
|
+
<div class="w-72">
|
|
676
|
+
<UiSlider v-model="value" :step="10" show-steps />
|
|
677
|
+
</div>
|
|
678
|
+
`,
|
|
679
|
+
}),
|
|
680
|
+
parameters: {
|
|
681
|
+
controls: { disable: true },
|
|
682
|
+
docs: { source: { code: withStepsTemplateSource } },
|
|
683
|
+
},
|
|
684
|
+
play: async ({ canvasElement, step }) => {
|
|
685
|
+
// Scenario (UiSlider): one dot per reachable value, decorative only, and the
|
|
686
|
+
// handle sits on the dot of its value. Non-mutating.
|
|
687
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
688
|
+
const marks = stepMarksIn(canvasElement);
|
|
689
|
+
|
|
690
|
+
await step(
|
|
691
|
+
'interaction: draws one dot per reachable value, with the handle on the dot of its value',
|
|
692
|
+
async () => {
|
|
693
|
+
await expect(marks).toHaveLength(11);
|
|
694
|
+
await expectCentredOnHandle(handle, marks[5]);
|
|
695
|
+
},
|
|
696
|
+
);
|
|
697
|
+
|
|
698
|
+
await step(
|
|
699
|
+
'screen-reader: the dots are hidden from assistive technology',
|
|
700
|
+
async () => {
|
|
701
|
+
await expect(marks[0].closest('[aria-hidden="true"]')).not.toBeNull();
|
|
702
|
+
},
|
|
703
|
+
);
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
const stepsIntervalTemplateSource = `<script setup lang="ts">
|
|
708
|
+
import { ref } from 'vue'
|
|
709
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
710
|
+
|
|
711
|
+
const value = ref([50])
|
|
712
|
+
</script>
|
|
713
|
+
|
|
714
|
+
<template>
|
|
715
|
+
<div class="w-72">
|
|
716
|
+
<UiSlider v-model="value" :step="1" show-steps :steps-interval="10" />
|
|
717
|
+
</div>
|
|
718
|
+
</template>`;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* A slider that moves in steps of 1 but shows a dot only every 10, so a fine
|
|
722
|
+
* range still reads at a glance.
|
|
723
|
+
*/
|
|
724
|
+
export const StepsInterval: Story = {
|
|
725
|
+
render: () => ({
|
|
726
|
+
components: { UiSlider },
|
|
727
|
+
setup() {
|
|
728
|
+
const value = ref([50]);
|
|
729
|
+
return { value };
|
|
730
|
+
},
|
|
731
|
+
template: `
|
|
732
|
+
<div class="w-72">
|
|
733
|
+
<UiSlider v-model="value" :step="1" show-steps :steps-interval="10" />
|
|
734
|
+
</div>
|
|
735
|
+
`,
|
|
736
|
+
}),
|
|
737
|
+
parameters: {
|
|
738
|
+
controls: { disable: true },
|
|
739
|
+
docs: { source: { code: stepsIntervalTemplateSource } },
|
|
740
|
+
},
|
|
741
|
+
play: async ({ canvasElement, step }) => {
|
|
742
|
+
// Scenario (UiSlider): a 0 to 100 slider in steps of 1 draws 11 dots, and
|
|
743
|
+
// the handle at 50 sits on the middle one. Non-mutating.
|
|
744
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
745
|
+
const marks = stepMarksIn(canvasElement);
|
|
746
|
+
|
|
747
|
+
await step(
|
|
748
|
+
'interaction: draws a dot every 10, with the handle at 50 on the middle one',
|
|
749
|
+
async () => {
|
|
750
|
+
await expect(marks).toHaveLength(11);
|
|
751
|
+
await expectCentredOnHandle(handle, marks[5]);
|
|
752
|
+
},
|
|
753
|
+
);
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
const stepsRightToLeftTemplateSource = `<script setup lang="ts">
|
|
758
|
+
import { ref } from 'vue'
|
|
759
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
760
|
+
|
|
761
|
+
const value = ref([60])
|
|
762
|
+
</script>
|
|
763
|
+
|
|
764
|
+
<template>
|
|
765
|
+
<div class="w-72">
|
|
766
|
+
<UiSlider v-model="value" :step="30" show-steps dir="rtl" />
|
|
767
|
+
</div>
|
|
768
|
+
</template>`;
|
|
769
|
+
|
|
770
|
+
const stepsInvertedTemplateSource = `<script setup lang="ts">
|
|
771
|
+
import { ref } from 'vue'
|
|
772
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
773
|
+
|
|
774
|
+
const value = ref([60])
|
|
775
|
+
</script>
|
|
776
|
+
|
|
777
|
+
<template>
|
|
778
|
+
<div class="w-72">
|
|
779
|
+
<UiSlider v-model="value" :step="30" show-steps inverted />
|
|
780
|
+
</div>
|
|
781
|
+
</template>`;
|
|
782
|
+
|
|
783
|
+
const stepsOverflowAlignmentTemplateSource = `<script setup lang="ts">
|
|
784
|
+
import { ref } from 'vue'
|
|
785
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
786
|
+
|
|
787
|
+
const value = ref([60])
|
|
788
|
+
</script>
|
|
789
|
+
|
|
790
|
+
<template>
|
|
791
|
+
<div class="w-72">
|
|
792
|
+
<UiSlider v-model="value" :step="30" show-steps thumb-alignment="overflow" />
|
|
793
|
+
</div>
|
|
794
|
+
</template>`;
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Renders a slider with step dots at 60 on a 0 to 100 track in steps of 30, so
|
|
798
|
+
* the dots sit at 0, 30, 60, 90 and 100. The step does not divide the range,
|
|
799
|
+
* so dots drawn from the wrong edge cannot line up with the handle by chance.
|
|
800
|
+
* @param attributes Extra template attributes for `UiSlider`.
|
|
801
|
+
* @returns Vue component options for a story `render` function.
|
|
802
|
+
*/
|
|
803
|
+
function renderStepsSlider(attributes: string) {
|
|
804
|
+
return {
|
|
805
|
+
components: { UiSlider },
|
|
806
|
+
setup() {
|
|
807
|
+
const value = ref([60]);
|
|
808
|
+
return { value };
|
|
809
|
+
},
|
|
810
|
+
template: `
|
|
811
|
+
<div class="w-72">
|
|
812
|
+
<UiSlider v-model="value" :step="30" show-steps ${attributes} />
|
|
813
|
+
</div>
|
|
814
|
+
`,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* The shared check for the direction stories: the handle at 60 sits on the
|
|
820
|
+
* third dot.
|
|
821
|
+
* @param context Storybook play context.
|
|
822
|
+
* @param context.canvasElement The story's root element.
|
|
823
|
+
* @param context.step Storybook's step reporter.
|
|
824
|
+
*/
|
|
825
|
+
const expectHandleOnItsDot: Story['play'] = async ({ canvasElement, step }) => {
|
|
826
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
827
|
+
const marks = stepMarksIn(canvasElement);
|
|
828
|
+
|
|
829
|
+
await step(
|
|
830
|
+
'interaction: the handle at 60 sits on the dot for 60, the third from the start',
|
|
831
|
+
async () => {
|
|
832
|
+
await expect(marks).toHaveLength(5);
|
|
833
|
+
await expectCentredOnHandle(handle, marks[2]);
|
|
834
|
+
},
|
|
835
|
+
);
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Step dots on a right-to-left slider start from the right edge, like the
|
|
840
|
+
* track itself.
|
|
841
|
+
*/
|
|
842
|
+
export const StepsRightToLeft: Story = {
|
|
843
|
+
render: () => renderStepsSlider('dir="rtl"'),
|
|
844
|
+
parameters: {
|
|
845
|
+
controls: { disable: true },
|
|
846
|
+
docs: { source: { code: stepsRightToLeftTemplateSource } },
|
|
847
|
+
},
|
|
848
|
+
play: expectHandleOnItsDot,
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Step dots on an inverted slider start from the right edge, like the track.
|
|
853
|
+
*/
|
|
854
|
+
export const StepsInverted: Story = {
|
|
855
|
+
render: () => renderStepsSlider('inverted'),
|
|
856
|
+
parameters: {
|
|
857
|
+
controls: { disable: true },
|
|
858
|
+
docs: { source: { code: stepsInvertedTemplateSource } },
|
|
859
|
+
},
|
|
860
|
+
play: expectHandleOnItsDot,
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* With `thumbAlignment="overflow"` the handle reaches the very ends of the
|
|
865
|
+
* track, and the dots run to the ends with it.
|
|
866
|
+
*/
|
|
867
|
+
export const StepsOverflowAlignment: Story = {
|
|
868
|
+
render: () => renderStepsSlider('thumb-alignment="overflow"'),
|
|
869
|
+
parameters: {
|
|
870
|
+
controls: { disable: true },
|
|
871
|
+
docs: {
|
|
872
|
+
source: { code: stepsOverflowAlignmentTemplateSource },
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
play: expectHandleOnItsDot,
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
const verticalWithValueAndStepsTemplateSource = `<script setup lang="ts">
|
|
879
|
+
import { ref } from 'vue'
|
|
880
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
881
|
+
|
|
882
|
+
const value = ref([50])
|
|
883
|
+
</script>
|
|
884
|
+
|
|
885
|
+
<template>
|
|
886
|
+
<!-- A vertical slider reserves no room beside it for the value. -->
|
|
887
|
+
<div class="h-44 pr-12">
|
|
888
|
+
<UiSlider
|
|
889
|
+
v-model="value"
|
|
890
|
+
orientation="vertical"
|
|
891
|
+
:step="10"
|
|
892
|
+
show-value
|
|
893
|
+
show-steps
|
|
894
|
+
:format-value="(value) => \`\${value}%\`"
|
|
895
|
+
/>
|
|
896
|
+
</div>
|
|
897
|
+
</template>`;
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* On a vertical slider the value sits beside the handle and the dots run from
|
|
901
|
+
* the bottom up. Leave room beside the slider for the value.
|
|
902
|
+
*/
|
|
903
|
+
export const VerticalWithValueAndSteps: Story = {
|
|
904
|
+
render: () => ({
|
|
905
|
+
components: { UiSlider },
|
|
906
|
+
setup() {
|
|
907
|
+
const value = ref([50]);
|
|
908
|
+
const formatValue = (value: number) => `${value}%`;
|
|
909
|
+
return { value, formatValue };
|
|
910
|
+
},
|
|
911
|
+
template: `
|
|
912
|
+
<div class="h-44 pr-12">
|
|
913
|
+
<UiSlider
|
|
914
|
+
v-model="value"
|
|
915
|
+
orientation="vertical"
|
|
916
|
+
:step="10"
|
|
917
|
+
show-value
|
|
918
|
+
show-steps
|
|
919
|
+
:format-value="formatValue"
|
|
920
|
+
/>
|
|
921
|
+
</div>
|
|
922
|
+
`,
|
|
923
|
+
}),
|
|
924
|
+
parameters: {
|
|
925
|
+
controls: { disable: true },
|
|
926
|
+
docs: { source: { code: verticalWithValueAndStepsTemplateSource } },
|
|
927
|
+
},
|
|
928
|
+
play: async ({ canvasElement, step }) => {
|
|
929
|
+
// Scenario (UiSlider): the handle at 50 sits on the middle dot, and "50%"
|
|
930
|
+
// reads beside it, level with it. Non-mutating.
|
|
931
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
932
|
+
const marks = stepMarksIn(canvasElement);
|
|
933
|
+
const shownValue = shownValueIn(canvasElement);
|
|
934
|
+
|
|
935
|
+
await step(
|
|
936
|
+
'interaction: the handle sits on the dot of its value, counted from the bottom',
|
|
937
|
+
async () => {
|
|
938
|
+
await expect(marks).toHaveLength(11);
|
|
939
|
+
await expectCentredOnHandle(handle, marks[5], 'y');
|
|
940
|
+
await expect(centreOf(marks[0]).y).toBeGreaterThan(
|
|
941
|
+
centreOf(marks[10]).y,
|
|
942
|
+
);
|
|
943
|
+
},
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
await step(
|
|
947
|
+
'interaction: the value sits beside the handle, level with it',
|
|
948
|
+
async () => {
|
|
949
|
+
await expect(shownValue).toHaveTextContent('50%');
|
|
950
|
+
await expectCentredOnHandle(handle, shownValue, 'y');
|
|
951
|
+
await expect(shownValue.getBoundingClientRect().left).toBeGreaterThan(
|
|
952
|
+
handle.getBoundingClientRect().right,
|
|
953
|
+
);
|
|
954
|
+
},
|
|
955
|
+
);
|
|
956
|
+
},
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
const rangeWithValueTemplateSource = `<script setup lang="ts">
|
|
960
|
+
import { ref } from 'vue'
|
|
961
|
+
import { UiSlider } from '@aleph-alpha/ui-library'
|
|
962
|
+
|
|
963
|
+
const range = ref([20, 80])
|
|
964
|
+
</script>
|
|
965
|
+
|
|
966
|
+
<template>
|
|
967
|
+
<div class="w-72">
|
|
968
|
+
<UiSlider v-model="range" show-value :format-value="(value) => \`\${value}%\`" />
|
|
969
|
+
</div>
|
|
970
|
+
</template>`;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* A range shows one value above each handle.
|
|
974
|
+
*/
|
|
975
|
+
export const RangeWithValue: Story = {
|
|
976
|
+
render: () => ({
|
|
977
|
+
components: { UiSlider },
|
|
978
|
+
setup() {
|
|
979
|
+
const range = ref([20, 80]);
|
|
980
|
+
const formatValue = (value: number) => `${value}%`;
|
|
981
|
+
return { range, formatValue };
|
|
304
982
|
},
|
|
305
983
|
template: `
|
|
306
|
-
<div class="w-72
|
|
307
|
-
<UiSlider v-model="value"
|
|
308
|
-
<div class="body-s-regular text-content-on-surface-muted my-4">Value: {{ value[0] }}</div>
|
|
984
|
+
<div class="w-72">
|
|
985
|
+
<UiSlider v-model="range" show-value :format-value="formatValue" />
|
|
309
986
|
</div>
|
|
310
987
|
`,
|
|
311
988
|
}),
|
|
312
989
|
parameters: {
|
|
313
990
|
controls: { disable: true },
|
|
314
|
-
docs: { source: { code:
|
|
991
|
+
docs: { source: { code: rangeWithValueTemplateSource } },
|
|
315
992
|
},
|
|
316
993
|
play: async ({ canvasElement, step }) => {
|
|
317
|
-
// Scenario (UiSlider):
|
|
318
|
-
//
|
|
994
|
+
// Scenario (UiSlider): each handle carries its own value, centred above it.
|
|
995
|
+
// Non-mutating.
|
|
319
996
|
const canvas = within(canvasElement);
|
|
320
|
-
const
|
|
997
|
+
const handles = canvas.getAllByRole('slider');
|
|
998
|
+
const shownValues = [
|
|
999
|
+
...canvasElement.querySelectorAll<HTMLElement>(SHOWN_VALUE),
|
|
1000
|
+
];
|
|
321
1001
|
|
|
322
1002
|
await step(
|
|
323
|
-
'interaction:
|
|
1003
|
+
'interaction: each handle shows its own value, centred above it',
|
|
324
1004
|
async () => {
|
|
325
|
-
await expect(
|
|
326
|
-
|
|
1005
|
+
await expect(
|
|
1006
|
+
shownValues.map((value) => value.textContent?.trim()),
|
|
1007
|
+
).toEqual(['20%', '80%']);
|
|
1008
|
+
await expectCentredOnHandle(handles[0], shownValues[0]);
|
|
1009
|
+
await expectCentredOnHandle(handles[1], shownValues[1]);
|
|
327
1010
|
},
|
|
328
1011
|
);
|
|
329
1012
|
|
|
330
1013
|
await step(
|
|
331
|
-
'
|
|
1014
|
+
'screen-reader: each handle announces its own formatted value',
|
|
332
1015
|
async () => {
|
|
333
|
-
await expect(
|
|
334
|
-
await
|
|
335
|
-
await expect(handle).not.toHaveFocus();
|
|
1016
|
+
await expect(handles[0]).toHaveAttribute('aria-valuetext', '20%');
|
|
1017
|
+
await expect(handles[1]).toHaveAttribute('aria-valuetext', '80%');
|
|
336
1018
|
},
|
|
337
1019
|
);
|
|
338
|
-
|
|
339
|
-
await step('interaction: a disabled slider does not change', async () => {
|
|
340
|
-
// The handle can't be focused, so dispatch the step key on the slider
|
|
341
|
-
// itself — that is the listener a focused handle would bubble to. A
|
|
342
|
-
// pointer drag is covered by the enabled stories.
|
|
343
|
-
await fireEvent.keyDown(handle, { key: 'ArrowRight' });
|
|
344
|
-
await expect(handle).toHaveAttribute('aria-valuenow', '50');
|
|
345
|
-
await expect(canvas.getByText('Value: 50')).toBeInTheDocument();
|
|
346
|
-
});
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Accessibility guidance for labelling the slider, exposing its value as text,
|
|
352
|
-
* and keeping it operable from the keyboard.
|
|
353
|
-
*/
|
|
354
|
-
export const Accessibility: Story = {
|
|
355
|
-
render: () => ({
|
|
356
|
-
components: { UiSlider },
|
|
357
|
-
setup() {
|
|
358
|
-
const defaultValue = ref([60]);
|
|
359
|
-
const accessibleValue = ref([60]);
|
|
360
|
-
return { defaultValue, accessibleValue };
|
|
361
|
-
},
|
|
362
|
-
template: `
|
|
363
|
-
<section class="flex flex-col gap-6 p-4">
|
|
364
|
-
<div>
|
|
365
|
-
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
366
|
-
Accessibility
|
|
367
|
-
</h2>
|
|
368
|
-
</div>
|
|
369
|
-
|
|
370
|
-
<div class="flex flex-col gap-6">
|
|
371
|
-
<div class="flex flex-col gap-2">
|
|
372
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
373
|
-
Label what the slider controls
|
|
374
|
-
</h3>
|
|
375
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
376
|
-
Each handle is announced as a slider named <code>Value</code>
|
|
377
|
-
(<code>Value 1</code> / <code>Value 2</code> for a range), which
|
|
378
|
-
says nothing about what is being adjusted. Put a visible heading
|
|
379
|
-
or <code>label</code> next to the slider so the surrounding
|
|
380
|
-
context supplies the meaning.
|
|
381
|
-
</p>
|
|
382
|
-
</div>
|
|
383
|
-
|
|
384
|
-
<div class="flex flex-col gap-2">
|
|
385
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
386
|
-
Show the current value as text
|
|
387
|
-
</h3>
|
|
388
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
389
|
-
Handle position alone is not perceivable for everyone. Render the
|
|
390
|
-
value next to the slider so it can be read, magnified, and
|
|
391
|
-
translated — the same number assistive technology gets from
|
|
392
|
-
<code>aria-valuenow</code>.
|
|
393
|
-
</p>
|
|
394
|
-
</div>
|
|
395
|
-
|
|
396
|
-
<div class="flex flex-col gap-2">
|
|
397
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
398
|
-
Keep it keyboard operable
|
|
399
|
-
</h3>
|
|
400
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
401
|
-
Every handle is a Tab stop and moves with the arrow keys.
|
|
402
|
-
<code>Home</code> and <code>End</code> jump to the minimum and
|
|
403
|
-
maximum, and <code>Page Up</code> / <code>Page Down</code> (or
|
|
404
|
-
<code>Shift</code> + arrow) move in larger jumps — so a long
|
|
405
|
-
range never needs hundreds of key presses.
|
|
406
|
-
</p>
|
|
407
|
-
</div>
|
|
408
|
-
|
|
409
|
-
<div class="flex flex-col gap-2">
|
|
410
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
411
|
-
Give small handles room
|
|
412
|
-
</h3>
|
|
413
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
414
|
-
The handle is smaller than the 24px minimum target size, so it
|
|
415
|
-
relies on the WCAG 2.5.8 spacing exception: keep other controls
|
|
416
|
-
at least 24px away, and don't crowd several sliders together.
|
|
417
|
-
</p>
|
|
418
|
-
</div>
|
|
419
|
-
|
|
420
|
-
<div class="flex flex-col gap-2">
|
|
421
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
422
|
-
Enable accessibility theme
|
|
423
|
-
</h3>
|
|
424
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
425
|
-
When accessibility is required, enable our accessibility theme.
|
|
426
|
-
This increases contrast and makes sure there are no color
|
|
427
|
-
contrast issues.
|
|
428
|
-
</p>
|
|
429
|
-
</div>
|
|
430
|
-
</div>
|
|
431
|
-
|
|
432
|
-
<div class="grid gap-4 md:grid-cols-2">
|
|
433
|
-
<div class="flex flex-col gap-3">
|
|
434
|
-
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
435
|
-
Default
|
|
436
|
-
</h3>
|
|
437
|
-
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
438
|
-
<p class="label-s-medium text-content-on-surface-primary">Volume</p>
|
|
439
|
-
<div class="my-3">
|
|
440
|
-
<UiSlider v-model="defaultValue" />
|
|
441
|
-
</div>
|
|
442
|
-
<p class="body-s-regular text-content-on-surface-muted">Value: {{ defaultValue[0] }}</p>
|
|
443
|
-
</div>
|
|
444
|
-
</div>
|
|
445
|
-
|
|
446
|
-
<div class="accessible-theme flex flex-col gap-3">
|
|
447
|
-
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
448
|
-
Accessible
|
|
449
|
-
</h3>
|
|
450
|
-
<div class="flex min-h-20 flex-col justify-center border border-border-surface-default p-6">
|
|
451
|
-
<p class="label-s-medium text-content-on-surface-primary">Volume</p>
|
|
452
|
-
<div class="my-3">
|
|
453
|
-
<UiSlider v-model="accessibleValue" />
|
|
454
|
-
</div>
|
|
455
|
-
<p class="body-s-regular text-content-on-surface-muted">Value: {{ accessibleValue[0] }}</p>
|
|
456
|
-
</div>
|
|
457
|
-
</div>
|
|
458
|
-
</div>
|
|
459
|
-
</section>
|
|
460
|
-
`,
|
|
461
|
-
}),
|
|
462
|
-
tags: ['!autodocs'],
|
|
463
|
-
parameters: {
|
|
464
|
-
a11y: { test: 'off' },
|
|
465
|
-
chromatic: {
|
|
466
|
-
disableSnapshot: true,
|
|
467
|
-
},
|
|
468
|
-
docs: {
|
|
469
|
-
canvas: {
|
|
470
|
-
sourceState: 'none',
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
1020
|
},
|
|
474
1021
|
};
|
|
475
1022
|
|
|
@@ -502,9 +1049,13 @@ export const Accessibility: Story = {
|
|
|
502
1049
|
* feeds it straight back in, so every play also exercises the wrapper's
|
|
503
1050
|
* controlled round-trip and its `valueCommit` re-emit.
|
|
504
1051
|
* @param step Stepping interval for the slider under test.
|
|
1052
|
+
* @param extraProps Further `UiSlider` props, such as `showValue`.
|
|
505
1053
|
* @returns Vue component options for a story `render` function.
|
|
506
1054
|
*/
|
|
507
|
-
function renderControlledSlider(
|
|
1055
|
+
function renderControlledSlider(
|
|
1056
|
+
step = 5,
|
|
1057
|
+
extraProps: Partial<UiSliderProps> = {},
|
|
1058
|
+
) {
|
|
508
1059
|
return {
|
|
509
1060
|
components: { UiSlider },
|
|
510
1061
|
setup() {
|
|
@@ -513,7 +1064,7 @@ function renderControlledSlider(step = 5) {
|
|
|
513
1064
|
value.value = next;
|
|
514
1065
|
onUpdateModelValue(next);
|
|
515
1066
|
};
|
|
516
|
-
return { value, update, step, onValueCommit };
|
|
1067
|
+
return { value, update, step, extraProps, onValueCommit };
|
|
517
1068
|
},
|
|
518
1069
|
template: `
|
|
519
1070
|
<div class="w-full max-w-72">
|
|
@@ -524,6 +1075,7 @@ function renderControlledSlider(step = 5) {
|
|
|
524
1075
|
:min="0"
|
|
525
1076
|
:max="100"
|
|
526
1077
|
:step="step"
|
|
1078
|
+
v-bind="extraProps"
|
|
527
1079
|
@update:model-value="update"
|
|
528
1080
|
@value-commit="onValueCommit"
|
|
529
1081
|
/>
|
|
@@ -943,3 +1495,183 @@ export const MobileBreakpoint: Story = {
|
|
|
943
1495
|
);
|
|
944
1496
|
},
|
|
945
1497
|
};
|
|
1498
|
+
|
|
1499
|
+
// The value-and-steps slider the test-only stories below drive.
|
|
1500
|
+
const valueAndStepsProps: Partial<UiSliderProps> = {
|
|
1501
|
+
showValue: true,
|
|
1502
|
+
showSteps: true,
|
|
1503
|
+
formatValue: (value: number) => `${value}%`,
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* The shown value follows the handle as it moves, and the handle lands on a
|
|
1508
|
+
* dot at every step, including both ends. Hidden test-only story.
|
|
1509
|
+
*/
|
|
1510
|
+
export const ValueAndStepsKeyboard: Story = {
|
|
1511
|
+
name: 'test - Value And Steps Keyboard',
|
|
1512
|
+
tags: ['!dev', '!autodocs'],
|
|
1513
|
+
parameters: {
|
|
1514
|
+
// Focus moves and the value changes during the play function.
|
|
1515
|
+
chromatic: { disableSnapshot: true },
|
|
1516
|
+
},
|
|
1517
|
+
render: () => renderControlledSlider(10, valueAndStepsProps),
|
|
1518
|
+
play: async ({ canvasElement, step }) => {
|
|
1519
|
+
// Scenario (UiSlider): a keyboard user moves the handle step by step and
|
|
1520
|
+
// to both ends; the shown value, its dot and what is announced follow.
|
|
1521
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
1522
|
+
const marks = stepMarksIn(canvasElement);
|
|
1523
|
+
|
|
1524
|
+
await step(
|
|
1525
|
+
'keyboard: the handle is reachable via Tab (WCAG 2.1.1)',
|
|
1526
|
+
async () => {
|
|
1527
|
+
await userEvent.tab();
|
|
1528
|
+
await expect(handle).toHaveFocus();
|
|
1529
|
+
},
|
|
1530
|
+
);
|
|
1531
|
+
|
|
1532
|
+
await step(
|
|
1533
|
+
'keyboard: an arrow key moves one step and the shown value follows',
|
|
1534
|
+
async () => {
|
|
1535
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1536
|
+
await waitFor(async () => {
|
|
1537
|
+
await expect(shownValueIn(canvasElement)).toHaveTextContent('60%');
|
|
1538
|
+
});
|
|
1539
|
+
await expectCentredOnHandle(handle, shownValueIn(canvasElement));
|
|
1540
|
+
},
|
|
1541
|
+
);
|
|
1542
|
+
|
|
1543
|
+
await step(
|
|
1544
|
+
'interaction: at both ends the handle sits on the first and last dot',
|
|
1545
|
+
async () => {
|
|
1546
|
+
await userEvent.keyboard('{End}');
|
|
1547
|
+
await waitFor(async () => {
|
|
1548
|
+
await expect(shownValueIn(canvasElement)).toHaveTextContent('100%');
|
|
1549
|
+
});
|
|
1550
|
+
await expectCentredOnHandle(handle, marks[marks.length - 1]);
|
|
1551
|
+
|
|
1552
|
+
await userEvent.keyboard('{Home}');
|
|
1553
|
+
await waitFor(async () => {
|
|
1554
|
+
await expect(shownValueIn(canvasElement)).toHaveTextContent('0%');
|
|
1555
|
+
});
|
|
1556
|
+
await expectCentredOnHandle(handle, marks[0]);
|
|
1557
|
+
},
|
|
1558
|
+
);
|
|
1559
|
+
|
|
1560
|
+
await step(
|
|
1561
|
+
'screen-reader: the handle announces each new value in the shown format',
|
|
1562
|
+
async () => {
|
|
1563
|
+
await expect(handle).toHaveAttribute('aria-valuenow', '0');
|
|
1564
|
+
await expect(handle).toHaveAttribute('aria-valuetext', '0%');
|
|
1565
|
+
await expect(shownValueIn(canvasElement)).toHaveAttribute(
|
|
1566
|
+
'aria-hidden',
|
|
1567
|
+
'true',
|
|
1568
|
+
);
|
|
1569
|
+
},
|
|
1570
|
+
);
|
|
1571
|
+
},
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* The shown value stays readable, on screen and with its handle at 200% page
|
|
1576
|
+
* zoom (WCAG 1.4.4). Hidden test-only story.
|
|
1577
|
+
*/
|
|
1578
|
+
export const ValueZoomMagnification: Story = {
|
|
1579
|
+
name: 'test - Value Zoom Magnification',
|
|
1580
|
+
tags: ['!dev', '!autodocs'],
|
|
1581
|
+
globals: { zoom: '200' },
|
|
1582
|
+
parameters: {
|
|
1583
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
1584
|
+
// already covers magnified snapshots.
|
|
1585
|
+
chromatic: { disableSnapshot: true },
|
|
1586
|
+
},
|
|
1587
|
+
render: () => renderControlledSlider(10, valueAndStepsProps),
|
|
1588
|
+
play: async ({ canvasElement, step }) => {
|
|
1589
|
+
// Scenario (UiSlider): magnified, the value above the handle is still
|
|
1590
|
+
// visible inside the viewport and moves with the handle.
|
|
1591
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
1592
|
+
|
|
1593
|
+
await step(
|
|
1594
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1595
|
+
async () => {
|
|
1596
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1597
|
+
},
|
|
1598
|
+
);
|
|
1599
|
+
|
|
1600
|
+
await step('zoom: the shown value stays visible on screen', async () => {
|
|
1601
|
+
const shownValue = shownValueIn(canvasElement);
|
|
1602
|
+
await expect(shownValue).toBeVisible();
|
|
1603
|
+
const { left, right, top } = shownValue.getBoundingClientRect();
|
|
1604
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
1605
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth);
|
|
1606
|
+
await expect(top).toBeGreaterThanOrEqual(0);
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
await step(
|
|
1610
|
+
'zoom: the shown value moves with the handle when magnified',
|
|
1611
|
+
async () => {
|
|
1612
|
+
await userEvent.tab();
|
|
1613
|
+
await expect(handle).toHaveFocus();
|
|
1614
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
1615
|
+
await waitFor(async () => {
|
|
1616
|
+
await expect(shownValueIn(canvasElement)).toHaveTextContent('60%');
|
|
1617
|
+
});
|
|
1618
|
+
await expectCentredOnHandle(handle, shownValueIn(canvasElement));
|
|
1619
|
+
},
|
|
1620
|
+
);
|
|
1621
|
+
},
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* At the 320px breakpoint the shown value stays inside the viewport at both
|
|
1626
|
+
* ends of the range, never rises above the slider, and never blocks a tap on
|
|
1627
|
+
* the handle. Hidden test-only story.
|
|
1628
|
+
*/
|
|
1629
|
+
export const ValueMobileBreakpoint: Story = {
|
|
1630
|
+
name: 'test - Value Mobile Breakpoint',
|
|
1631
|
+
tags: ['!dev', '!autodocs'],
|
|
1632
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1633
|
+
parameters: {
|
|
1634
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
1635
|
+
chromatic: { disableSnapshot: true },
|
|
1636
|
+
},
|
|
1637
|
+
render: () => renderControlledSlider(10, valueAndStepsProps),
|
|
1638
|
+
play: async ({ canvasElement, step }) => {
|
|
1639
|
+
// Scenario (UiSlider): on a phone the value never pokes out of the screen
|
|
1640
|
+
// or over the content above the slider, whichever end the handle is at.
|
|
1641
|
+
const handle = within(canvasElement).getByRole('slider', { name: 'Value' });
|
|
1642
|
+
const slider = canvasElement.querySelector('[data-slot="slider"]');
|
|
1643
|
+
if (!slider) throw new Error('No slider in the story');
|
|
1644
|
+
|
|
1645
|
+
await step(
|
|
1646
|
+
'mobile: the shown value stays inside the 320px viewport and below the top of the slider at both ends (WCAG 1.4.10 Reflow)',
|
|
1647
|
+
async () => {
|
|
1648
|
+
await userEvent.tab();
|
|
1649
|
+
await expect(handle).toHaveFocus();
|
|
1650
|
+
|
|
1651
|
+
for (const [key, text] of [
|
|
1652
|
+
['{End}', '100%'],
|
|
1653
|
+
['{Home}', '0%'],
|
|
1654
|
+
]) {
|
|
1655
|
+
await userEvent.keyboard(key);
|
|
1656
|
+
await waitFor(async () => {
|
|
1657
|
+
await expect(shownValueIn(canvasElement)).toHaveTextContent(text);
|
|
1658
|
+
});
|
|
1659
|
+
const labelBox = shownValueIn(canvasElement).getBoundingClientRect();
|
|
1660
|
+
await expect(labelBox.left).toBeGreaterThanOrEqual(0);
|
|
1661
|
+
await expect(labelBox.right).toBeLessThanOrEqual(window.innerWidth);
|
|
1662
|
+
await expect(labelBox.top).toBeGreaterThanOrEqual(
|
|
1663
|
+
slider.getBoundingClientRect().top,
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
);
|
|
1668
|
+
|
|
1669
|
+
await step(
|
|
1670
|
+
'mobile: nothing covers the handle, so a tap on it still reaches it (WCAG 2.5.8)',
|
|
1671
|
+
async () => {
|
|
1672
|
+
const { x, y } = centreOf(handle);
|
|
1673
|
+
await expect(document.elementFromPoint(x, y)).toBe(handle);
|
|
1674
|
+
},
|
|
1675
|
+
);
|
|
1676
|
+
},
|
|
1677
|
+
};
|