@aleph-alpha/ui-library 5.6.0 → 5.7.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 +5 -0
- package/dist/system/components/UiField/types.d.ts +2 -1
- package/dist/system/lib.js +5 -4
- package/package.json +5 -5
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +1 -1
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
- package/src/components/UiField/UiField.stories.ts +1 -1
- package/src/components/UiField/types.ts +2 -1
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
- package/src/components/UiSelect/UiSelect.stories.ts +1 -1
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +3 -2
- package/src/components/core/field/FieldTitle.vue +1 -1
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
- package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
|
@@ -1052,7 +1052,7 @@ export const OpenSelectClose: Story = {
|
|
|
1052
1052
|
// Disabled items render with pointer-events: none, so bypass the
|
|
1053
1053
|
// check and assert the click is still a no-op.
|
|
1054
1054
|
await userEvent.click(disabledOption, { pointerEventsCheck: 0 });
|
|
1055
|
-
await
|
|
1055
|
+
await findOpenListbox(body);
|
|
1056
1056
|
await expect(trigger).toHaveTextContent('Select a food');
|
|
1057
1057
|
},
|
|
1058
1058
|
);
|
|
@@ -12,7 +12,7 @@ const props = defineProps<{
|
|
|
12
12
|
data-slot="field-description"
|
|
13
13
|
:class="
|
|
14
14
|
cn(
|
|
15
|
-
'text-content-on-surface-muted
|
|
15
|
+
'text-content-on-surface-muted label-14-regular group-has-[[data-orientation=horizontal]]/field:text-balance',
|
|
16
16
|
'last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5',
|
|
17
17
|
'[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4',
|
|
18
18
|
props.class,
|
|
@@ -17,8 +17,9 @@ const props = defineProps<{
|
|
|
17
17
|
:class="
|
|
18
18
|
cn(
|
|
19
19
|
'group/field-label peer/field-label flex w-fit items-center gap-2 leading-snug text-content-on-surface-muted body-14-medium group-data-[disabled=true]/field:opacity-50',
|
|
20
|
-
'has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-
|
|
21
|
-
'has-data-[state=checked]:bg-
|
|
20
|
+
'has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border has-[>[data-slot=field]]:border-border-input-default',
|
|
21
|
+
'has-data-[state=checked]:bg-background-surface-selected has-data-[state=checked]:border-transparent',
|
|
22
|
+
'[&>[data-slot=field]]:p-4',
|
|
22
23
|
props.class,
|
|
23
24
|
)
|
|
24
25
|
"
|
|
@@ -12,7 +12,7 @@ const props = defineProps<{
|
|
|
12
12
|
data-slot="field-label"
|
|
13
13
|
:class="
|
|
14
14
|
cn(
|
|
15
|
-
'
|
|
15
|
+
'label-14-regular text-content-on-surface-primary flex w-fit items-center gap-2 leading-snug group-data-[disabled=true]/field:opacity-50',
|
|
16
16
|
props.class,
|
|
17
17
|
)
|
|
18
18
|
"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/vue';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { describe, expect, test } from 'vitest';
|
|
4
|
-
import UiCheckbox from '../UiCheckbox.vue';
|
|
5
|
-
|
|
6
|
-
describe('UiCheckbox', () => {
|
|
7
|
-
// v-model wiring (the wrapper's own integration work) is unit-tested here.
|
|
8
|
-
test('emits update:modelValue on click', async () => {
|
|
9
|
-
const { getByRole, emitted } = render(UiCheckbox);
|
|
10
|
-
|
|
11
|
-
await userEvent.click(getByRole('checkbox'));
|
|
12
|
-
expect(emitted('update:modelValue')?.[0][0]).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/vue';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { describe, expect, test } from 'vitest';
|
|
4
|
-
import { UiRadioGroup, UiRadioGroupItem } from '../index';
|
|
5
|
-
import { h } from 'vue';
|
|
6
|
-
|
|
7
|
-
// Values for the radio buttons
|
|
8
|
-
const firstItemValue = 'first';
|
|
9
|
-
const secondItemValue = 'second';
|
|
10
|
-
const thirdItemValue = 'third';
|
|
11
|
-
|
|
12
|
-
// Labels for accessible names (via label element with for attribute)
|
|
13
|
-
const firstItemLabel = 'First Option';
|
|
14
|
-
const secondItemLabel = 'Second Option';
|
|
15
|
-
const thirdItemLabel = 'Third Option';
|
|
16
|
-
|
|
17
|
-
const twoItemsContent = () => [
|
|
18
|
-
h('div', [
|
|
19
|
-
h(UiRadioGroupItem, {
|
|
20
|
-
id: 'rg-1',
|
|
21
|
-
value: firstItemValue,
|
|
22
|
-
}),
|
|
23
|
-
h('label', { for: 'rg-1' }, firstItemLabel),
|
|
24
|
-
]),
|
|
25
|
-
h('div', [
|
|
26
|
-
h(UiRadioGroupItem, {
|
|
27
|
-
id: 'rg-2',
|
|
28
|
-
value: secondItemValue,
|
|
29
|
-
}),
|
|
30
|
-
h('label', { for: 'rg-2' }, secondItemLabel),
|
|
31
|
-
]),
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
const threeItemsContent = () => [
|
|
35
|
-
h('div', [
|
|
36
|
-
h(UiRadioGroupItem, {
|
|
37
|
-
id: 'rg-1',
|
|
38
|
-
value: firstItemValue,
|
|
39
|
-
}),
|
|
40
|
-
h('label', { for: 'rg-1' }, firstItemLabel),
|
|
41
|
-
]),
|
|
42
|
-
h('div', [
|
|
43
|
-
h(UiRadioGroupItem, {
|
|
44
|
-
id: 'rg-2',
|
|
45
|
-
value: secondItemValue,
|
|
46
|
-
}),
|
|
47
|
-
h('label', { for: 'rg-2' }, secondItemLabel),
|
|
48
|
-
]),
|
|
49
|
-
h('div', [
|
|
50
|
-
h(UiRadioGroupItem, {
|
|
51
|
-
id: 'rg-3',
|
|
52
|
-
value: thirdItemValue,
|
|
53
|
-
}),
|
|
54
|
-
h('label', { for: 'rg-3' }, thirdItemLabel),
|
|
55
|
-
]),
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
const contentWithDisabledItem = () => [
|
|
59
|
-
h('div', [
|
|
60
|
-
h(UiRadioGroupItem, {
|
|
61
|
-
id: 'rg-1',
|
|
62
|
-
value: firstItemValue,
|
|
63
|
-
}),
|
|
64
|
-
h('label', { for: 'rg-1' }, firstItemLabel),
|
|
65
|
-
]),
|
|
66
|
-
h('div', [
|
|
67
|
-
h(UiRadioGroupItem, {
|
|
68
|
-
id: 'rg-2',
|
|
69
|
-
value: secondItemValue,
|
|
70
|
-
disabled: true,
|
|
71
|
-
}),
|
|
72
|
-
h('label', { for: 'rg-2' }, secondItemLabel),
|
|
73
|
-
]),
|
|
74
|
-
h('div', [
|
|
75
|
-
h(UiRadioGroupItem, {
|
|
76
|
-
id: 'rg-3',
|
|
77
|
-
value: thirdItemValue,
|
|
78
|
-
}),
|
|
79
|
-
h('label', { for: 'rg-3' }, thirdItemLabel),
|
|
80
|
-
]),
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
describe('UiRadioGroup', () => {
|
|
84
|
-
describe('selection behavior', () => {
|
|
85
|
-
test('renders with initial selected value', () => {
|
|
86
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
87
|
-
props: {
|
|
88
|
-
name: 'radio-group',
|
|
89
|
-
modelValue: secondItemValue,
|
|
90
|
-
},
|
|
91
|
-
slots: {
|
|
92
|
-
default: twoItemsContent(),
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(getByLabelText(secondItemLabel)).toBeChecked();
|
|
97
|
-
expect(getByLabelText(firstItemLabel)).not.toBeChecked();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('emits update:modelValue when selection changes', async () => {
|
|
101
|
-
const { getByLabelText, emitted } = render(UiRadioGroup, {
|
|
102
|
-
props: {
|
|
103
|
-
name: 'radio-group',
|
|
104
|
-
modelValue: firstItemValue,
|
|
105
|
-
},
|
|
106
|
-
slots: {
|
|
107
|
-
default: twoItemsContent(),
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await userEvent.click(getByLabelText(secondItemLabel));
|
|
112
|
-
|
|
113
|
-
expect(emitted('update:modelValue')).toHaveLength(1);
|
|
114
|
-
expect(emitted('update:modelValue')[0][0]).toBe(secondItemValue);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('allows only one item to be selected at a time', async () => {
|
|
118
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
119
|
-
props: {
|
|
120
|
-
name: 'radio-group',
|
|
121
|
-
modelValue: firstItemValue,
|
|
122
|
-
},
|
|
123
|
-
slots: {
|
|
124
|
-
default: threeItemsContent(),
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Initially first is selected
|
|
129
|
-
expect(getByLabelText(firstItemLabel)).toBeChecked();
|
|
130
|
-
|
|
131
|
-
// Click second
|
|
132
|
-
await userEvent.click(getByLabelText(secondItemLabel));
|
|
133
|
-
expect(getByLabelText(secondItemLabel)).toBeChecked();
|
|
134
|
-
expect(getByLabelText(firstItemLabel)).not.toBeChecked();
|
|
135
|
-
|
|
136
|
-
// Click third
|
|
137
|
-
await userEvent.click(getByLabelText(thirdItemLabel));
|
|
138
|
-
expect(getByLabelText(thirdItemLabel)).toBeChecked();
|
|
139
|
-
expect(getByLabelText(secondItemLabel)).not.toBeChecked();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('keyboard navigation', () => {
|
|
144
|
-
test('arrow down moves focus to next item', async () => {
|
|
145
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
146
|
-
props: {
|
|
147
|
-
name: 'radio-group',
|
|
148
|
-
modelValue: firstItemValue,
|
|
149
|
-
},
|
|
150
|
-
slots: {
|
|
151
|
-
default: threeItemsContent(),
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const firstRadio = getByLabelText(firstItemLabel);
|
|
156
|
-
firstRadio.focus();
|
|
157
|
-
|
|
158
|
-
await userEvent.keyboard('{ArrowDown}');
|
|
159
|
-
|
|
160
|
-
expect(getByLabelText(secondItemLabel)).toHaveFocus();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('arrow up moves focus to previous item', async () => {
|
|
164
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
165
|
-
props: {
|
|
166
|
-
name: 'radio-group',
|
|
167
|
-
modelValue: secondItemValue,
|
|
168
|
-
},
|
|
169
|
-
slots: {
|
|
170
|
-
default: threeItemsContent(),
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const secondRadio = getByLabelText(secondItemLabel);
|
|
175
|
-
secondRadio.focus();
|
|
176
|
-
|
|
177
|
-
await userEvent.keyboard('{ArrowUp}');
|
|
178
|
-
|
|
179
|
-
expect(getByLabelText(firstItemLabel)).toHaveFocus();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test('loops from last to first when loop is enabled (default)', async () => {
|
|
183
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
184
|
-
props: {
|
|
185
|
-
name: 'radio-group',
|
|
186
|
-
modelValue: thirdItemValue,
|
|
187
|
-
},
|
|
188
|
-
slots: {
|
|
189
|
-
default: threeItemsContent(),
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
const thirdRadio = getByLabelText(thirdItemLabel);
|
|
194
|
-
thirdRadio.focus();
|
|
195
|
-
|
|
196
|
-
await userEvent.keyboard('{ArrowDown}');
|
|
197
|
-
|
|
198
|
-
expect(getByLabelText(firstItemLabel)).toHaveFocus();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('does not loop when loop is disabled', async () => {
|
|
202
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
203
|
-
props: {
|
|
204
|
-
name: 'radio-group',
|
|
205
|
-
modelValue: thirdItemValue,
|
|
206
|
-
loop: false,
|
|
207
|
-
},
|
|
208
|
-
slots: {
|
|
209
|
-
default: threeItemsContent(),
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const thirdRadio = getByLabelText(thirdItemLabel);
|
|
214
|
-
thirdRadio.focus();
|
|
215
|
-
|
|
216
|
-
await userEvent.keyboard('{ArrowDown}');
|
|
217
|
-
|
|
218
|
-
// Should stay on third item
|
|
219
|
-
expect(getByLabelText(thirdItemLabel)).toHaveFocus();
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('skips disabled items during navigation', async () => {
|
|
223
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
224
|
-
props: {
|
|
225
|
-
name: 'radio-group',
|
|
226
|
-
modelValue: firstItemValue,
|
|
227
|
-
},
|
|
228
|
-
slots: {
|
|
229
|
-
default: contentWithDisabledItem(),
|
|
230
|
-
},
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const firstRadio = getByLabelText(firstItemLabel);
|
|
234
|
-
firstRadio.focus();
|
|
235
|
-
|
|
236
|
-
await userEvent.keyboard('{ArrowDown}');
|
|
237
|
-
|
|
238
|
-
// Should skip disabled second item and go to third
|
|
239
|
-
expect(getByLabelText(thirdItemLabel)).toHaveFocus();
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe('disabled state', () => {
|
|
244
|
-
test('disabled group prevents selection changes', async () => {
|
|
245
|
-
const { getByLabelText, emitted } = render(UiRadioGroup, {
|
|
246
|
-
props: {
|
|
247
|
-
name: 'radio-group',
|
|
248
|
-
modelValue: firstItemValue,
|
|
249
|
-
disabled: true,
|
|
250
|
-
},
|
|
251
|
-
slots: {
|
|
252
|
-
default: twoItemsContent(),
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
await userEvent.click(getByLabelText(secondItemLabel));
|
|
257
|
-
|
|
258
|
-
expect(emitted('update:modelValue')).toBeUndefined();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test('disabled item cannot be selected', async () => {
|
|
262
|
-
const { getByLabelText, emitted } = render(UiRadioGroup, {
|
|
263
|
-
props: {
|
|
264
|
-
name: 'radio-group',
|
|
265
|
-
modelValue: firstItemValue,
|
|
266
|
-
},
|
|
267
|
-
slots: {
|
|
268
|
-
default: contentWithDisabledItem(),
|
|
269
|
-
},
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
await userEvent.click(getByLabelText(secondItemLabel));
|
|
273
|
-
|
|
274
|
-
expect(emitted('update:modelValue')).toBeUndefined();
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe('accessibility', () => {
|
|
279
|
-
test('has radiogroup role', () => {
|
|
280
|
-
const { getByRole } = render(UiRadioGroup, {
|
|
281
|
-
props: {
|
|
282
|
-
name: 'radio-group',
|
|
283
|
-
},
|
|
284
|
-
slots: {
|
|
285
|
-
default: twoItemsContent(),
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(getByRole('radiogroup')).toBeInTheDocument();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
test('items have radio role', () => {
|
|
293
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
294
|
-
props: {
|
|
295
|
-
name: 'radio-group',
|
|
296
|
-
},
|
|
297
|
-
slots: {
|
|
298
|
-
default: twoItemsContent(),
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// Assert role via the labeled interactive elements
|
|
303
|
-
expect(getByLabelText(firstItemLabel).getAttribute('role')).toBe('radio');
|
|
304
|
-
expect(getByLabelText(secondItemLabel).getAttribute('role')).toBe(
|
|
305
|
-
'radio',
|
|
306
|
-
);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
test('selected item has aria-checked true', () => {
|
|
310
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
311
|
-
props: {
|
|
312
|
-
name: 'radio-group',
|
|
313
|
-
modelValue: firstItemValue,
|
|
314
|
-
},
|
|
315
|
-
slots: {
|
|
316
|
-
default: twoItemsContent(),
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
expect(getByLabelText(firstItemLabel)).toHaveAttribute(
|
|
321
|
-
'aria-checked',
|
|
322
|
-
'true',
|
|
323
|
-
);
|
|
324
|
-
expect(getByLabelText(secondItemLabel)).toHaveAttribute(
|
|
325
|
-
'aria-checked',
|
|
326
|
-
'false',
|
|
327
|
-
);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
test('disabled item has disabled attribute', () => {
|
|
331
|
-
const { getByLabelText } = render(UiRadioGroup, {
|
|
332
|
-
props: {
|
|
333
|
-
name: 'radio-group',
|
|
334
|
-
},
|
|
335
|
-
slots: {
|
|
336
|
-
default: contentWithDisabledItem(),
|
|
337
|
-
},
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
expect(getByLabelText(secondItemLabel)).toBeDisabled();
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
describe('orientation', () => {
|
|
345
|
-
test('uses vertical orientation by default', () => {
|
|
346
|
-
const { getByRole } = render(UiRadioGroup, {
|
|
347
|
-
props: {
|
|
348
|
-
name: 'radio-group',
|
|
349
|
-
},
|
|
350
|
-
slots: {
|
|
351
|
-
default: twoItemsContent(),
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
const radioGroup = getByRole('radiogroup');
|
|
356
|
-
expect(radioGroup).toHaveAttribute('data-orientation', 'vertical');
|
|
357
|
-
expect(radioGroup).toHaveClass('grid');
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
test('horizontal orientation sets horizontal layout', () => {
|
|
361
|
-
const { getByRole } = render(UiRadioGroup, {
|
|
362
|
-
props: {
|
|
363
|
-
name: 'radio-group',
|
|
364
|
-
orientation: 'horizontal',
|
|
365
|
-
},
|
|
366
|
-
slots: {
|
|
367
|
-
default: threeItemsContent(),
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
const radioGroup = getByRole('radiogroup');
|
|
372
|
-
expect(radioGroup).toHaveAttribute('data-orientation', 'horizontal');
|
|
373
|
-
expect(radioGroup).toHaveClass('flex');
|
|
374
|
-
expect(radioGroup).not.toHaveClass('grid');
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
test('merges custom class with orientation classes', () => {
|
|
378
|
-
const { getByRole } = render(UiRadioGroup, {
|
|
379
|
-
props: {
|
|
380
|
-
name: 'radio-group',
|
|
381
|
-
orientation: 'horizontal',
|
|
382
|
-
class: 'mt-4 custom-class',
|
|
383
|
-
},
|
|
384
|
-
slots: {
|
|
385
|
-
default: twoItemsContent(),
|
|
386
|
-
},
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
const radioGroup = getByRole('radiogroup');
|
|
390
|
-
expect(radioGroup).toHaveClass('flex');
|
|
391
|
-
expect(radioGroup).toHaveClass('mt-4');
|
|
392
|
-
expect(radioGroup).toHaveClass('custom-class');
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
test('custom class can override default gap', () => {
|
|
396
|
-
const { getByRole } = render(UiRadioGroup, {
|
|
397
|
-
props: {
|
|
398
|
-
name: 'radio-group',
|
|
399
|
-
class: 'gap-6',
|
|
400
|
-
},
|
|
401
|
-
slots: {
|
|
402
|
-
default: twoItemsContent(),
|
|
403
|
-
},
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
const radioGroup = getByRole('radiogroup');
|
|
407
|
-
// tailwind-merge resolves conflicting gap utilities
|
|
408
|
-
expect(radioGroup).toHaveClass('gap-6');
|
|
409
|
-
expect(radioGroup).not.toHaveClass('gap-3');
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
});
|