@aleph-alpha/ui-library 6.3.2 → 6.3.4
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.js +2 -0
- package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
- package/dist/system/components/UiStepper/context.d.ts +8 -0
- package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
- package/dist/system/icons/story-sidebar-icons.json +7 -0
- package/dist/system/lib.js +14776 -14598
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
- package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
- package/dist/system/story-sidebar-icons.json +7 -0
- package/package.json +1 -1
- package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
- package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
- package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
- package/src/components/UiFileUploadBox/types.ts +8 -5
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
- package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
- package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
- package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
- package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
- package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
- package/src/components/UiStepper/UiStepper.stories.ts +566 -2
- package/src/components/UiStepper/UiStepper.vue +14 -1
- package/src/components/UiStepper/UiStepperItem.vue +22 -4
- package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
- package/src/components/UiStepper/context.ts +10 -0
- package/src/components/core/calendar/Calendar.vue +234 -2
- package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
- package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
- package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
- package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
- package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
- package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
- package/src/patterns/UiLayout/layout-shell.ts +159 -13
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
- package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
- package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
|
@@ -21,15 +21,18 @@ describe('UiCalendar', () => {
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
const cells = getAllByRole('gridcell');
|
|
24
|
+
const dayTriggerSelector = '[data-slot="calendar-cell-trigger"]';
|
|
24
25
|
const clickableCell = cells.find(
|
|
25
|
-
(cell) =>
|
|
26
|
+
(cell) =>
|
|
27
|
+
!cell.querySelector(dayTriggerSelector)?.hasAttribute('data-disabled'),
|
|
26
28
|
);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const dayTrigger =
|
|
30
|
+
clickableCell?.querySelector<HTMLElement>(dayTriggerSelector);
|
|
31
|
+
if (!dayTrigger) {
|
|
32
|
+
throw new Error('Expected an enabled date trigger');
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
await userEvent.click(
|
|
35
|
+
await userEvent.click(dayTrigger);
|
|
33
36
|
expect(emitted('update:modelValue')).toHaveLength(1);
|
|
34
37
|
});
|
|
35
38
|
|
|
@@ -19,7 +19,9 @@ const props = withDefaults(defineProps<UiDropdownMenuTriggerProps>(), {
|
|
|
19
19
|
:disabled="props.disabled"
|
|
20
20
|
:as-child="props.asChild"
|
|
21
21
|
:aria-label="props.ariaLabel"
|
|
22
|
-
:class="
|
|
22
|
+
:class="
|
|
23
|
+
cn('ui-focus-ring', !props.asChild && 'rounded-sm', $attrs?.class ?? '')
|
|
24
|
+
"
|
|
23
25
|
>
|
|
24
26
|
<slot />
|
|
25
27
|
</ShadcnDropdownMenuTrigger>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fireEvent, fn, userEvent, within } from 'storybook/test';
|
|
2
3
|
import { ref } from 'vue';
|
|
3
4
|
import { UiFileUploadBox } from '@/components/UiFileUploadBox';
|
|
4
5
|
|
|
@@ -24,7 +25,6 @@ const meta: Meta<typeof UiFileUploadBox> = {
|
|
|
24
25
|
maxSizeLabel: '',
|
|
25
26
|
dropLabel: 'Drop files here',
|
|
26
27
|
chooseLabel: 'Choose files',
|
|
27
|
-
ariaLabel: 'File upload',
|
|
28
28
|
},
|
|
29
29
|
argTypes: {
|
|
30
30
|
accept: { control: 'text' },
|
|
@@ -54,6 +54,44 @@ const meta: Meta<typeof UiFileUploadBox> = {
|
|
|
54
54
|
export default meta;
|
|
55
55
|
type Story = StoryObj<typeof UiFileUploadBox>;
|
|
56
56
|
|
|
57
|
+
// The box emits native-style events and declares no handler props, so the plays
|
|
58
|
+
// bind module-level spies via the template and clear them per story.
|
|
59
|
+
const onPickerOpen = fn();
|
|
60
|
+
const onUpdateFiles = fn();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Renders the box with the spies bound, so plays can assert what it emits.
|
|
64
|
+
* @param args - Story args passed through to `UiFileUploadBox`.
|
|
65
|
+
*/
|
|
66
|
+
function renderWithSpies(args: Story['args']) {
|
|
67
|
+
return {
|
|
68
|
+
components: { UiFileUploadBox },
|
|
69
|
+
setup() {
|
|
70
|
+
return { args, onPickerOpen, onUpdateFiles };
|
|
71
|
+
},
|
|
72
|
+
template: `
|
|
73
|
+
<UiFileUploadBox
|
|
74
|
+
v-bind="args"
|
|
75
|
+
@picker-open="onPickerOpen"
|
|
76
|
+
@update:files="onUpdateFiles"
|
|
77
|
+
/>
|
|
78
|
+
`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Drops one file on `target` the way a browser drag-and-drop gesture would.
|
|
84
|
+
* @param target - Element inside the drop zone to drop onto.
|
|
85
|
+
* @param file - File carried by the drag.
|
|
86
|
+
*/
|
|
87
|
+
function dropFile(target: HTMLElement, file: File) {
|
|
88
|
+
const dataTransfer = new DataTransfer();
|
|
89
|
+
dataTransfer.items.add(file);
|
|
90
|
+
target.dispatchEvent(
|
|
91
|
+
new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer }),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
57
95
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
58
96
|
import { ref } from 'vue'
|
|
59
97
|
import { UiFileUploadBox } from '@aleph-alpha/ui-library'
|
|
@@ -104,11 +142,11 @@ export const Default: Story = {
|
|
|
104
142
|
function onError(e: { message: string }) {
|
|
105
143
|
lastError.value = e.message;
|
|
106
144
|
}
|
|
107
|
-
return { args, names, lastError, onFiles, onError };
|
|
145
|
+
return { args, names, lastError, onFiles, onError, onPickerOpen };
|
|
108
146
|
},
|
|
109
147
|
template: `
|
|
110
148
|
<div class="max-w-md gap-y-2">
|
|
111
|
-
<UiFileUploadBox v-bind="args" @update:files="onFiles" @error="onError" />
|
|
149
|
+
<UiFileUploadBox v-bind="args" @update:files="onFiles" @error="onError" @picker-open="onPickerOpen" />
|
|
112
150
|
<p v-if="lastError" class="body-14-regular text-destructive">{{ lastError }}</p>
|
|
113
151
|
<p v-if="names.length" class="body-14-regular text-content-on-surface-muted">Selected: {{ names.join(', ') }}</p>
|
|
114
152
|
</div>
|
|
@@ -119,4 +157,352 @@ export const Default: Story = {
|
|
|
119
157
|
source: { code: defaultTemplateSource },
|
|
120
158
|
},
|
|
121
159
|
},
|
|
160
|
+
play: async ({ canvasElement, step }) => {
|
|
161
|
+
// Scenario (UiFileUploadBox): the whole box is one target — a click or a drop
|
|
162
|
+
// anywhere inside it works, not only on the title or the icon.
|
|
163
|
+
onPickerOpen.mockClear();
|
|
164
|
+
const canvas = within(canvasElement);
|
|
165
|
+
|
|
166
|
+
await step(
|
|
167
|
+
'interaction: clicking anywhere in the box opens the file picker once',
|
|
168
|
+
async () => {
|
|
169
|
+
await userEvent.click(canvas.getByText('Choose files'));
|
|
170
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
await step(
|
|
175
|
+
'interaction: a file dropped outside the title and icon is accepted',
|
|
176
|
+
async () => {
|
|
177
|
+
dropFile(
|
|
178
|
+
canvas.getByText('Choose files'),
|
|
179
|
+
new File(['%PDF'], 'report.pdf', { type: 'application/pdf' }),
|
|
180
|
+
);
|
|
181
|
+
await expect(
|
|
182
|
+
await canvas.findByText('Selected: report.pdf'),
|
|
183
|
+
).toBeVisible();
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** Disabled: the box is skipped by Tab, reports itself as disabled, and ignores clicks and drops. */
|
|
190
|
+
export const Disabled: Story = {
|
|
191
|
+
args: {
|
|
192
|
+
disabled: true,
|
|
193
|
+
},
|
|
194
|
+
render: (args) => renderWithSpies(args),
|
|
195
|
+
parameters: {
|
|
196
|
+
docs: {
|
|
197
|
+
source: { code: '<UiFileUploadBox disabled />' },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
play: async ({ canvasElement, step }) => {
|
|
201
|
+
// Scenario (UiFileUploadBox): while uploads are blocked the box must not
|
|
202
|
+
// look operable to any input method.
|
|
203
|
+
onPickerOpen.mockClear();
|
|
204
|
+
onUpdateFiles.mockClear();
|
|
205
|
+
const canvas = within(canvasElement);
|
|
206
|
+
const zone = canvas.getByRole('button', { name: /Drop files here/ });
|
|
207
|
+
|
|
208
|
+
await step('interaction: the box reports its disabled state', async () => {
|
|
209
|
+
await expect(zone).toHaveAttribute('aria-disabled', 'true');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
await step('interaction: clicks do not open the picker', async () => {
|
|
213
|
+
await userEvent.click(zone);
|
|
214
|
+
await expect(onPickerOpen).not.toHaveBeenCalled();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
await step('interaction: dropped files are ignored', async () => {
|
|
218
|
+
dropFile(zone, new File(['x'], 'a.pdf', { type: 'application/pdf' }));
|
|
219
|
+
await expect(onUpdateFiles).not.toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Drag-over: while files are dragged over the box, its border, icon, and title
|
|
226
|
+
* change together so the state does not rely on colour alone.
|
|
227
|
+
*/
|
|
228
|
+
export const DragOver: Story = {
|
|
229
|
+
render: (args) => renderWithSpies(args),
|
|
230
|
+
parameters: {
|
|
231
|
+
docs: {
|
|
232
|
+
source: { code: '<UiFileUploadBox @update:files="onFiles" />' },
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
play: async ({ canvasElement, step }) => {
|
|
236
|
+
const canvas = within(canvasElement);
|
|
237
|
+
const zone = canvas.getByRole('button', { name: /Drop files here/ });
|
|
238
|
+
|
|
239
|
+
await step(
|
|
240
|
+
'interaction: dragging files anywhere over the box shows the drag-over state',
|
|
241
|
+
async () => {
|
|
242
|
+
await fireEvent.dragEnter(canvas.getByText('Choose files'));
|
|
243
|
+
await expect(zone).toHaveAttribute('data-dragging', 'true');
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
await step(
|
|
248
|
+
'interaction: leaving the box clears the drag-over state',
|
|
249
|
+
async () => {
|
|
250
|
+
await fireEvent.dragLeave(canvas.getByText('Choose files'));
|
|
251
|
+
await expect(zone).not.toHaveAttribute('data-dragging');
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Re-enter so the snapshot captures the drag-over state.
|
|
256
|
+
await fireEvent.dragEnter(zone);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Accessibility guidance for the box: its name, keyboard use, disabled state,
|
|
262
|
+
* and what may go in the `choose` slot — shown in the default and accessible themes.
|
|
263
|
+
*/
|
|
264
|
+
export const Accessibility: Story = {
|
|
265
|
+
render: () => ({
|
|
266
|
+
components: { UiFileUploadBox },
|
|
267
|
+
template: `
|
|
268
|
+
<section class="flex flex-col gap-6 p-4">
|
|
269
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
270
|
+
Accessibility
|
|
271
|
+
</h2>
|
|
272
|
+
|
|
273
|
+
<div class="flex flex-col gap-2">
|
|
274
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
275
|
+
Requirements
|
|
276
|
+
</h3>
|
|
277
|
+
<ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
|
|
278
|
+
<li>
|
|
279
|
+
The whole box is one native button: one Tab stop, and Enter or
|
|
280
|
+
Space opens the file picker
|
|
281
|
+
</li>
|
|
282
|
+
<li>
|
|
283
|
+
Its accessible name comes from the visible text. If you set
|
|
284
|
+
<code>ariaLabel</code>, start it with that text so speech-input
|
|
285
|
+
users can still say what they see (WCAG 2.5.3)
|
|
286
|
+
</li>
|
|
287
|
+
<li>
|
|
288
|
+
The <code>choose</code> slot renders inside the button, so put
|
|
289
|
+
only text or icons there — never a button or a link
|
|
290
|
+
</li>
|
|
291
|
+
<li>
|
|
292
|
+
When disabled, the box leaves the tab order, announces itself as
|
|
293
|
+
disabled, and ignores clicks and drops
|
|
294
|
+
</li>
|
|
295
|
+
<li>
|
|
296
|
+
Drag-and-drop is optional: clicking or the keyboard always
|
|
297
|
+
reaches the picker
|
|
298
|
+
</li>
|
|
299
|
+
</ul>
|
|
300
|
+
</div>
|
|
301
|
+
|
|
302
|
+
<div class="flex flex-col gap-2">
|
|
303
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
304
|
+
Enable accessibility theme
|
|
305
|
+
</h3>
|
|
306
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
307
|
+
When accessibility is required, enable our accessibility theme.
|
|
308
|
+
This increases contrast and ensures there are no color contrast
|
|
309
|
+
issues.
|
|
310
|
+
</p>
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
314
|
+
<div class="flex flex-col gap-3">
|
|
315
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
316
|
+
Default
|
|
317
|
+
</h3>
|
|
318
|
+
<UiFileUploadBox supported-types-label="Supported: PDF" />
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
322
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
323
|
+
Accessible
|
|
324
|
+
</h3>
|
|
325
|
+
<UiFileUploadBox supported-types-label="Supported: PDF" />
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
</section>
|
|
329
|
+
`,
|
|
330
|
+
}),
|
|
331
|
+
tags: ['!autodocs'],
|
|
332
|
+
parameters: {
|
|
333
|
+
chromatic: { disableSnapshot: true },
|
|
334
|
+
docs: {
|
|
335
|
+
canvas: { sourceState: 'none' },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Keyboard: the box is a single tab stop that opens the picker with Enter or
|
|
342
|
+
* Space. Hidden test-only story.
|
|
343
|
+
*/
|
|
344
|
+
export const KeyboardNavigation: Story = {
|
|
345
|
+
name: 'test - Keyboard Navigation',
|
|
346
|
+
tags: ['!dev', '!autodocs'],
|
|
347
|
+
parameters: {
|
|
348
|
+
// Focus moves during the play; skip the snapshot so the focus ring isn't a diff.
|
|
349
|
+
chromatic: { disableSnapshot: true },
|
|
350
|
+
controls: { disable: true },
|
|
351
|
+
},
|
|
352
|
+
render: (args) => renderWithSpies(args),
|
|
353
|
+
play: async ({ canvasElement, step }) => {
|
|
354
|
+
onPickerOpen.mockClear();
|
|
355
|
+
const canvas = within(canvasElement);
|
|
356
|
+
const zone = canvas.getByRole('button', { name: /Drop files here/ });
|
|
357
|
+
|
|
358
|
+
await step('keyboard: Tab focuses the box (WCAG 2.1.1)', async () => {
|
|
359
|
+
await userEvent.tab();
|
|
360
|
+
await expect(zone).toHaveFocus();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
await step('keyboard: Enter opens the file picker', async () => {
|
|
364
|
+
await userEvent.keyboard('{Enter}');
|
|
365
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
await step('keyboard: Space opens the file picker', async () => {
|
|
369
|
+
await userEvent.keyboard(' ');
|
|
370
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(2);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
await step(
|
|
374
|
+
'keyboard: the box is a single tab stop (WCAG 2.4.3)',
|
|
375
|
+
async () => {
|
|
376
|
+
await userEvent.tab();
|
|
377
|
+
await expect(zone).not.toHaveFocus();
|
|
378
|
+
},
|
|
379
|
+
);
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Screen reader: the box is one button named by its visible text; the icon and
|
|
385
|
+
* the hidden file input stay out of the accessibility tree. Hidden test-only story.
|
|
386
|
+
*/
|
|
387
|
+
export const ScreenReader: Story = {
|
|
388
|
+
name: 'test - Screen Reader',
|
|
389
|
+
tags: ['!dev', '!autodocs'],
|
|
390
|
+
parameters: {
|
|
391
|
+
controls: { disable: true },
|
|
392
|
+
},
|
|
393
|
+
render: (args) => renderWithSpies(args),
|
|
394
|
+
play: async ({ canvasElement, step }) => {
|
|
395
|
+
const canvas = within(canvasElement);
|
|
396
|
+
|
|
397
|
+
await step(
|
|
398
|
+
'screen-reader: the box is one button named by its visible text (WCAG 4.1.2, 2.5.3)',
|
|
399
|
+
async () => {
|
|
400
|
+
await expect(canvas.getByRole('button')).toHaveAccessibleName(
|
|
401
|
+
'Drop files here Choose files',
|
|
402
|
+
);
|
|
403
|
+
},
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
await step(
|
|
407
|
+
'screen-reader: the file input and the icon are hidden from assistive tech',
|
|
408
|
+
async () => {
|
|
409
|
+
const input = canvasElement.querySelector('input[type="file"]');
|
|
410
|
+
await expect(input).toHaveAttribute('aria-hidden', 'true');
|
|
411
|
+
await expect(input).toHaveAttribute('tabindex', '-1');
|
|
412
|
+
await expect(
|
|
413
|
+
canvas.getByRole('button').querySelector('[aria-hidden="true"]'),
|
|
414
|
+
).toBeInTheDocument();
|
|
415
|
+
},
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
await step(
|
|
419
|
+
'screen-reader: the footer hints are readable text',
|
|
420
|
+
async () => {
|
|
421
|
+
await expect(
|
|
422
|
+
canvas.getByText('Supported file types: PDF, DOCX, TXT'),
|
|
423
|
+
).toBeVisible();
|
|
424
|
+
await expect(canvas.getByText('Max size: 500 MB')).toBeVisible();
|
|
425
|
+
},
|
|
426
|
+
);
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Hidden test-only story.
|
|
432
|
+
*/
|
|
433
|
+
export const ZoomMagnification: Story = {
|
|
434
|
+
name: 'test - Zoom Magnification',
|
|
435
|
+
tags: ['!dev', '!autodocs'],
|
|
436
|
+
globals: { zoom: '200' },
|
|
437
|
+
parameters: {
|
|
438
|
+
// The accessible-reflow Chromatic mode already covers magnified snapshots.
|
|
439
|
+
chromatic: { disableSnapshot: true },
|
|
440
|
+
controls: { disable: true },
|
|
441
|
+
},
|
|
442
|
+
render: (args) => renderWithSpies(args),
|
|
443
|
+
play: async ({ canvasElement, step }) => {
|
|
444
|
+
onPickerOpen.mockClear();
|
|
445
|
+
const canvas = within(canvasElement);
|
|
446
|
+
const zone = canvas.getByRole('button', { name: /Drop files here/ });
|
|
447
|
+
|
|
448
|
+
await step(
|
|
449
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
450
|
+
async () => {
|
|
451
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
await step('zoom: the box and its labels stay visible', async () => {
|
|
456
|
+
await expect(zone).toBeVisible();
|
|
457
|
+
await expect(canvas.getByText('Choose files')).toBeVisible();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
await step('zoom: the picker still opens when magnified', async () => {
|
|
461
|
+
await userEvent.click(zone);
|
|
462
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Rendered at the mobile (320px reflow) breakpoint. Hidden test-only story.
|
|
469
|
+
*/
|
|
470
|
+
export const MobileBreakpoint: Story = {
|
|
471
|
+
name: 'test - Mobile Breakpoint',
|
|
472
|
+
tags: ['!dev', '!autodocs'],
|
|
473
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
474
|
+
parameters: {
|
|
475
|
+
// Reflow snapshots are covered by the accessible-reflow Chromatic mode.
|
|
476
|
+
chromatic: { disableSnapshot: true },
|
|
477
|
+
controls: { disable: true },
|
|
478
|
+
},
|
|
479
|
+
render: (args) => renderWithSpies(args),
|
|
480
|
+
play: async ({ canvasElement, step }) => {
|
|
481
|
+
onPickerOpen.mockClear();
|
|
482
|
+
const canvas = within(canvasElement);
|
|
483
|
+
const zone = canvas.getByRole('button', { name: /Drop files here/ });
|
|
484
|
+
|
|
485
|
+
await step(
|
|
486
|
+
'mobile: the box fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
487
|
+
async () => {
|
|
488
|
+
await expect(zone.getBoundingClientRect().width).toBeLessThanOrEqual(
|
|
489
|
+
window.innerWidth,
|
|
490
|
+
);
|
|
491
|
+
},
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
await step(
|
|
495
|
+
'mobile: the box meets the minimum touch-target size (WCAG 2.5.8)',
|
|
496
|
+
async () => {
|
|
497
|
+
const box = zone.getBoundingClientRect();
|
|
498
|
+
await expect(box.width).toBeGreaterThanOrEqual(24);
|
|
499
|
+
await expect(box.height).toBeGreaterThanOrEqual(24);
|
|
500
|
+
},
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
await step('mobile: the picker still opens at 320px', async () => {
|
|
504
|
+
await userEvent.click(zone);
|
|
505
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
506
|
+
});
|
|
507
|
+
},
|
|
122
508
|
};
|
|
@@ -19,7 +19,7 @@ const props = withDefaults(defineProps<UiFileUploadBoxProps>(), {
|
|
|
19
19
|
maxSizeLabel: '',
|
|
20
20
|
dropLabel: 'Drop files here',
|
|
21
21
|
chooseLabel: 'Choose files',
|
|
22
|
-
ariaLabel:
|
|
22
|
+
ariaLabel: undefined,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const emit = defineEmits<UiFileUploadBoxEmits>();
|
|
@@ -50,18 +50,12 @@ function openPicker() {
|
|
|
50
50
|
function onZoneClick(e: MouseEvent) {
|
|
51
51
|
if (props.disabled) return;
|
|
52
52
|
emit('click', e);
|
|
53
|
-
const t = e.target as HTMLElement | null;
|
|
54
|
-
if (t?.closest?.('button')) return;
|
|
55
53
|
openPicker();
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
function onZoneKeydown(e: KeyboardEvent) {
|
|
59
57
|
if (props.disabled) return;
|
|
60
58
|
emit('keydown', e);
|
|
61
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
openPicker();
|
|
64
|
-
}
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
function onDragEnter(e: DragEvent) {
|
|
@@ -147,86 +141,72 @@ function processFileList(fileList: FileList) {
|
|
|
147
141
|
@change="onInputChange"
|
|
148
142
|
/>
|
|
149
143
|
|
|
150
|
-
<
|
|
144
|
+
<button
|
|
145
|
+
type="button"
|
|
146
|
+
:tabindex="disabled ? -1 : undefined"
|
|
151
147
|
:class="
|
|
152
148
|
cn(
|
|
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
|
-
isDragging
|
|
149
|
+
'border-border-surface-default bg-background-surface-modal ui-focus-ring text-content-on-surface-primary relative flex cursor-pointer flex-col items-center justify-center gap-4 rounded-lg border border-dashed p-8 text-center transition-colors',
|
|
150
|
+
isDragging
|
|
151
|
+
? 'border-1 border-border-surface-focus-ring body-16-bold'
|
|
152
|
+
: 'body-16-medium',
|
|
155
153
|
disabled && 'cursor-not-allowed opacity-50',
|
|
156
154
|
)
|
|
157
155
|
"
|
|
156
|
+
:aria-disabled="disabled ? true : undefined"
|
|
157
|
+
:aria-label="ariaLabel"
|
|
158
|
+
:data-dragging="isDragging || undefined"
|
|
159
|
+
@click="onZoneClick"
|
|
160
|
+
@keydown="onZoneKeydown"
|
|
161
|
+
@focus="emit('focus', $event)"
|
|
162
|
+
@blur="emit('blur', $event)"
|
|
163
|
+
@dragenter="onDragEnter"
|
|
164
|
+
@dragleave="onDragLeave"
|
|
165
|
+
@dragover="onDragOver"
|
|
166
|
+
@drop="onDrop"
|
|
158
167
|
>
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
isDragging ? 'body-16-bold' : 'body-16-medium',
|
|
168
|
-
)
|
|
169
|
-
"
|
|
170
|
-
:aria-disabled="disabled ? true : undefined"
|
|
171
|
-
:aria-label="ariaLabel"
|
|
172
|
-
@click="onZoneClick"
|
|
173
|
-
@keydown="onZoneKeydown"
|
|
174
|
-
@focus="emit('focus', $event)"
|
|
175
|
-
@blur="emit('blur', $event)"
|
|
176
|
-
@dragenter="onDragEnter"
|
|
177
|
-
@dragleave="onDragLeave"
|
|
178
|
-
@dragover="onDragOver"
|
|
179
|
-
@drop="onDrop"
|
|
168
|
+
<span>
|
|
169
|
+
<slot name="title">{{ dropLabel }}</slot>
|
|
170
|
+
</span>
|
|
171
|
+
|
|
172
|
+
<!-- Fixed 80×80 slot so inner circle can go 72 → 80 on drag without shifting the drop zone. -->
|
|
173
|
+
<span
|
|
174
|
+
class="flex size-20 shrink-0 items-center justify-center"
|
|
175
|
+
aria-hidden="true"
|
|
180
176
|
>
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
177
|
+
<span
|
|
178
|
+
:class="
|
|
179
|
+
cn(
|
|
180
|
+
'flex items-center justify-center rounded-full transition-all duration-50 ease-out',
|
|
181
|
+
isDragging
|
|
182
|
+
? 'size-20 bg-background-accent-soft'
|
|
183
|
+
: 'size-18 bg-background-surface-muted',
|
|
184
|
+
)
|
|
185
|
+
"
|
|
189
186
|
>
|
|
190
|
-
<
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
isDragging
|
|
207
|
-
? 'text-content-on-surface-link'
|
|
208
|
-
: 'text-content-on-surface-muted',
|
|
209
|
-
)
|
|
210
|
-
"
|
|
211
|
-
aria-hidden="true"
|
|
212
|
-
/>
|
|
213
|
-
</slot>
|
|
214
|
-
</div>
|
|
215
|
-
</div>
|
|
216
|
-
</div>
|
|
187
|
+
<slot name="icon">
|
|
188
|
+
<UiIcon
|
|
189
|
+
name="cloud-upload"
|
|
190
|
+
:size="32"
|
|
191
|
+
:class="
|
|
192
|
+
cn(
|
|
193
|
+
isDragging
|
|
194
|
+
? 'text-content-on-surface-link'
|
|
195
|
+
: 'text-content-on-surface-muted',
|
|
196
|
+
)
|
|
197
|
+
"
|
|
198
|
+
aria-hidden="true"
|
|
199
|
+
/>
|
|
200
|
+
</slot>
|
|
201
|
+
</span>
|
|
202
|
+
</span>
|
|
217
203
|
|
|
218
204
|
<slot name="choose">
|
|
219
|
-
<UiButton
|
|
220
|
-
|
|
221
|
-
variant="secondary"
|
|
222
|
-
size="sm"
|
|
223
|
-
:disabled="disabled"
|
|
224
|
-
@click.stop="openPicker"
|
|
225
|
-
>
|
|
226
|
-
{{ chooseLabel }}
|
|
205
|
+
<UiButton as-child variant="secondary" size="sm">
|
|
206
|
+
<span>{{ chooseLabel }}</span>
|
|
227
207
|
</UiButton>
|
|
228
208
|
</slot>
|
|
229
|
-
</
|
|
209
|
+
</button>
|
|
230
210
|
|
|
231
211
|
<slot name="footer">
|
|
232
212
|
<div
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
import UiFileUploadBox from '../UiFileUploadBox.vue';
|
|
5
|
+
|
|
6
|
+
function dropFile(target: HTMLElement, file: File) {
|
|
7
|
+
const files = {
|
|
8
|
+
length: 1,
|
|
9
|
+
item: (i: number) => (i === 0 ? file : null),
|
|
10
|
+
*[Symbol.iterator]() {
|
|
11
|
+
yield file;
|
|
12
|
+
},
|
|
13
|
+
} as unknown as FileList;
|
|
14
|
+
const event = new Event('drop', { bubbles: true, cancelable: true });
|
|
15
|
+
Object.defineProperty(event, 'dataTransfer', { value: { files } });
|
|
16
|
+
target.dispatchEvent(event);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('UiFileUploadBox', () => {
|
|
20
|
+
const file = new File(['x'], 'a.txt', { type: 'text/plain' });
|
|
21
|
+
|
|
22
|
+
test('accepts files dropped outside the title and icon area', () => {
|
|
23
|
+
const { getByText, emitted } = render(UiFileUploadBox);
|
|
24
|
+
dropFile(getByText('Choose files'), file);
|
|
25
|
+
expect(emitted('update:files')).toEqual([[[file]]]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('ignores dropped files when disabled', () => {
|
|
29
|
+
const { getByText, emitted } = render(UiFileUploadBox, {
|
|
30
|
+
props: { disabled: true },
|
|
31
|
+
});
|
|
32
|
+
dropFile(getByText('Choose files'), file);
|
|
33
|
+
expect(emitted('update:files')).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test.each(['Drop files here', 'Choose files'])(
|
|
37
|
+
'clicking "%s" opens the picker once',
|
|
38
|
+
async (text) => {
|
|
39
|
+
const { getByText, emitted } = render(UiFileUploadBox);
|
|
40
|
+
await userEvent.click(getByText(text));
|
|
41
|
+
expect(emitted('pickerOpen')).toHaveLength(1);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
});
|