@aleph-alpha/ui-library 5.5.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.
Files changed (41) hide show
  1. package/config.js +5 -0
  2. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  3. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  5. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  6. package/dist/system/components/UiField/types.d.ts +2 -1
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +7855 -7732
  13. package/dist/system/story-sidebar-icons.json +3 -0
  14. package/package.json +5 -5
  15. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +619 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  17. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  18. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  19. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  20. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  21. package/src/components/UiButtonGroup/index.ts +2 -0
  22. package/src/components/UiButtonGroup/types.ts +21 -0
  23. package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
  24. package/src/components/UiField/UiField.stories.ts +1 -1
  25. package/src/components/UiField/types.ts +2 -1
  26. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
  27. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  28. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  29. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  30. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  31. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  32. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  33. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  34. package/src/components/core/button-group/index.ts +25 -0
  35. package/src/components/core/field/FieldDescription.vue +1 -1
  36. package/src/components/core/field/FieldLabel.vue +3 -2
  37. package/src/components/core/field/FieldTitle.vue +1 -1
  38. package/src/components/core/select/SelectTrigger.vue +1 -1
  39. package/src/components/index.ts +1 -0
  40. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
  41. package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
@@ -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
- });