@aleph-alpha/ui-library 5.3.1 → 5.5.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/config.d.ts +38 -3
- package/config.js +103 -6
- package/dist/system/lib.js +8926 -8768
- package/dist/system/patterns/UiDataTable/UiDataTableFilterMenu.vue.d.ts +24 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
- package/dist/system/patterns/UiDataTable/index.d.ts +1 -0
- package/dist/system/patterns/UiDataTable/types.d.ts +23 -1
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +5 -1
- package/docs/public-docs/getting-started-designers.md +3 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -1
- package/src/components/UiAutocomplete/UiAutocomplete.vue +5 -5
- package/src/components/UiButton/UiButton.stories.ts +14 -14
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +260 -9
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiChip/UiChip.vue +1 -1
- package/src/components/UiDrawer/UiDrawer.stories.ts +2 -2
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
- package/src/components/UiEmpty/UiEmpty.vue +2 -2
- package/src/components/UiField/UiField.stories.ts +610 -3
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +2 -2
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +2 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/UiInput.vue +3 -3
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiKbd/UiKbd.stories.ts +14 -14
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +42 -42
- package/src/components/UiPopover/UiPopover.stories.ts +6 -6
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +2 -2
- package/src/components/UiResizable/UiResizable.stories.ts +6 -5
- package/src/components/UiSeparator/UiSeparator.stories.ts +6 -6
- package/src/components/UiSheet/UiSheet.stories.ts +2 -2
- package/src/components/UiSlider/UiSlider.stories.ts +8 -8
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
- package/src/components/UiSwitch/UiSwitch.stories.ts +2 -2
- package/src/components/UiTabs/UiTabs.stories.ts +30 -30
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +5 -3
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +9 -9
- package/src/components/UiTooltip/UiTooltip.stories.ts +3 -3
- package/src/components/core/accordion/AccordionTrigger.vue +2 -2
- package/src/components/core/alert/AlertDescription.vue +1 -1
- package/src/components/core/badge/index.ts +1 -1
- package/src/components/core/button/index.ts +2 -2
- package/src/components/core/calendar/CalendarCellTrigger.vue +2 -2
- package/src/components/core/calendar/CalendarHeadCell.vue +1 -1
- package/src/components/core/card/CardDescription.vue +1 -1
- package/src/components/core/checkbox/Checkbox.vue +1 -2
- package/src/components/core/drawer/DrawerDescription.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +1 -1
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/field/FieldSeparator.vue +1 -1
- package/src/components/core/input/Input.vue +2 -2
- package/src/components/core/item/index.ts +1 -1
- package/src/components/core/kbd/Kbd.vue +1 -1
- package/src/components/core/listbox/ListboxFilter.vue +1 -1
- package/src/components/core/listbox/ListboxGroupLabel.vue +4 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/native-select/NativeSelect.vue +3 -3
- package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
- package/src/components/core/navigation-menu/index.ts +1 -1
- package/src/components/core/radio-group/RadioGroupItem.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +2 -2
- package/src/components/core/range-calendar/RangeCalendarHeadCell.vue +1 -1
- package/src/components/core/select/SelectItem.vue +1 -1
- package/src/components/core/select/SelectLabel.vue +4 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/sheet/SheetDescription.vue +3 -1
- package/src/components/core/switch/Switch.vue +1 -1
- package/src/components/core/table/TableCaption.vue +3 -1
- package/src/components/core/tabs/TabsList.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/core/tags-input/TagsInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputItemDelete.vue +1 -1
- package/src/components/core/textarea/Textarea.vue +1 -1
- package/src/components/core/toggle/index.ts +3 -3
- package/src/components/core/toggle-group/index.ts +2 -2
- package/src/lib/useDrag.stories.ts +8 -8
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +913 -16
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +91 -0
- package/src/patterns/UiDataTable/UiDataTablePagination.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiDataTable/constants.ts +12 -0
- package/src/patterns/UiDataTable/index.ts +1 -0
- package/src/patterns/UiDataTable/types.ts +24 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +4 -4
- package/src/patterns/UiDatePicker/UiDatePicker.vue +1 -1
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +140 -12
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +1231 -438
- package/src/patterns/UiFloatActions/UiFloatActions.vue +1 -1
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +2 -2
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, inject, ref } from 'vue';
|
|
2
|
+
import { computed, inject, ref, useId } from 'vue';
|
|
3
3
|
import { FieldDescription as ShadcnFieldDescription } from '@/components/core/field';
|
|
4
4
|
import { UiCheckbox } from '@/components/UiCheckbox';
|
|
5
5
|
import type { UiFieldDescriptionProps } from './types';
|
|
@@ -22,6 +22,10 @@ const showCheckbox = computed(
|
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const checked = defineModel<UiCheckboxModelValue>();
|
|
25
|
+
|
|
26
|
+
// Associate the slotted text with the checkbox so assistive tech derives the
|
|
27
|
+
// accessible name from the visible label (and clicking the text toggles it).
|
|
28
|
+
const checkboxId = useId();
|
|
25
29
|
</script>
|
|
26
30
|
|
|
27
31
|
<template>
|
|
@@ -31,10 +35,11 @@ const checked = defineModel<UiCheckboxModelValue>();
|
|
|
31
35
|
|
|
32
36
|
<ShadcnFieldDescription v-else class="flex items-center gap-2">
|
|
33
37
|
<UiCheckbox
|
|
38
|
+
:id="checkboxId"
|
|
34
39
|
v-model="checked"
|
|
35
40
|
:name="props.name ?? ''"
|
|
36
41
|
:disabled="props.disabled"
|
|
37
42
|
/>
|
|
38
|
-
<
|
|
43
|
+
<label :for="checkboxId"><slot /></label>
|
|
39
44
|
</ShadcnFieldDescription>
|
|
40
45
|
</template>
|
|
@@ -83,7 +83,7 @@ function onError(e: { message: string }) {
|
|
|
83
83
|
@error="onError"
|
|
84
84
|
/>
|
|
85
85
|
<p v-if="lastError" class="body-14-regular text-destructive">{{ lastError }}</p>
|
|
86
|
-
<p v-if="names.length" class="body-14-regular text-muted
|
|
86
|
+
<p v-if="names.length" class="body-14-regular text-content-on-surface-muted">Selected: {{ names.join(', ') }}</p>
|
|
87
87
|
</div>
|
|
88
88
|
</template>`;
|
|
89
89
|
|
|
@@ -110,7 +110,7 @@ export const Default: Story = {
|
|
|
110
110
|
<div class="max-w-md gap-y-2">
|
|
111
111
|
<UiFileUploadBox v-bind="args" @update:files="onFiles" @error="onError" />
|
|
112
112
|
<p v-if="lastError" class="body-14-regular text-destructive">{{ lastError }}</p>
|
|
113
|
-
<p v-if="names.length" class="body-14-regular text-muted
|
|
113
|
+
<p v-if="names.length" class="body-14-regular text-content-on-surface-muted">Selected: {{ names.join(', ') }}</p>
|
|
114
114
|
</div>
|
|
115
115
|
`,
|
|
116
116
|
}),
|
|
@@ -150,7 +150,7 @@ function processFileList(fileList: FileList) {
|
|
|
150
150
|
<div
|
|
151
151
|
:class="
|
|
152
152
|
cn(
|
|
153
|
-
'border-border-surface-default bg-background-surface-modal focus-
|
|
153
|
+
'border-border-surface-default bg-background-surface-modal ui-focus-ring relative flex cursor-pointer flex-col items-center justify-center gap-4 rounded-lg border border-dashed p-8 text-center transition-colors',
|
|
154
154
|
isDragging && 'border-1 border-border-surface-focus-ring',
|
|
155
155
|
disabled && 'cursor-not-allowed opacity-50',
|
|
156
156
|
)
|
|
@@ -231,7 +231,7 @@ function processFileList(fileList: FileList) {
|
|
|
231
231
|
<slot name="footer">
|
|
232
232
|
<div
|
|
233
233
|
v-if="showFooter"
|
|
234
|
-
class="text-muted
|
|
234
|
+
class="text-content-on-surface-muted flex flex-wrap items-center justify-between gap-2 label-12-regular"
|
|
235
235
|
>
|
|
236
236
|
<span v-if="supportedTypesLabel?.trim()">{{
|
|
237
237
|
supportedTypesLabel
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, within } from 'storybook/test';
|
|
2
3
|
import UiInput from './UiInput.vue';
|
|
3
4
|
import { UiButton } from '../UiButton';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Pair it with `UiField` and `UiLabel` for accessible form layouts; for multi-line content, use `UiTextarea`.
|
|
7
|
+
* Text input is an interactive field that allows users to enter text and data. It’s commonly used in form patterns.
|
|
8
8
|
*/
|
|
9
9
|
const meta: Meta<typeof UiInput> = {
|
|
10
10
|
title: 'Components/UiInput',
|
|
@@ -35,6 +35,12 @@ export default meta;
|
|
|
35
35
|
|
|
36
36
|
type Story = StoryObj<typeof UiInput>;
|
|
37
37
|
|
|
38
|
+
// `UiInput` wires `defineModel` (`update:modelValue`) and emits `update:files`
|
|
39
|
+
// in file mode. Play functions bind these module-level spies via
|
|
40
|
+
// `@update:model-value` / `@update:files` and `mockClear()` them first.
|
|
41
|
+
const onUpdate = fn();
|
|
42
|
+
const onFiles = fn();
|
|
43
|
+
|
|
38
44
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
39
45
|
import { UiInput } from '@aleph-alpha/ui-library'
|
|
40
46
|
</script>
|
|
@@ -61,6 +67,20 @@ export const Default: Story = {
|
|
|
61
67
|
},
|
|
62
68
|
},
|
|
63
69
|
},
|
|
70
|
+
play: async ({ canvasElement, step }) => {
|
|
71
|
+
// Scenario (UiInput): assistive tech sees an editable textbox that is enabled by
|
|
72
|
+
// default. These checks don't mutate state, so the snapshot stays stable.
|
|
73
|
+
const canvas = within(canvasElement);
|
|
74
|
+
const input = canvas.getByRole('textbox');
|
|
75
|
+
|
|
76
|
+
await step(
|
|
77
|
+
'screen-reader: exposes an editable, enabled textbox (WCAG 4.1.2)',
|
|
78
|
+
async () => {
|
|
79
|
+
await expect(input).toBeEnabled();
|
|
80
|
+
await expect(input).toHaveAttribute('placeholder', 'Email');
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
},
|
|
64
84
|
};
|
|
65
85
|
|
|
66
86
|
const withLabelTemplateSource = `<script setup lang="ts">
|
|
@@ -95,6 +115,19 @@ export const WithLabel: Story = {
|
|
|
95
115
|
},
|
|
96
116
|
},
|
|
97
117
|
},
|
|
118
|
+
play: async ({ canvasElement, step }) => {
|
|
119
|
+
// Scenario (UiInput): a visible label is programmatically associated with the input,
|
|
120
|
+
// so screen readers announce it as the accessible name.
|
|
121
|
+
const canvas = within(canvasElement);
|
|
122
|
+
|
|
123
|
+
await step(
|
|
124
|
+
'screen-reader: the label names its associated input (WCAG 1.3.1 / 4.1.2)',
|
|
125
|
+
async () => {
|
|
126
|
+
const input = canvas.getByRole('textbox', { name: 'Email' });
|
|
127
|
+
await expect(input).toHaveAccessibleName('Email');
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
},
|
|
98
131
|
};
|
|
99
132
|
|
|
100
133
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
@@ -126,6 +159,24 @@ export const Disabled: Story = {
|
|
|
126
159
|
},
|
|
127
160
|
},
|
|
128
161
|
},
|
|
162
|
+
play: async ({ canvasElement, step }) => {
|
|
163
|
+
// Scenario (UiInput): a disabled input reports its disabled state to assistive tech
|
|
164
|
+
// and is removed from the tab order.
|
|
165
|
+
const canvas = within(canvasElement);
|
|
166
|
+
const input = canvas.getByRole('textbox');
|
|
167
|
+
|
|
168
|
+
await step(
|
|
169
|
+
'interaction: exposes the disabled state (WCAG 4.1.2)',
|
|
170
|
+
async () => {
|
|
171
|
+
await expect(input).toBeDisabled();
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
await step('keyboard: disabled input is skipped by Tab', async () => {
|
|
176
|
+
await userEvent.tab();
|
|
177
|
+
await expect(input).not.toHaveFocus();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
129
180
|
};
|
|
130
181
|
|
|
131
182
|
const withButtonTemplateSource = `<script setup lang="ts">
|
|
@@ -195,3 +246,286 @@ export const File: Story = {
|
|
|
195
246
|
},
|
|
196
247
|
},
|
|
197
248
|
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* `UiInput` is keyboard operable and emits `update:modelValue` as the user
|
|
252
|
+
* types. Hidden test-only story.
|
|
253
|
+
*/
|
|
254
|
+
export const TextEntry: Story = {
|
|
255
|
+
name: 'test - Text Entry',
|
|
256
|
+
tags: ['!dev', '!autodocs'],
|
|
257
|
+
render: () => ({
|
|
258
|
+
components: { UiInput },
|
|
259
|
+
setup() {
|
|
260
|
+
return { onUpdate };
|
|
261
|
+
},
|
|
262
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
263
|
+
<label for="full-name" class="body-14-medium">Full name</label>
|
|
264
|
+
<UiInput id="full-name" name="full-name" placeholder="Ada Lovelace" @update:model-value="onUpdate" />
|
|
265
|
+
</div>`,
|
|
266
|
+
}),
|
|
267
|
+
parameters: {
|
|
268
|
+
// The play function focuses the input and types; skip the visual snapshot.
|
|
269
|
+
chromatic: { disableSnapshot: true },
|
|
270
|
+
docs: {
|
|
271
|
+
description: {
|
|
272
|
+
story:
|
|
273
|
+
'Tab to focus the input, then type — each keystroke emits `update:modelValue`.',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
play: async ({ canvasElement, step }) => {
|
|
278
|
+
// Scenario (UiInput): a keyboard user tabs to the input and types, which updates the
|
|
279
|
+
// value and emits update:modelValue.
|
|
280
|
+
onUpdate.mockClear();
|
|
281
|
+
const canvas = within(canvasElement);
|
|
282
|
+
const input = canvas.getByRole('textbox', { name: 'Full name' });
|
|
283
|
+
|
|
284
|
+
await step(
|
|
285
|
+
'keyboard: input is reachable via Tab (WCAG 2.1.1)',
|
|
286
|
+
async () => {
|
|
287
|
+
await userEvent.tab();
|
|
288
|
+
await expect(input).toHaveFocus();
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
await step(
|
|
293
|
+
'interaction: typing updates the value and emits update:modelValue',
|
|
294
|
+
async () => {
|
|
295
|
+
await userEvent.keyboard('Ada Lovelace');
|
|
296
|
+
await expect(input).toHaveValue('Ada Lovelace');
|
|
297
|
+
await expect(onUpdate).toHaveBeenLastCalledWith('Ada Lovelace');
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* File mode exposes an accessible upload control and emits `update:files` with
|
|
305
|
+
* the selected files. Hidden test-only story.
|
|
306
|
+
*/
|
|
307
|
+
export const FileUpload: Story = {
|
|
308
|
+
name: 'test - File Upload',
|
|
309
|
+
tags: ['!dev', '!autodocs'],
|
|
310
|
+
render: () => ({
|
|
311
|
+
components: { UiInput },
|
|
312
|
+
setup() {
|
|
313
|
+
return { onFiles };
|
|
314
|
+
},
|
|
315
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
316
|
+
<label for="attachment" class="body-14-medium">Attachment</label>
|
|
317
|
+
<UiInput id="attachment" name="attachment" type="file" @update:files="onFiles" />
|
|
318
|
+
</div>`,
|
|
319
|
+
}),
|
|
320
|
+
parameters: {
|
|
321
|
+
chromatic: { disableSnapshot: true },
|
|
322
|
+
docs: {
|
|
323
|
+
description: {
|
|
324
|
+
story:
|
|
325
|
+
'Selecting a file emits `update:files` and shows the file name. The upload control is labelled for assistive tech.',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
play: async ({ canvasElement, step }) => {
|
|
330
|
+
// Scenario (UiInput): the hidden file input is labelled and, once a file is picked,
|
|
331
|
+
// the component emits update:files and shows the file name.
|
|
332
|
+
onFiles.mockClear();
|
|
333
|
+
const canvas = within(canvasElement);
|
|
334
|
+
const fileInput = canvas.getByLabelText('Upload') as HTMLInputElement;
|
|
335
|
+
|
|
336
|
+
await step(
|
|
337
|
+
'screen-reader: the upload control exposes an accessible name (WCAG 4.1.2)',
|
|
338
|
+
async () => {
|
|
339
|
+
await expect(fileInput).toHaveAccessibleName('Upload');
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
await step(
|
|
344
|
+
'interaction: selecting a file emits update:files and shows the file name',
|
|
345
|
+
async () => {
|
|
346
|
+
// Use globalThis.File because this module exports a `File` story that
|
|
347
|
+
// shadows the global File constructor.
|
|
348
|
+
const file = new globalThis.File(['hello'], 'hello.png', {
|
|
349
|
+
type: 'image/png',
|
|
350
|
+
});
|
|
351
|
+
await userEvent.upload(fileInput, file);
|
|
352
|
+
await expect(onFiles).toHaveBeenCalledWith([file]);
|
|
353
|
+
await expect(canvas.getByText('hello.png')).toBeInTheDocument();
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Design guidance for when to use the raw input vs. the field component.
|
|
361
|
+
*/
|
|
362
|
+
export const DesignNotes: Story = {
|
|
363
|
+
render: () => ({
|
|
364
|
+
template: `
|
|
365
|
+
<section class="flex flex-col gap-8 p-4 bg-surface-secondary">
|
|
366
|
+
<div>
|
|
367
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">Usage</h2>
|
|
368
|
+
<p class="body-16-regular mt-2 text-content-on-surface-primary">
|
|
369
|
+
The input field is a base component for form fields. It should not be
|
|
370
|
+
used on its own unless there is a specific need for text input without
|
|
371
|
+
labels. Please use the <strong class="font-semibold">field component</strong> and the
|
|
372
|
+
documentation there.
|
|
373
|
+
</p>
|
|
374
|
+
</div>
|
|
375
|
+
</section>
|
|
376
|
+
`,
|
|
377
|
+
}),
|
|
378
|
+
tags: ['!autodocs'],
|
|
379
|
+
parameters: {
|
|
380
|
+
a11y: { test: 'off' },
|
|
381
|
+
chromatic: {
|
|
382
|
+
disableSnapshot: true,
|
|
383
|
+
},
|
|
384
|
+
docs: {
|
|
385
|
+
canvas: {
|
|
386
|
+
sourceState: 'none',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Accessibility guidance for input labelling, keyboard operability, and contrast.
|
|
394
|
+
*/
|
|
395
|
+
export const Accessibility: Story = {
|
|
396
|
+
render: () => ({
|
|
397
|
+
components: { UiInput },
|
|
398
|
+
template: `
|
|
399
|
+
<section class="flex flex-col gap-6 p-4">
|
|
400
|
+
<div>
|
|
401
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
402
|
+
Accessibility
|
|
403
|
+
</h2>
|
|
404
|
+
</div>
|
|
405
|
+
|
|
406
|
+
<div class="flex flex-col gap-6">
|
|
407
|
+
<div class="flex flex-col gap-2">
|
|
408
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
409
|
+
Enable accessibility theme
|
|
410
|
+
</h3>
|
|
411
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
412
|
+
When accessibility is required, enable our accessibility theme. This
|
|
413
|
+
increases contrast and ensures there are no color contrast issues.
|
|
414
|
+
</p>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
|
|
418
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
419
|
+
<div class="flex flex-col gap-3">
|
|
420
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
421
|
+
Default
|
|
422
|
+
</h3>
|
|
423
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
424
|
+
<UiInput name="a11y-default" placeholder="Placeholder" class="max-w-xs" />
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
429
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
430
|
+
Accessible
|
|
431
|
+
</h3>
|
|
432
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
433
|
+
<UiInput name="a11y-accessible" placeholder="Placeholder" class="max-w-xs" />
|
|
434
|
+
</div>
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
</section>
|
|
438
|
+
`,
|
|
439
|
+
}),
|
|
440
|
+
tags: ['!autodocs'],
|
|
441
|
+
parameters: {
|
|
442
|
+
a11y: { test: 'off' },
|
|
443
|
+
chromatic: {
|
|
444
|
+
disableSnapshot: true,
|
|
445
|
+
},
|
|
446
|
+
docs: {
|
|
447
|
+
canvas: {
|
|
448
|
+
sourceState: 'none',
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const mobileBreakpointTemplateSource = `<script setup lang="ts">
|
|
455
|
+
import { UiInput } from '@aleph-alpha/ui-library'
|
|
456
|
+
</script>
|
|
457
|
+
|
|
458
|
+
<template>
|
|
459
|
+
<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
460
|
+
<label for="mobile-email" class="body-14-medium">Email</label>
|
|
461
|
+
<UiInput id="mobile-email" name="email" type="email" placeholder="Email" />
|
|
462
|
+
</div>
|
|
463
|
+
</template>`;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
467
|
+
* toolbar. Stays operable, keyboard navigable, and meets the minimum
|
|
468
|
+
* touch-target size (WCAG 2.5.8). Hidden test-only story.
|
|
469
|
+
*/
|
|
470
|
+
export const MobileBreakpoint: Story = {
|
|
471
|
+
name: 'test - Mobile Breakpoint',
|
|
472
|
+
tags: ['!dev', '!autodocs'],
|
|
473
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
474
|
+
render: () => ({
|
|
475
|
+
components: { UiInput },
|
|
476
|
+
setup() {
|
|
477
|
+
return { onUpdate };
|
|
478
|
+
},
|
|
479
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
480
|
+
<label for="mobile-email" class="body-14-medium">Email</label>
|
|
481
|
+
<UiInput id="mobile-email" name="email" type="email" placeholder="Email" @update:model-value="onUpdate" />
|
|
482
|
+
</div>`,
|
|
483
|
+
}),
|
|
484
|
+
parameters: {
|
|
485
|
+
// The play function focuses the input and types; skip the visual snapshot.
|
|
486
|
+
chromatic: { disableSnapshot: true },
|
|
487
|
+
docs: {
|
|
488
|
+
description: {
|
|
489
|
+
story:
|
|
490
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
491
|
+
},
|
|
492
|
+
source: { code: mobileBreakpointTemplateSource },
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
play: async ({ canvasElement, step }) => {
|
|
496
|
+
// Scenario (UiInput): at the 320px mobile breakpoint the input stays labelled,
|
|
497
|
+
// keyboard operable, and large enough to touch.
|
|
498
|
+
onUpdate.mockClear();
|
|
499
|
+
const canvas = within(canvasElement);
|
|
500
|
+
const input = canvas.getByRole('textbox', { name: 'Email' });
|
|
501
|
+
|
|
502
|
+
await step(
|
|
503
|
+
'mobile: exposes an enabled, labelled textbox at the 320px breakpoint (WCAG 4.1.2)',
|
|
504
|
+
async () => {
|
|
505
|
+
await expect(input).toBeVisible();
|
|
506
|
+
await expect(input).toBeEnabled();
|
|
507
|
+
await expect(input).toHaveAccessibleName('Email');
|
|
508
|
+
},
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
await step(
|
|
512
|
+
'mobile: stays keyboard operable — Tab focuses and typing emits update:modelValue (WCAG 2.1.1)',
|
|
513
|
+
async () => {
|
|
514
|
+
await userEvent.tab();
|
|
515
|
+
await expect(input).toHaveFocus();
|
|
516
|
+
await userEvent.keyboard('ada@company.com');
|
|
517
|
+
await expect(input).toHaveValue('ada@company.com');
|
|
518
|
+
await expect(onUpdate).toHaveBeenLastCalledWith('ada@company.com');
|
|
519
|
+
},
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
await step(
|
|
523
|
+
'mobile: meets the minimum touch-target size (WCAG 2.5.8)',
|
|
524
|
+
async () => {
|
|
525
|
+
const { width, height } = input.getBoundingClientRect();
|
|
526
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
527
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
528
|
+
},
|
|
529
|
+
);
|
|
530
|
+
},
|
|
531
|
+
};
|
|
@@ -61,7 +61,7 @@ function handleFilesChange(e: Event) {
|
|
|
61
61
|
<div
|
|
62
62
|
v-if="isFile"
|
|
63
63
|
v-bind="attrs"
|
|
64
|
-
class="flex h-9 w-full min-w-0 items-center gap-2 rounded-md border border-input bg-background-input-default px-1 transition-[color] outline-none
|
|
64
|
+
class="flex h-9 w-full min-w-0 items-center gap-2 rounded-md border border-input bg-background-input-default px-1 transition-[color] outline-none ui-focus-ring-within aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive"
|
|
65
65
|
:class="{
|
|
66
66
|
'pointer-events-none cursor-not-allowed opacity-50': props.disabled,
|
|
67
67
|
}"
|
|
@@ -84,8 +84,8 @@ function handleFilesChange(e: Event) {
|
|
|
84
84
|
</label>
|
|
85
85
|
</UiButton>
|
|
86
86
|
<span
|
|
87
|
-
class="placeholder:text-muted
|
|
88
|
-
:class="{ 'text-muted
|
|
87
|
+
class="placeholder:text-content-on-surface-muted flex-1 truncate pr-2 label-16-regular md:label-14-regular"
|
|
88
|
+
:class="{ 'text-content-on-surface-muted': fileDisplayValue === '' }"
|
|
89
89
|
:aria-controls="fileInputId"
|
|
90
90
|
>
|
|
91
91
|
{{ fileDisplayValue || filePlaceholder }}
|
|
@@ -4,37 +4,29 @@ import { describe, expect, test } from 'vitest';
|
|
|
4
4
|
import UiInput from '../UiInput.vue';
|
|
5
5
|
|
|
6
6
|
describe('UiInput', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// Text-input accessibility (textbox role, label association, disabled state),
|
|
8
|
+
// keyboard entry, and the `update:modelValue` / `update:files` events are
|
|
9
|
+
// covered by the Storybook play tests in `UiInput.stories.ts`. These unit
|
|
10
|
+
// tests cover the file-mode display logic that is unique to this wrapper.
|
|
11
|
+
test('file mode shows the selected file name', async () => {
|
|
12
|
+
const { getByLabelText, getByText } = render(UiInput, {
|
|
13
|
+
props: { name: 'attachment', type: 'file' },
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(getByRole('textbox')).toBeEnabled();
|
|
15
|
+
await userEvent.upload(
|
|
16
|
+
getByLabelText('Upload'),
|
|
17
|
+
new File(['hello'], 'hello.png', { type: 'image/png' }),
|
|
18
|
+
);
|
|
19
|
+
expect(getByText('hello.png')).toBeInTheDocument();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
test('
|
|
23
|
-
const {
|
|
24
|
-
props: {
|
|
25
|
-
disabled: true,
|
|
26
|
-
},
|
|
22
|
+
test('file mode shows a count when multiple files are selected', async () => {
|
|
23
|
+
const { getByLabelText, getByText } = render(UiInput, {
|
|
24
|
+
props: { name: 'attachments', type: 'file', multiple: true },
|
|
27
25
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { getByRole, emitted } = render(UiInput);
|
|
34
|
-
await userEvent.type(getByRole('textbox'), testValue);
|
|
35
|
-
const emittedModelValue = emitted('update:modelValue') as string[][];
|
|
36
|
-
expect(emittedModelValue[emittedModelValue.length - 1][0]).toMatch(
|
|
37
|
-
testValue,
|
|
38
|
-
);
|
|
26
|
+
await userEvent.upload(getByLabelText('Upload'), [
|
|
27
|
+
new File(['a'], 'a.png', { type: 'image/png' }),
|
|
28
|
+
new File(['b'], 'b.png', { type: 'image/png' }),
|
|
29
|
+
]);
|
|
30
|
+
expect(getByText('2 files selected')).toBeInTheDocument();
|
|
39
31
|
});
|
|
40
32
|
});
|