@aleph-alpha/ui-library 6.3.4 → 6.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.js +2 -1
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
- package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
- package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
- package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
- package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +10 -1
- package/dist/system/components/UiFileItem/index.d.ts +1 -1
- package/dist/system/components/UiFileItem/types.d.ts +81 -5
- package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
- package/dist/system/components/UiPopover/UiPopoverContent.vue.d.ts +1 -0
- package/dist/system/components/UiPopover/types.d.ts +6 -0
- package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
- package/dist/system/components/UiToggle/types.d.ts +10 -2
- package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
- package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
- package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
- package/dist/system/components/core/popover/PopoverContent.vue.d.ts +1 -0
- package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
- package/dist/system/components/core/toggle/index.d.ts +47 -2
- package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
- package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
- package/dist/system/components/core/toggle-group/context.d.ts +1 -0
- package/dist/system/components/core/toggle-group/index.d.ts +10 -2
- package/dist/system/lib.js +10646 -10369
- package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +171 -12
- package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
- package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +9 -4
- package/package.json +2 -2
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
- package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
- package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
- package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
- package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
- package/src/components/UiDropdownMenu/types.ts +3 -0
- package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
- package/src/components/UiFileItem/UiFileItem.vue +111 -6
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +52 -0
- package/src/components/UiFileItem/index.ts +1 -0
- package/src/components/UiFileItem/types.ts +82 -5
- package/src/components/UiPopover/UiPopover.stories.ts +141 -0
- package/src/components/UiPopover/UiPopoverContent.vue +2 -0
- package/src/components/UiPopover/__tests__/UiPopover.test.ts +48 -0
- package/src/components/UiPopover/types.ts +7 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +104 -32
- package/src/components/UiToggle/UiToggle.stories.ts +386 -261
- package/src/components/UiToggle/UiToggle.vue +2 -0
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
- package/src/components/UiToggle/types.ts +10 -2
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
- package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
- package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
- package/src/components/UiToggleGroup/types.ts +12 -2
- package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
- package/src/components/core/popover/PopoverContent.vue +9 -3
- package/src/components/core/toggle/Toggle.vue +12 -5
- package/src/components/core/toggle/index.ts +47 -19
- package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
- package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
- package/src/components/core/toggle-group/context.ts +1 -0
- package/src/components/core/toggle-group/index.ts +10 -24
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +808 -22
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +188 -6
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
- package/src/patterns/UiTopBar/accessory-dropdown.ts +5 -3
|
@@ -65,9 +65,14 @@ const meta: Meta<typeof UiToggleGroup> = {
|
|
|
65
65
|
},
|
|
66
66
|
variant: {
|
|
67
67
|
control: 'select',
|
|
68
|
-
options: ['default', 'outline'
|
|
68
|
+
options: ['default', 'outline'],
|
|
69
69
|
description: 'The visual style variant applied to all items',
|
|
70
70
|
},
|
|
71
|
+
soft: {
|
|
72
|
+
control: 'boolean',
|
|
73
|
+
description:
|
|
74
|
+
'Fills the selected items with the subtle hover overlay instead of the accent surface',
|
|
75
|
+
},
|
|
71
76
|
size: {
|
|
72
77
|
control: 'select',
|
|
73
78
|
options: ['default', 'sm', 'lg'],
|
|
@@ -81,6 +86,7 @@ const meta: Meta<typeof UiToggleGroup> = {
|
|
|
81
86
|
args: {
|
|
82
87
|
type: 'multiple',
|
|
83
88
|
variant: 'default',
|
|
89
|
+
soft: false,
|
|
84
90
|
size: 'default',
|
|
85
91
|
disabled: false,
|
|
86
92
|
},
|
|
@@ -108,6 +114,7 @@ const onUpdate = fn();
|
|
|
108
114
|
* @param config.items Items to render.
|
|
109
115
|
* @param [config.initialValue] Initially selected value(s).
|
|
110
116
|
* @param [config.variant] Visual style applied to all items.
|
|
117
|
+
* @param [config.soft] Whether selected items use the subtle overlay fill.
|
|
111
118
|
* @param [config.size] Size applied to all items.
|
|
112
119
|
* @param [config.disabled] Whether the whole group is disabled.
|
|
113
120
|
* @param [config.disabledValue] Value of a single item to disable.
|
|
@@ -119,7 +126,8 @@ function renderGroup(config: {
|
|
|
119
126
|
groupLabel: string;
|
|
120
127
|
items: ToggleItemConfig[];
|
|
121
128
|
initialValue?: string | string[];
|
|
122
|
-
variant?: 'default' | 'outline'
|
|
129
|
+
variant?: 'default' | 'outline';
|
|
130
|
+
soft?: boolean;
|
|
123
131
|
size?: 'default' | 'sm' | 'lg';
|
|
124
132
|
disabled?: boolean;
|
|
125
133
|
disabledValue?: string;
|
|
@@ -139,6 +147,7 @@ function renderGroup(config: {
|
|
|
139
147
|
:type="config.type"
|
|
140
148
|
:aria-label="config.groupLabel"
|
|
141
149
|
:variant="config.variant ?? 'default'"
|
|
150
|
+
:soft="config.soft ?? false"
|
|
142
151
|
:size="config.size ?? 'default'"
|
|
143
152
|
:disabled="config.disabled ?? false"
|
|
144
153
|
@update:model-value="onUpdate"
|
|
@@ -158,6 +167,27 @@ function renderGroup(config: {
|
|
|
158
167
|
});
|
|
159
168
|
}
|
|
160
169
|
|
|
170
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
171
|
+
import { ref } from 'vue'
|
|
172
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
173
|
+
|
|
174
|
+
const formatting = ref<string[]>([])
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
<template>
|
|
178
|
+
<UiToggleGroup v-model="formatting" type="multiple" aria-label="Text formatting">
|
|
179
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
180
|
+
<UiIcon name="bold" :size="16" />
|
|
181
|
+
</UiToggleGroupItem>
|
|
182
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
183
|
+
<UiIcon name="italic" :size="16" />
|
|
184
|
+
</UiToggleGroupItem>
|
|
185
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
186
|
+
<UiIcon name="underline" :size="16" />
|
|
187
|
+
</UiToggleGroupItem>
|
|
188
|
+
</UiToggleGroup>
|
|
189
|
+
</template>`;
|
|
190
|
+
|
|
161
191
|
/**
|
|
162
192
|
* The default toggle group with multiple selection enabled: every item toggles
|
|
163
193
|
* on and off independently, like a row of checkboxes.
|
|
@@ -166,6 +196,13 @@ function renderGroup(config: {
|
|
|
166
196
|
* announced with no name, and each icon-only item carries its own.
|
|
167
197
|
*/
|
|
168
198
|
export const Default: Story = {
|
|
199
|
+
parameters: {
|
|
200
|
+
docs: {
|
|
201
|
+
source: {
|
|
202
|
+
code: defaultTemplateSource,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
169
206
|
render: (args) => ({
|
|
170
207
|
components: { UiToggleGroup, UiToggleGroupItem, UiIcon },
|
|
171
208
|
setup() {
|
|
@@ -178,6 +215,7 @@ export const Default: Story = {
|
|
|
178
215
|
type="multiple"
|
|
179
216
|
aria-label="Text formatting"
|
|
180
217
|
:variant="args.variant"
|
|
218
|
+
:soft="args.soft"
|
|
181
219
|
:size="args.size"
|
|
182
220
|
:disabled="args.disabled"
|
|
183
221
|
>
|
|
@@ -217,6 +255,32 @@ export const Default: Story = {
|
|
|
217
255
|
},
|
|
218
256
|
};
|
|
219
257
|
|
|
258
|
+
const outlineTemplateSource = `<script setup lang="ts">
|
|
259
|
+
import { ref } from 'vue'
|
|
260
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
261
|
+
|
|
262
|
+
const formatting = ref<string[]>([])
|
|
263
|
+
</script>
|
|
264
|
+
|
|
265
|
+
<template>
|
|
266
|
+
<UiToggleGroup
|
|
267
|
+
v-model="formatting"
|
|
268
|
+
type="multiple"
|
|
269
|
+
variant="outline"
|
|
270
|
+
aria-label="Text formatting"
|
|
271
|
+
>
|
|
272
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
273
|
+
<UiIcon name="bold" :size="16" />
|
|
274
|
+
</UiToggleGroupItem>
|
|
275
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
276
|
+
<UiIcon name="italic" :size="16" />
|
|
277
|
+
</UiToggleGroupItem>
|
|
278
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
279
|
+
<UiIcon name="underline" :size="16" />
|
|
280
|
+
</UiToggleGroupItem>
|
|
281
|
+
</UiToggleGroup>
|
|
282
|
+
</template>`;
|
|
283
|
+
|
|
220
284
|
/**
|
|
221
285
|
* The outline variant gives every item a visible border, which keeps the
|
|
222
286
|
* unpressed items discoverable when the group sits on its own rather than
|
|
@@ -229,7 +293,14 @@ export const Outline: Story = {
|
|
|
229
293
|
items: formattingItems,
|
|
230
294
|
variant: 'outline',
|
|
231
295
|
}),
|
|
232
|
-
parameters: {
|
|
296
|
+
parameters: {
|
|
297
|
+
controls: { disable: true },
|
|
298
|
+
docs: {
|
|
299
|
+
source: {
|
|
300
|
+
code: outlineTemplateSource,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
233
304
|
play: async ({ canvasElement, step }) => {
|
|
234
305
|
// Scenario (Toggle group): a style variation carries the same semantics.
|
|
235
306
|
// Non-mutating, so the visual snapshot stays stable.
|
|
@@ -249,6 +320,33 @@ export const Outline: Story = {
|
|
|
249
320
|
},
|
|
250
321
|
};
|
|
251
322
|
|
|
323
|
+
const singleTemplateSource = `<script setup lang="ts">
|
|
324
|
+
import { ref } from 'vue'
|
|
325
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
326
|
+
|
|
327
|
+
// A single-choice group holds one value, not an array.
|
|
328
|
+
const alignment = ref('center')
|
|
329
|
+
</script>
|
|
330
|
+
|
|
331
|
+
<template>
|
|
332
|
+
<UiToggleGroup
|
|
333
|
+
v-model="alignment"
|
|
334
|
+
type="single"
|
|
335
|
+
variant="outline"
|
|
336
|
+
aria-label="Text alignment"
|
|
337
|
+
>
|
|
338
|
+
<UiToggleGroupItem value="left" aria-label="Align left">
|
|
339
|
+
<UiIcon name="align-left" :size="16" />
|
|
340
|
+
</UiToggleGroupItem>
|
|
341
|
+
<UiToggleGroupItem value="center" aria-label="Align center">
|
|
342
|
+
<UiIcon name="align-center" :size="16" />
|
|
343
|
+
</UiToggleGroupItem>
|
|
344
|
+
<UiToggleGroupItem value="right" aria-label="Align right">
|
|
345
|
+
<UiIcon name="align-right" :size="16" />
|
|
346
|
+
</UiToggleGroupItem>
|
|
347
|
+
</UiToggleGroup>
|
|
348
|
+
</template>`;
|
|
349
|
+
|
|
252
350
|
/**
|
|
253
351
|
* With `type="single"` only one item can be pressed at a time, and pressing a
|
|
254
352
|
* new one releases the previous. Focus enters the group on the pressed item.
|
|
@@ -261,7 +359,14 @@ export const Single: Story = {
|
|
|
261
359
|
variant: 'outline',
|
|
262
360
|
initialValue: 'center',
|
|
263
361
|
}),
|
|
264
|
-
parameters: {
|
|
362
|
+
parameters: {
|
|
363
|
+
controls: { disable: true },
|
|
364
|
+
docs: {
|
|
365
|
+
source: {
|
|
366
|
+
code: singleTemplateSource,
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
265
370
|
play: async ({ canvasElement, step }) => {
|
|
266
371
|
// Scenario (Toggle group): single-choice resting state. Non-mutating, so
|
|
267
372
|
// the visual snapshot stays stable.
|
|
@@ -280,6 +385,33 @@ export const Single: Story = {
|
|
|
280
385
|
},
|
|
281
386
|
};
|
|
282
387
|
|
|
388
|
+
const multipleTemplateSource = `<script setup lang="ts">
|
|
389
|
+
import { ref } from 'vue'
|
|
390
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
391
|
+
|
|
392
|
+
// A multiple-choice group holds an array, so items are independent.
|
|
393
|
+
const formatting = ref(['bold', 'underline'])
|
|
394
|
+
</script>
|
|
395
|
+
|
|
396
|
+
<template>
|
|
397
|
+
<UiToggleGroup
|
|
398
|
+
v-model="formatting"
|
|
399
|
+
type="multiple"
|
|
400
|
+
variant="outline"
|
|
401
|
+
aria-label="Text formatting"
|
|
402
|
+
>
|
|
403
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
404
|
+
<UiIcon name="bold" :size="16" />
|
|
405
|
+
</UiToggleGroupItem>
|
|
406
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
407
|
+
<UiIcon name="italic" :size="16" />
|
|
408
|
+
</UiToggleGroupItem>
|
|
409
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
410
|
+
<UiIcon name="underline" :size="16" />
|
|
411
|
+
</UiToggleGroupItem>
|
|
412
|
+
</UiToggleGroup>
|
|
413
|
+
</template>`;
|
|
414
|
+
|
|
283
415
|
/**
|
|
284
416
|
* Multiple-choice mode, with more than one item pressed at once. Unlike the
|
|
285
417
|
* single-choice group there is no mutual exclusion, so the state of each item
|
|
@@ -293,7 +425,14 @@ export const Multiple: Story = {
|
|
|
293
425
|
variant: 'outline',
|
|
294
426
|
initialValue: ['bold', 'underline'],
|
|
295
427
|
}),
|
|
296
|
-
parameters: {
|
|
428
|
+
parameters: {
|
|
429
|
+
controls: { disable: true },
|
|
430
|
+
docs: {
|
|
431
|
+
source: {
|
|
432
|
+
code: multipleTemplateSource,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
},
|
|
297
436
|
play: async ({ canvasElement, step }) => {
|
|
298
437
|
// Scenario (Toggle group): multiple-choice resting state. Non-mutating, so
|
|
299
438
|
// the visual snapshot stays stable.
|
|
@@ -316,9 +455,245 @@ export const Multiple: Story = {
|
|
|
316
455
|
},
|
|
317
456
|
};
|
|
318
457
|
|
|
458
|
+
const softTemplateSource = `<script setup lang="ts">
|
|
459
|
+
import { ref } from 'vue'
|
|
460
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
461
|
+
|
|
462
|
+
const formatting = ref(['bold', 'underline'])
|
|
463
|
+
</script>
|
|
464
|
+
|
|
465
|
+
<template>
|
|
466
|
+
<UiToggleGroup
|
|
467
|
+
v-model="formatting"
|
|
468
|
+
type="multiple"
|
|
469
|
+
soft
|
|
470
|
+
aria-label="Text formatting"
|
|
471
|
+
>
|
|
472
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
473
|
+
<UiIcon name="bold" :size="16" />
|
|
474
|
+
</UiToggleGroupItem>
|
|
475
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
476
|
+
<UiIcon name="italic" :size="16" />
|
|
477
|
+
</UiToggleGroupItem>
|
|
478
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
479
|
+
<UiIcon name="underline" :size="16" />
|
|
480
|
+
</UiToggleGroupItem>
|
|
481
|
+
</UiToggleGroup>
|
|
482
|
+
</template>`;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* The `soft` flag fills selected items with the subtle hover overlay instead of
|
|
486
|
+
* a muted surface, leaving every other state untouched. Shown with two items
|
|
487
|
+
* selected, since that is the only state it changes. The quieter the fill, the
|
|
488
|
+
* more `aria-pressed` is doing the work — which is why it stays correct here
|
|
489
|
+
* (WCAG 1.4.1 Use of Color).
|
|
490
|
+
*/
|
|
491
|
+
export const Soft: Story = {
|
|
492
|
+
render: renderGroup({
|
|
493
|
+
type: 'multiple',
|
|
494
|
+
groupLabel: 'Text formatting',
|
|
495
|
+
items: formattingItems,
|
|
496
|
+
soft: true,
|
|
497
|
+
initialValue: ['bold', 'underline'],
|
|
498
|
+
}),
|
|
499
|
+
parameters: {
|
|
500
|
+
// The play toggles items; skip the visual snapshot.
|
|
501
|
+
chromatic: { disableSnapshot: true },
|
|
502
|
+
controls: { disable: true },
|
|
503
|
+
docs: {
|
|
504
|
+
source: {
|
|
505
|
+
code: softTemplateSource,
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
play: async ({ canvasElement, step }) => {
|
|
510
|
+
// Scenario (Toggle group): the soft fill is a visual swap only, so the
|
|
511
|
+
// selected items must still read as pressed and keep toggling. The play
|
|
512
|
+
// changes the selection, so the snapshot is skipped below.
|
|
513
|
+
const canvas = within(canvasElement);
|
|
514
|
+
const bold = canvas.getByRole('button', { name: 'Bold' });
|
|
515
|
+
const italic = canvas.getByRole('button', { name: 'Italic' });
|
|
516
|
+
|
|
517
|
+
await step(
|
|
518
|
+
'interaction: the softly filled items still report the pressed state (WCAG 1.4.1)',
|
|
519
|
+
async () => {
|
|
520
|
+
await expect(bold).toHaveAttribute('aria-pressed', 'true');
|
|
521
|
+
await expect(bold).toHaveAttribute('data-state', 'on');
|
|
522
|
+
await expect(italic).toHaveAttribute('aria-pressed', 'false');
|
|
523
|
+
},
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
await step(
|
|
527
|
+
'interaction: every item carries the soft fill rather than the muted one',
|
|
528
|
+
async () => {
|
|
529
|
+
for (const item of canvas.getAllByRole('button')) {
|
|
530
|
+
await expect(item).toHaveClass(
|
|
531
|
+
'aria-pressed:bg-overlay-hover-subtle',
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
await step(
|
|
538
|
+
'interaction: the soft fill does not change how the group toggles',
|
|
539
|
+
async () => {
|
|
540
|
+
await userEvent.click(italic);
|
|
541
|
+
await expect(italic).toHaveAttribute('aria-pressed', 'true');
|
|
542
|
+
// Multiple-choice, so the neighbour keeps its own state.
|
|
543
|
+
await expect(bold).toHaveAttribute('aria-pressed', 'true');
|
|
544
|
+
|
|
545
|
+
await userEvent.click(bold);
|
|
546
|
+
await expect(bold).toHaveAttribute('aria-pressed', 'false');
|
|
547
|
+
},
|
|
548
|
+
);
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
const softItemOverrideTemplateSource = `<script setup lang="ts">
|
|
553
|
+
import { ref } from 'vue'
|
|
554
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
555
|
+
|
|
556
|
+
const formatting = ref(['bold', 'italic'])
|
|
557
|
+
</script>
|
|
558
|
+
|
|
559
|
+
<template>
|
|
560
|
+
<!-- The group sets the soft fill; a single item opts back out of it. -->
|
|
561
|
+
<UiToggleGroup
|
|
562
|
+
v-model="formatting"
|
|
563
|
+
type="multiple"
|
|
564
|
+
soft
|
|
565
|
+
aria-label="Text formatting"
|
|
566
|
+
>
|
|
567
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
568
|
+
<UiIcon name="bold" :size="16" />
|
|
569
|
+
</UiToggleGroupItem>
|
|
570
|
+
<UiToggleGroupItem value="italic" :soft="false" aria-label="Italic">
|
|
571
|
+
<UiIcon name="italic" :size="16" />
|
|
572
|
+
</UiToggleGroupItem>
|
|
573
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
574
|
+
<UiIcon name="underline" :size="16" />
|
|
575
|
+
</UiToggleGroupItem>
|
|
576
|
+
</UiToggleGroup>
|
|
577
|
+
</template>`;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* An item may opt out of the group's fill: `soft` on `UiToggleGroupItem`
|
|
581
|
+
* overrides whatever the group set, the same way `variant` and `size` do. Both
|
|
582
|
+
* selected items here report the same state — only their fill differs, which is
|
|
583
|
+
* exactly why the state has to live in `aria-pressed` rather than in the colour.
|
|
584
|
+
*/
|
|
585
|
+
export const SoftItemOverride: Story = {
|
|
586
|
+
render: () => ({
|
|
587
|
+
components: { UiToggleGroup, UiToggleGroupItem, UiIcon },
|
|
588
|
+
setup() {
|
|
589
|
+
const formatting = ref<string[]>(['bold', 'italic']);
|
|
590
|
+
return { formatting };
|
|
591
|
+
},
|
|
592
|
+
template: `
|
|
593
|
+
<UiToggleGroup
|
|
594
|
+
v-model="formatting"
|
|
595
|
+
type="multiple"
|
|
596
|
+
soft
|
|
597
|
+
aria-label="Text formatting"
|
|
598
|
+
>
|
|
599
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
600
|
+
<UiIcon name="bold" :size="16" />
|
|
601
|
+
</UiToggleGroupItem>
|
|
602
|
+
<UiToggleGroupItem value="italic" :soft="false" aria-label="Italic">
|
|
603
|
+
<UiIcon name="italic" :size="16" />
|
|
604
|
+
</UiToggleGroupItem>
|
|
605
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
606
|
+
<UiIcon name="underline" :size="16" />
|
|
607
|
+
</UiToggleGroupItem>
|
|
608
|
+
</UiToggleGroup>
|
|
609
|
+
`,
|
|
610
|
+
}),
|
|
611
|
+
parameters: {
|
|
612
|
+
// The play toggles the overriding item; skip the visual snapshot.
|
|
613
|
+
chromatic: { disableSnapshot: true },
|
|
614
|
+
controls: { disable: true },
|
|
615
|
+
docs: {
|
|
616
|
+
source: {
|
|
617
|
+
code: softItemOverrideTemplateSource,
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
play: async ({ canvasElement, step }) => {
|
|
622
|
+
// Scenario (Toggle group): one item overrides the group's fill. Both
|
|
623
|
+
// selected items must stay indistinguishable to assistive technology.
|
|
624
|
+
const canvas = within(canvasElement);
|
|
625
|
+
const bold = canvas.getByRole('button', { name: 'Bold' });
|
|
626
|
+
const italic = canvas.getByRole('button', { name: 'Italic' });
|
|
627
|
+
const underline = canvas.getByRole('button', { name: 'Underline' });
|
|
628
|
+
|
|
629
|
+
await step(
|
|
630
|
+
'interaction: the item keeps the group fill unless it overrides it',
|
|
631
|
+
async () => {
|
|
632
|
+
for (const inherited of [bold, underline]) {
|
|
633
|
+
await expect(inherited).toHaveClass(
|
|
634
|
+
'aria-pressed:bg-overlay-hover-subtle',
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
await expect(italic).toHaveClass(
|
|
638
|
+
'aria-pressed:bg-background-surface-muted-subtle',
|
|
639
|
+
);
|
|
640
|
+
await expect(italic).not.toHaveClass(
|
|
641
|
+
'aria-pressed:bg-overlay-hover-subtle',
|
|
642
|
+
);
|
|
643
|
+
},
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
await step(
|
|
647
|
+
'interaction: the two fills are announced identically (WCAG 1.4.1)',
|
|
648
|
+
async () => {
|
|
649
|
+
await expect(bold).toHaveAttribute('aria-pressed', 'true');
|
|
650
|
+
await expect(italic).toHaveAttribute('aria-pressed', 'true');
|
|
651
|
+
await expect(underline).toHaveAttribute('aria-pressed', 'false');
|
|
652
|
+
},
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
await step(
|
|
656
|
+
'interaction: the overriding item toggles like any other',
|
|
657
|
+
async () => {
|
|
658
|
+
await userEvent.click(italic);
|
|
659
|
+
await expect(italic).toHaveAttribute('aria-pressed', 'false');
|
|
660
|
+
await expect(bold).toHaveAttribute('aria-pressed', 'true');
|
|
661
|
+
},
|
|
662
|
+
);
|
|
663
|
+
},
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
const smallTemplateSource = `<script setup lang="ts">
|
|
667
|
+
import { ref } from 'vue'
|
|
668
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
669
|
+
|
|
670
|
+
const alignment = ref('left')
|
|
671
|
+
</script>
|
|
672
|
+
|
|
673
|
+
<template>
|
|
674
|
+
<UiToggleGroup
|
|
675
|
+
v-model="alignment"
|
|
676
|
+
type="single"
|
|
677
|
+
variant="outline"
|
|
678
|
+
size="sm"
|
|
679
|
+
aria-label="Text alignment"
|
|
680
|
+
>
|
|
681
|
+
<UiToggleGroupItem value="left" aria-label="Align left">
|
|
682
|
+
<UiIcon name="align-left" :size="16" />
|
|
683
|
+
</UiToggleGroupItem>
|
|
684
|
+
<UiToggleGroupItem value="center" aria-label="Align center">
|
|
685
|
+
<UiIcon name="align-center" :size="16" />
|
|
686
|
+
</UiToggleGroupItem>
|
|
687
|
+
<UiToggleGroupItem value="right" aria-label="Align right">
|
|
688
|
+
<UiIcon name="align-right" :size="16" />
|
|
689
|
+
</UiToggleGroupItem>
|
|
690
|
+
</UiToggleGroup>
|
|
691
|
+
</template>`;
|
|
692
|
+
|
|
319
693
|
/**
|
|
320
|
-
* The small size (`size="sm"`) for compact toolbars.
|
|
321
|
-
* the 24×24px floor in WCAG 2.5.8
|
|
694
|
+
* The small size (`size="sm"`) for compact toolbars. The sizes differ in
|
|
695
|
+
* padding, and this tightest one still clears the 24×24px floor in WCAG 2.5.8
|
|
696
|
+
* Target Size (Minimum).
|
|
322
697
|
*/
|
|
323
698
|
export const Small: Story = {
|
|
324
699
|
render: renderGroup({
|
|
@@ -329,7 +704,14 @@ export const Small: Story = {
|
|
|
329
704
|
size: 'sm',
|
|
330
705
|
initialValue: 'left',
|
|
331
706
|
}),
|
|
332
|
-
parameters: {
|
|
707
|
+
parameters: {
|
|
708
|
+
controls: { disable: true },
|
|
709
|
+
docs: {
|
|
710
|
+
source: {
|
|
711
|
+
code: smallTemplateSource,
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
},
|
|
333
715
|
play: async ({ canvasElement, step }) => {
|
|
334
716
|
// Scenario (Toggle group): the smallest size still has to be tappable.
|
|
335
717
|
// Non-mutating, so the visual snapshot stays stable.
|
|
@@ -348,6 +730,33 @@ export const Small: Story = {
|
|
|
348
730
|
},
|
|
349
731
|
};
|
|
350
732
|
|
|
733
|
+
const largeTemplateSource = `<script setup lang="ts">
|
|
734
|
+
import { ref } from 'vue'
|
|
735
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
736
|
+
|
|
737
|
+
const formatting = ref(['italic'])
|
|
738
|
+
</script>
|
|
739
|
+
|
|
740
|
+
<template>
|
|
741
|
+
<UiToggleGroup
|
|
742
|
+
v-model="formatting"
|
|
743
|
+
type="multiple"
|
|
744
|
+
variant="outline"
|
|
745
|
+
size="lg"
|
|
746
|
+
aria-label="Text formatting"
|
|
747
|
+
>
|
|
748
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
749
|
+
<UiIcon name="bold" :size="16" />
|
|
750
|
+
</UiToggleGroupItem>
|
|
751
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
752
|
+
<UiIcon name="italic" :size="16" />
|
|
753
|
+
</UiToggleGroupItem>
|
|
754
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
755
|
+
<UiIcon name="underline" :size="16" />
|
|
756
|
+
</UiToggleGroupItem>
|
|
757
|
+
</UiToggleGroup>
|
|
758
|
+
</template>`;
|
|
759
|
+
|
|
351
760
|
/**
|
|
352
761
|
* The large size (`size="lg"`) for touch-first surfaces and primary toolbars.
|
|
353
762
|
*/
|
|
@@ -360,7 +769,14 @@ export const Large: Story = {
|
|
|
360
769
|
size: 'lg',
|
|
361
770
|
initialValue: ['italic'],
|
|
362
771
|
}),
|
|
363
|
-
parameters: {
|
|
772
|
+
parameters: {
|
|
773
|
+
controls: { disable: true },
|
|
774
|
+
docs: {
|
|
775
|
+
source: {
|
|
776
|
+
code: largeTemplateSource,
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
},
|
|
364
780
|
play: async ({ canvasElement, step }) => {
|
|
365
781
|
// Scenario (Toggle group): the largest size variation. Non-mutating, so
|
|
366
782
|
// the visual snapshot stays stable.
|
|
@@ -379,6 +795,33 @@ export const Large: Story = {
|
|
|
379
795
|
},
|
|
380
796
|
};
|
|
381
797
|
|
|
798
|
+
const disabledTemplateSource = `<script setup lang="ts">
|
|
799
|
+
import { ref } from 'vue'
|
|
800
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
801
|
+
|
|
802
|
+
const formatting = ref<string[]>([])
|
|
803
|
+
</script>
|
|
804
|
+
|
|
805
|
+
<template>
|
|
806
|
+
<UiToggleGroup
|
|
807
|
+
v-model="formatting"
|
|
808
|
+
type="multiple"
|
|
809
|
+
variant="outline"
|
|
810
|
+
disabled
|
|
811
|
+
aria-label="Text formatting"
|
|
812
|
+
>
|
|
813
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
814
|
+
<UiIcon name="bold" :size="16" />
|
|
815
|
+
</UiToggleGroupItem>
|
|
816
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
817
|
+
<UiIcon name="italic" :size="16" />
|
|
818
|
+
</UiToggleGroupItem>
|
|
819
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
820
|
+
<UiIcon name="underline" :size="16" />
|
|
821
|
+
</UiToggleGroupItem>
|
|
822
|
+
</UiToggleGroup>
|
|
823
|
+
</template>`;
|
|
824
|
+
|
|
382
825
|
/**
|
|
383
826
|
* The whole group disabled. Every item reports `disabled` to assistive
|
|
384
827
|
* technology and the group drops out of the tab order entirely, so keyboard
|
|
@@ -392,7 +835,14 @@ export const Disabled: Story = {
|
|
|
392
835
|
variant: 'outline',
|
|
393
836
|
disabled: true,
|
|
394
837
|
}),
|
|
395
|
-
parameters: {
|
|
838
|
+
parameters: {
|
|
839
|
+
controls: { disable: true },
|
|
840
|
+
docs: {
|
|
841
|
+
source: {
|
|
842
|
+
code: disabledTemplateSource,
|
|
843
|
+
},
|
|
844
|
+
},
|
|
845
|
+
},
|
|
396
846
|
play: async ({ canvasElement, step }) => {
|
|
397
847
|
// Scenario (Toggle group): a disabled group refuses activation and is
|
|
398
848
|
// skipped by Tab. The forced click is a no-op, so the snapshot stays
|
|
@@ -430,6 +880,36 @@ export const Disabled: Story = {
|
|
|
430
880
|
},
|
|
431
881
|
};
|
|
432
882
|
|
|
883
|
+
const withTextTemplateSource = `<script setup lang="ts">
|
|
884
|
+
import { ref } from 'vue'
|
|
885
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
886
|
+
|
|
887
|
+
const alignment = ref('left')
|
|
888
|
+
</script>
|
|
889
|
+
|
|
890
|
+
<template>
|
|
891
|
+
<UiToggleGroup
|
|
892
|
+
v-model="alignment"
|
|
893
|
+
type="single"
|
|
894
|
+
variant="outline"
|
|
895
|
+
aria-label="Text alignment"
|
|
896
|
+
>
|
|
897
|
+
<!-- Each aria-label contains the visible word (WCAG 2.5.3). -->
|
|
898
|
+
<UiToggleGroupItem value="left" aria-label="Align left">
|
|
899
|
+
<UiIcon name="align-left" :size="16" />
|
|
900
|
+
<span>Left</span>
|
|
901
|
+
</UiToggleGroupItem>
|
|
902
|
+
<UiToggleGroupItem value="center" aria-label="Align center">
|
|
903
|
+
<UiIcon name="align-center" :size="16" />
|
|
904
|
+
<span>Center</span>
|
|
905
|
+
</UiToggleGroupItem>
|
|
906
|
+
<UiToggleGroupItem value="right" aria-label="Align right">
|
|
907
|
+
<UiIcon name="align-right" :size="16" />
|
|
908
|
+
<span>Right</span>
|
|
909
|
+
</UiToggleGroupItem>
|
|
910
|
+
</UiToggleGroup>
|
|
911
|
+
</template>`;
|
|
912
|
+
|
|
433
913
|
/**
|
|
434
914
|
* Items can include text next to the icon. The accessible name still comes from
|
|
435
915
|
* `aria-label`, which must contain the visible words so speech-input users can
|
|
@@ -444,7 +924,14 @@ export const WithText: Story = {
|
|
|
444
924
|
initialValue: 'left',
|
|
445
925
|
showText: true,
|
|
446
926
|
}),
|
|
447
|
-
parameters: {
|
|
927
|
+
parameters: {
|
|
928
|
+
controls: { disable: true },
|
|
929
|
+
docs: {
|
|
930
|
+
source: {
|
|
931
|
+
code: withTextTemplateSource,
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
},
|
|
448
935
|
play: async ({ canvasElement, step }) => {
|
|
449
936
|
// Scenario (Toggle group): items with text. Non-mutating, so the visual
|
|
450
937
|
// snapshot stays stable.
|
|
@@ -464,6 +951,32 @@ export const WithText: Story = {
|
|
|
464
951
|
},
|
|
465
952
|
};
|
|
466
953
|
|
|
954
|
+
const viewToggleTemplateSource = `<script setup lang="ts">
|
|
955
|
+
import { ref } from 'vue'
|
|
956
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
957
|
+
|
|
958
|
+
const view = ref('grid')
|
|
959
|
+
</script>
|
|
960
|
+
|
|
961
|
+
<template>
|
|
962
|
+
<UiToggleGroup
|
|
963
|
+
v-model="view"
|
|
964
|
+
type="single"
|
|
965
|
+
variant="outline"
|
|
966
|
+
aria-label="View mode"
|
|
967
|
+
>
|
|
968
|
+
<UiToggleGroupItem value="list" aria-label="List view">
|
|
969
|
+
<UiIcon name="list" :size="16" />
|
|
970
|
+
</UiToggleGroupItem>
|
|
971
|
+
<UiToggleGroupItem value="grid" aria-label="Grid view">
|
|
972
|
+
<UiIcon name="layout-grid" :size="16" />
|
|
973
|
+
</UiToggleGroupItem>
|
|
974
|
+
<UiToggleGroupItem value="columns" aria-label="Column view">
|
|
975
|
+
<UiIcon name="columns-3" :size="16" />
|
|
976
|
+
</UiToggleGroupItem>
|
|
977
|
+
</UiToggleGroup>
|
|
978
|
+
</template>`;
|
|
979
|
+
|
|
467
980
|
/**
|
|
468
981
|
* A common single-choice pattern: switching between list, grid, and column
|
|
469
982
|
* views.
|
|
@@ -476,7 +989,14 @@ export const ViewToggle: Story = {
|
|
|
476
989
|
variant: 'outline',
|
|
477
990
|
initialValue: 'grid',
|
|
478
991
|
}),
|
|
479
|
-
parameters: {
|
|
992
|
+
parameters: {
|
|
993
|
+
controls: { disable: true },
|
|
994
|
+
docs: {
|
|
995
|
+
source: {
|
|
996
|
+
code: viewToggleTemplateSource,
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
},
|
|
480
1000
|
play: async ({ canvasElement, step }) => {
|
|
481
1001
|
// Scenario (Toggle group): a realistic single-choice group. Non-mutating,
|
|
482
1002
|
// so the visual snapshot stays stable.
|
|
@@ -496,6 +1016,33 @@ export const ViewToggle: Story = {
|
|
|
496
1016
|
},
|
|
497
1017
|
};
|
|
498
1018
|
|
|
1019
|
+
const individualDisabledTemplateSource = `<script setup lang="ts">
|
|
1020
|
+
import { ref } from 'vue'
|
|
1021
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
1022
|
+
|
|
1023
|
+
const formatting = ref(['bold'])
|
|
1024
|
+
</script>
|
|
1025
|
+
|
|
1026
|
+
<template>
|
|
1027
|
+
<UiToggleGroup
|
|
1028
|
+
v-model="formatting"
|
|
1029
|
+
type="multiple"
|
|
1030
|
+
variant="outline"
|
|
1031
|
+
aria-label="Text formatting"
|
|
1032
|
+
>
|
|
1033
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1034
|
+
<UiIcon name="bold" :size="16" />
|
|
1035
|
+
</UiToggleGroupItem>
|
|
1036
|
+
<!-- Disabled per item; the arrow keys step over it. -->
|
|
1037
|
+
<UiToggleGroupItem value="italic" disabled aria-label="Italic">
|
|
1038
|
+
<UiIcon name="italic" :size="16" />
|
|
1039
|
+
</UiToggleGroupItem>
|
|
1040
|
+
<UiToggleGroupItem value="underline" aria-label="Underline">
|
|
1041
|
+
<UiIcon name="underline" :size="16" />
|
|
1042
|
+
</UiToggleGroupItem>
|
|
1043
|
+
</UiToggleGroup>
|
|
1044
|
+
</template>`;
|
|
1045
|
+
|
|
499
1046
|
/**
|
|
500
1047
|
* A single item disabled while the rest stay interactive. Arrow-key navigation
|
|
501
1048
|
* steps over the disabled item rather than stopping on something that cannot be
|
|
@@ -510,7 +1057,14 @@ export const IndividualDisabled: Story = {
|
|
|
510
1057
|
initialValue: ['bold'],
|
|
511
1058
|
disabledValue: 'italic',
|
|
512
1059
|
}),
|
|
513
|
-
parameters: {
|
|
1060
|
+
parameters: {
|
|
1061
|
+
controls: { disable: true },
|
|
1062
|
+
docs: {
|
|
1063
|
+
source: {
|
|
1064
|
+
code: individualDisabledTemplateSource,
|
|
1065
|
+
},
|
|
1066
|
+
},
|
|
1067
|
+
},
|
|
514
1068
|
play: async ({ canvasElement, step }) => {
|
|
515
1069
|
// Scenario (Toggle group): one unavailable item among enabled ones. The
|
|
516
1070
|
// arrow key moves focus only, so the snapshot stays stable.
|
|
@@ -541,17 +1095,79 @@ export const IndividualDisabled: Story = {
|
|
|
541
1095
|
},
|
|
542
1096
|
};
|
|
543
1097
|
|
|
1098
|
+
const allStatesTemplateSource = `<script setup lang="ts">
|
|
1099
|
+
import { ref } from 'vue'
|
|
1100
|
+
import { UiToggleGroup, UiToggleGroupItem, UiIcon } from '@aleph-alpha/ui-library'
|
|
1101
|
+
|
|
1102
|
+
const formatting = ref(['bold'])
|
|
1103
|
+
const alignment = ref('center')
|
|
1104
|
+
</script>
|
|
1105
|
+
|
|
1106
|
+
<template>
|
|
1107
|
+
<div class="flex flex-col gap-8">
|
|
1108
|
+
<!-- Variants and the selected fill -->
|
|
1109
|
+
<UiToggleGroup v-model="formatting" type="multiple" aria-label="Text formatting, default variant">
|
|
1110
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1111
|
+
<UiIcon name="bold" :size="16" />
|
|
1112
|
+
</UiToggleGroupItem>
|
|
1113
|
+
<UiToggleGroupItem value="italic" aria-label="Italic">
|
|
1114
|
+
<UiIcon name="italic" :size="16" />
|
|
1115
|
+
</UiToggleGroupItem>
|
|
1116
|
+
</UiToggleGroup>
|
|
1117
|
+
|
|
1118
|
+
<UiToggleGroup v-model="formatting" type="multiple" variant="ghost" aria-label="Text formatting, ghost variant">
|
|
1119
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1120
|
+
<UiIcon name="bold" :size="16" />
|
|
1121
|
+
</UiToggleGroupItem>
|
|
1122
|
+
</UiToggleGroup>
|
|
1123
|
+
|
|
1124
|
+
<UiToggleGroup v-model="formatting" type="multiple" variant="outline" aria-label="Text formatting, outline variant">
|
|
1125
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1126
|
+
<UiIcon name="bold" :size="16" />
|
|
1127
|
+
</UiToggleGroupItem>
|
|
1128
|
+
</UiToggleGroup>
|
|
1129
|
+
|
|
1130
|
+
<UiToggleGroup v-model="formatting" type="multiple" soft aria-label="Text formatting, soft fill">
|
|
1131
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1132
|
+
<UiIcon name="bold" :size="16" />
|
|
1133
|
+
</UiToggleGroupItem>
|
|
1134
|
+
</UiToggleGroup>
|
|
1135
|
+
|
|
1136
|
+
<!-- Sizes: sm, default, lg -->
|
|
1137
|
+
<UiToggleGroup v-model="alignment" type="single" variant="outline" size="sm" aria-label="Text alignment, small">
|
|
1138
|
+
<UiToggleGroupItem value="center" aria-label="Align center">
|
|
1139
|
+
<UiIcon name="align-center" :size="16" />
|
|
1140
|
+
</UiToggleGroupItem>
|
|
1141
|
+
</UiToggleGroup>
|
|
1142
|
+
|
|
1143
|
+
<!-- Disabled, whole group and per item -->
|
|
1144
|
+
<UiToggleGroup v-model="formatting" type="multiple" variant="outline" disabled aria-label="Text formatting, disabled">
|
|
1145
|
+
<UiToggleGroupItem value="bold" aria-label="Bold">
|
|
1146
|
+
<UiIcon name="bold" :size="16" />
|
|
1147
|
+
</UiToggleGroupItem>
|
|
1148
|
+
</UiToggleGroup>
|
|
1149
|
+
</div>
|
|
1150
|
+
</template>`;
|
|
1151
|
+
|
|
544
1152
|
/**
|
|
545
1153
|
* A comprehensive showcase of all toggle group states and variations in a
|
|
546
|
-
* single view: both selection modes, the style variants,
|
|
547
|
-
* text, and the disabled states.
|
|
1154
|
+
* single view: both selection modes, the style variants, both selected fills,
|
|
1155
|
+
* every size, items with text, and the disabled states.
|
|
548
1156
|
*/
|
|
549
1157
|
export const AllStates: Story = {
|
|
550
|
-
parameters: {
|
|
1158
|
+
parameters: {
|
|
1159
|
+
controls: { disable: true },
|
|
1160
|
+
docs: {
|
|
1161
|
+
source: {
|
|
1162
|
+
code: allStatesTemplateSource,
|
|
1163
|
+
},
|
|
1164
|
+
},
|
|
1165
|
+
},
|
|
551
1166
|
render: () => ({
|
|
552
1167
|
components: { UiToggleGroup, UiToggleGroupItem, UiIcon },
|
|
553
1168
|
setup() {
|
|
554
1169
|
const multipleDefault = ref<string[]>(['bold']);
|
|
1170
|
+
const multipleGhost = ref<string[]>(['bold']);
|
|
555
1171
|
const multipleOutline = ref<string[]>(['italic']);
|
|
556
1172
|
const multipleSoft = ref<string[]>(['underline']);
|
|
557
1173
|
const singleValue = ref<string>('center');
|
|
@@ -564,6 +1180,7 @@ export const AllStates: Story = {
|
|
|
564
1180
|
const textValue = ref<string>('left');
|
|
565
1181
|
return {
|
|
566
1182
|
multipleDefault,
|
|
1183
|
+
multipleGhost,
|
|
567
1184
|
multipleOutline,
|
|
568
1185
|
multipleSoft,
|
|
569
1186
|
singleValue,
|
|
@@ -581,7 +1198,7 @@ export const AllStates: Story = {
|
|
|
581
1198
|
template: `
|
|
582
1199
|
<div class="flex flex-col gap-8 w-full max-w-2xl">
|
|
583
1200
|
<section>
|
|
584
|
-
<h3 class="heading-s mb-4">Variants</h3>
|
|
1201
|
+
<h3 class="heading-s mb-4">Variants & selected fill</h3>
|
|
585
1202
|
<div class="flex flex-col gap-4">
|
|
586
1203
|
<div class="flex items-center gap-4">
|
|
587
1204
|
<span class="body-14-regular text-content-on-surface-muted w-24">Default:</span>
|
|
@@ -591,6 +1208,14 @@ export const AllStates: Story = {
|
|
|
591
1208
|
</UiToggleGroupItem>
|
|
592
1209
|
</UiToggleGroup>
|
|
593
1210
|
</div>
|
|
1211
|
+
<div class="flex items-center gap-4">
|
|
1212
|
+
<span class="body-14-regular text-content-on-surface-muted w-24">Ghost:</span>
|
|
1213
|
+
<UiToggleGroup v-model="multipleGhost" type="multiple" variant="ghost" aria-label="Text formatting, ghost variant">
|
|
1214
|
+
<UiToggleGroupItem v-for="item in formattingItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
1215
|
+
<UiIcon :name="item.icon" :size="16" />
|
|
1216
|
+
</UiToggleGroupItem>
|
|
1217
|
+
</UiToggleGroup>
|
|
1218
|
+
</div>
|
|
594
1219
|
<div class="flex items-center gap-4">
|
|
595
1220
|
<span class="body-14-regular text-content-on-surface-muted w-24">Outline:</span>
|
|
596
1221
|
<UiToggleGroup v-model="multipleOutline" type="multiple" variant="outline" aria-label="Text formatting, outline variant">
|
|
@@ -601,7 +1226,7 @@ export const AllStates: Story = {
|
|
|
601
1226
|
</div>
|
|
602
1227
|
<div class="flex items-center gap-4">
|
|
603
1228
|
<span class="body-14-regular text-content-on-surface-muted w-24">Soft:</span>
|
|
604
|
-
<UiToggleGroup v-model="multipleSoft" type="multiple"
|
|
1229
|
+
<UiToggleGroup v-model="multipleSoft" type="multiple" soft aria-label="Text formatting, soft fill">
|
|
605
1230
|
<UiToggleGroupItem v-for="item in formattingItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
606
1231
|
<UiIcon :name="item.icon" :size="16" />
|
|
607
1232
|
</UiToggleGroupItem>
|
|
@@ -746,8 +1371,16 @@ export const Accessibility: Story = {
|
|
|
746
1371
|
components: { UiToggleGroup, UiToggleGroupItem, UiIcon },
|
|
747
1372
|
setup() {
|
|
748
1373
|
const defaultValue = ref<string>('center');
|
|
1374
|
+
const defaultSoftValue = ref<string>('center');
|
|
749
1375
|
const accessibleValue = ref<string>('center');
|
|
750
|
-
|
|
1376
|
+
const accessibleSoftValue = ref<string>('center');
|
|
1377
|
+
return {
|
|
1378
|
+
defaultValue,
|
|
1379
|
+
defaultSoftValue,
|
|
1380
|
+
accessibleValue,
|
|
1381
|
+
accessibleSoftValue,
|
|
1382
|
+
alignmentItems,
|
|
1383
|
+
};
|
|
751
1384
|
},
|
|
752
1385
|
template: `
|
|
753
1386
|
<section class="flex flex-col gap-6 p-4">
|
|
@@ -815,11 +1448,25 @@ export const Accessibility: Story = {
|
|
|
815
1448
|
Do not rely on the fill alone
|
|
816
1449
|
</h3>
|
|
817
1450
|
<p class="body-16-regular text-content-on-surface-primary">
|
|
818
|
-
|
|
819
|
-
|
|
1451
|
+
Selected items are filled with a muted surface, and
|
|
1452
|
+
<code>soft</code> makes that fill quieter still. Neither is the
|
|
1453
|
+
real signal: the same information reaches everyone through
|
|
820
1454
|
<code>aria-pressed</code> (WCAG 1.4.1 Use of Color). In a
|
|
821
|
-
single-choice group
|
|
822
|
-
option is active.
|
|
1455
|
+
single-choice group that is what tells assistive technology which
|
|
1456
|
+
option is active, so never express selection by colour alone.
|
|
1457
|
+
</p>
|
|
1458
|
+
</div>
|
|
1459
|
+
|
|
1460
|
+
<div class="flex flex-col gap-2">
|
|
1461
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1462
|
+
A group is not a radio group
|
|
1463
|
+
</h3>
|
|
1464
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
1465
|
+
Even with <code>type="single"</code> the items stay toggle buttons
|
|
1466
|
+
with <code>aria-pressed</code>, not radios with
|
|
1467
|
+
<code>aria-checked</code>. If the choice is a form value that must
|
|
1468
|
+
be submitted, use <code>UiRadioGroup</code> instead; use this
|
|
1469
|
+
group for view and formatting controls that act immediately.
|
|
823
1470
|
</p>
|
|
824
1471
|
</div>
|
|
825
1472
|
|
|
@@ -828,9 +1475,23 @@ export const Accessibility: Story = {
|
|
|
828
1475
|
Every size is large enough to tap
|
|
829
1476
|
</h3>
|
|
830
1477
|
<p class="body-16-regular text-content-on-surface-primary">
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1478
|
+
The sizes differ in padding rather than in a fixed box, and every
|
|
1479
|
+
one of them clears the 24×24px floor in WCAG 2.5.8 Target Size
|
|
1480
|
+
(Minimum) — including <code>sm</code>, and including icon-only
|
|
1481
|
+
items, which carry the target without help from a label.
|
|
1482
|
+
</p>
|
|
1483
|
+
</div>
|
|
1484
|
+
|
|
1485
|
+
<div class="flex flex-col gap-2">
|
|
1486
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
1487
|
+
Selected items keep their contrast when focused
|
|
1488
|
+
</h3>
|
|
1489
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
1490
|
+
Hover, focus and press are drawn as an overlay on top of the
|
|
1491
|
+
item's own fill, so a selected item that is also focused stays
|
|
1492
|
+
readable instead of washing out. The focus ring itself only
|
|
1493
|
+
appears for keyboard focus, which is why clicking an item does not
|
|
1494
|
+
leave it looking selected (WCAG 2.4.7 Focus Visible).
|
|
834
1495
|
</p>
|
|
835
1496
|
</div>
|
|
836
1497
|
|
|
@@ -851,12 +1512,17 @@ export const Accessibility: Story = {
|
|
|
851
1512
|
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
852
1513
|
Default
|
|
853
1514
|
</h3>
|
|
854
|
-
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
1515
|
+
<div class="flex min-h-20 flex-col items-center justify-center gap-4 border border-border-surface-default p-6">
|
|
855
1516
|
<UiToggleGroup v-model="defaultValue" type="single" variant="outline" aria-label="Text alignment">
|
|
856
1517
|
<UiToggleGroupItem v-for="item in alignmentItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
857
1518
|
<UiIcon :name="item.icon" :size="16" />
|
|
858
1519
|
</UiToggleGroupItem>
|
|
859
1520
|
</UiToggleGroup>
|
|
1521
|
+
<UiToggleGroup v-model="defaultSoftValue" type="single" variant="outline" soft aria-label="Text alignment, soft fill">
|
|
1522
|
+
<UiToggleGroupItem v-for="item in alignmentItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
1523
|
+
<UiIcon :name="item.icon" :size="16" />
|
|
1524
|
+
</UiToggleGroupItem>
|
|
1525
|
+
</UiToggleGroup>
|
|
860
1526
|
</div>
|
|
861
1527
|
</div>
|
|
862
1528
|
|
|
@@ -864,12 +1530,17 @@ export const Accessibility: Story = {
|
|
|
864
1530
|
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
865
1531
|
Accessible
|
|
866
1532
|
</h3>
|
|
867
|
-
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
1533
|
+
<div class="flex min-h-20 flex-col items-center justify-center gap-4 border border-border-surface-default p-6">
|
|
868
1534
|
<UiToggleGroup v-model="accessibleValue" type="single" variant="outline" aria-label="Text alignment">
|
|
869
1535
|
<UiToggleGroupItem v-for="item in alignmentItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
870
1536
|
<UiIcon :name="item.icon" :size="16" />
|
|
871
1537
|
</UiToggleGroupItem>
|
|
872
1538
|
</UiToggleGroup>
|
|
1539
|
+
<UiToggleGroup v-model="accessibleSoftValue" type="single" variant="outline" soft aria-label="Text alignment, soft fill">
|
|
1540
|
+
<UiToggleGroupItem v-for="item in alignmentItems" :key="item.value" :value="item.value" :aria-label="item.label">
|
|
1541
|
+
<UiIcon :name="item.icon" :size="16" />
|
|
1542
|
+
</UiToggleGroupItem>
|
|
1543
|
+
</UiToggleGroup>
|
|
873
1544
|
</div>
|
|
874
1545
|
</div>
|
|
875
1546
|
</div>
|
|
@@ -887,14 +1558,16 @@ export const Accessibility: Story = {
|
|
|
887
1558
|
// Shared render for the test scenarios: a multiple-choice formatting group
|
|
888
1559
|
// with an icon-only item, an item with text and a disabled item, followed by a
|
|
889
1560
|
// single-choice alignment group. Two groups in a row is what makes the
|
|
890
|
-
// tab-stop and arrow-key contract observable.
|
|
1561
|
+
// tab-stop and arrow-key contract observable. A third, softly filled group
|
|
1562
|
+
// follows so every scenario also covers the quieter selected fill.
|
|
891
1563
|
function renderTestGroups() {
|
|
892
1564
|
return {
|
|
893
1565
|
components: { UiToggleGroup, UiToggleGroupItem, UiIcon },
|
|
894
1566
|
setup() {
|
|
895
1567
|
const formatting = ref<string[]>([]);
|
|
896
1568
|
const alignment = ref<string>('center');
|
|
897
|
-
|
|
1569
|
+
const density = ref<string>('comfortable');
|
|
1570
|
+
return { formatting, alignment, density, alignmentItems, onUpdate };
|
|
898
1571
|
},
|
|
899
1572
|
template: `
|
|
900
1573
|
<div class="flex flex-col items-start gap-4">
|
|
@@ -935,6 +1608,21 @@ function renderTestGroups() {
|
|
|
935
1608
|
<UiIcon :name="item.icon" :size="16" />
|
|
936
1609
|
</UiToggleGroupItem>
|
|
937
1610
|
</UiToggleGroup>
|
|
1611
|
+
|
|
1612
|
+
<UiToggleGroup
|
|
1613
|
+
v-model="density"
|
|
1614
|
+
type="single"
|
|
1615
|
+
variant="outline"
|
|
1616
|
+
soft
|
|
1617
|
+
aria-label="Row density"
|
|
1618
|
+
>
|
|
1619
|
+
<UiToggleGroupItem value="comfortable" aria-label="Comfortable rows">
|
|
1620
|
+
<UiIcon name="list" :size="16" />
|
|
1621
|
+
</UiToggleGroupItem>
|
|
1622
|
+
<UiToggleGroupItem value="compact" aria-label="Compact rows">
|
|
1623
|
+
<UiIcon name="layout-grid" :size="16" />
|
|
1624
|
+
</UiToggleGroupItem>
|
|
1625
|
+
</UiToggleGroup>
|
|
938
1626
|
</div>
|
|
939
1627
|
`,
|
|
940
1628
|
};
|
|
@@ -1196,6 +1884,53 @@ export const ScreenReader: Story = {
|
|
|
1196
1884
|
'screen-reader: an unavailable item announces its disabled state (WCAG 4.1.2)',
|
|
1197
1885
|
async () => {
|
|
1198
1886
|
await expect(strikethrough).toBeDisabled();
|
|
1887
|
+
// Unavailable is not the same as unselected, so the state still has to
|
|
1888
|
+
// be announced.
|
|
1889
|
+
await expect(strikethrough).toHaveAttribute('aria-pressed', 'false');
|
|
1890
|
+
},
|
|
1891
|
+
);
|
|
1892
|
+
|
|
1893
|
+
await step(
|
|
1894
|
+
'screen-reader: a single-choice group is still toggle buttons, not radios',
|
|
1895
|
+
async () => {
|
|
1896
|
+
// reka exposes the choice through aria-pressed. Announcing it as a
|
|
1897
|
+
// radio would promise form semantics the group does not have.
|
|
1898
|
+
const alignment = within(
|
|
1899
|
+
canvas.getByRole('group', { name: 'Text alignment' }),
|
|
1900
|
+
);
|
|
1901
|
+
await expect(alignment.queryAllByRole('radio')).toHaveLength(0);
|
|
1902
|
+
for (const item of alignment.getAllByRole('button')) {
|
|
1903
|
+
await expect(item).toHaveAttribute('aria-pressed');
|
|
1904
|
+
await expect(item).not.toHaveAttribute('aria-checked');
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
);
|
|
1908
|
+
|
|
1909
|
+
await step(
|
|
1910
|
+
'screen-reader: every item is announced inside its own group (WCAG 1.3.1)',
|
|
1911
|
+
async () => {
|
|
1912
|
+
// An item that escaped its group would still be reachable, but it would
|
|
1913
|
+
// lose the context the group name provides.
|
|
1914
|
+
for (const [name, count] of [
|
|
1915
|
+
['Text formatting', 4],
|
|
1916
|
+
['Text alignment', 3],
|
|
1917
|
+
['Row density', 2],
|
|
1918
|
+
] as const) {
|
|
1919
|
+
const group = within(canvas.getByRole('group', { name }));
|
|
1920
|
+
await expect(group.getAllByRole('button')).toHaveLength(count);
|
|
1921
|
+
}
|
|
1922
|
+
},
|
|
1923
|
+
);
|
|
1924
|
+
|
|
1925
|
+
await step(
|
|
1926
|
+
'screen-reader: the soft fill is announced exactly like the muted one (WCAG 1.4.1)',
|
|
1927
|
+
async () => {
|
|
1928
|
+
const comfortable = canvas.getByRole('button', {
|
|
1929
|
+
name: 'Comfortable rows',
|
|
1930
|
+
});
|
|
1931
|
+
const compact = canvas.getByRole('button', { name: 'Compact rows' });
|
|
1932
|
+
await expect(comfortable).toHaveAttribute('aria-pressed', 'true');
|
|
1933
|
+
await expect(compact).toHaveAttribute('aria-pressed', 'false');
|
|
1199
1934
|
},
|
|
1200
1935
|
);
|
|
1201
1936
|
|