@aleph-alpha/ui-library 5.6.0 → 5.8.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/README.md +4 -0
- package/config.d.ts +5 -1
- package/config.js +23 -1
- package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
- package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
- package/dist/system/components/UiField/types.d.ts +2 -1
- package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
- package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
- package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
- package/dist/system/components/core/listbox/context.d.ts +21 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +10062 -9711
- package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
- package/dist/system/story-sidebar-icons.json +6 -0
- package/package.json +5 -5
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +1 -1
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
- package/src/components/UiBreadcrumb/index.ts +8 -0
- package/src/components/UiBreadcrumb/types.ts +28 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
- package/src/components/UiField/UiField.stories.ts +1 -1
- package/src/components/UiField/types.ts +2 -1
- package/src/components/UiListbox/UiListbox.stories.ts +1283 -30
- package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
- package/src/components/UiSelect/UiSelect.stories.ts +1 -1
- package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
- package/src/components/UiToggle/UiToggle.stories.ts +961 -130
- package/src/components/UiToggle/UiToggle.vue +8 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
- package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
- package/src/components/UiToggleGroup/types.ts +0 -5
- package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
- package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
- package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
- package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
- package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/src/components/core/breadcrumb/index.ts +7 -0
- 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/core/listbox/Listbox.vue +14 -2
- package/src/components/core/listbox/ListboxContent.vue +61 -3
- package/src/components/core/listbox/ListboxItem.vue +6 -1
- package/src/components/core/listbox/context.ts +34 -0
- package/src/components/core/toggle/Toggle.vue +15 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
- package/src/components/core/toggle-group/index.ts +5 -2
- package/src/components/index.ts +1 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
- package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
|
@@ -28,7 +28,6 @@ const props = withDefaults(
|
|
|
28
28
|
size: 'default',
|
|
29
29
|
loop: true,
|
|
30
30
|
rovingFocus: true,
|
|
31
|
-
orientation: 'horizontal',
|
|
32
31
|
},
|
|
33
32
|
);
|
|
34
33
|
|
|
@@ -36,6 +35,9 @@ const modelValue = defineModel<UiToggleGroupModelValue<T>>();
|
|
|
36
35
|
</script>
|
|
37
36
|
|
|
38
37
|
<template>
|
|
38
|
+
<!-- The group always lays out as a horizontal row, so the arrow-key axis is
|
|
39
|
+
pinned to match it rather than exposed as a prop that could disagree
|
|
40
|
+
with what is on screen. -->
|
|
39
41
|
<ShadcnToggleGroup
|
|
40
42
|
v-model="modelValue"
|
|
41
43
|
:type="props.type"
|
|
@@ -45,7 +47,7 @@ const modelValue = defineModel<UiToggleGroupModelValue<T>>();
|
|
|
45
47
|
:size="props.size"
|
|
46
48
|
:loop="props.loop"
|
|
47
49
|
:roving-focus="props.rovingFocus"
|
|
48
|
-
|
|
50
|
+
orientation="horizontal"
|
|
49
51
|
>
|
|
50
52
|
<slot />
|
|
51
53
|
</ShadcnToggleGroup>
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable vue/one-component-per-file -- each test defines its own
|
|
2
|
-
inline host component to exercise a distinct UiToggleGroup scenario. */
|
|
3
1
|
import { render } from '@testing-library/vue';
|
|
4
2
|
import userEvent from '@testing-library/user-event';
|
|
5
3
|
import { describe, expect, test } from 'vitest';
|
|
@@ -7,57 +5,47 @@ import { ref, nextTick, defineComponent } from 'vue';
|
|
|
7
5
|
import UiToggleGroup from '../UiToggleGroup.vue';
|
|
8
6
|
import UiToggleGroupItem from '../UiToggleGroupItem.vue';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Builds a host component around a group of `a`/`b`/`c` items.
|
|
10
|
+
* @param options Scenario options.
|
|
11
|
+
* @param options.type Selection mode.
|
|
12
|
+
* @param options.modelValue Ref holding the group's value.
|
|
13
|
+
* @param [options.groupProps] Extra attributes for the group element.
|
|
14
|
+
* @param [options.disabledValue] Value of a single item to disable.
|
|
15
|
+
* @returns A component ready to pass to `render`.
|
|
16
|
+
*/
|
|
17
|
+
function createGroup({
|
|
18
|
+
type,
|
|
19
|
+
modelValue,
|
|
20
|
+
groupProps = '',
|
|
21
|
+
disabledValue = '',
|
|
22
|
+
}: {
|
|
23
|
+
type: 'single' | 'multiple';
|
|
24
|
+
modelValue: ReturnType<typeof ref>;
|
|
25
|
+
groupProps?: string;
|
|
26
|
+
disabledValue?: string;
|
|
27
|
+
}) {
|
|
28
|
+
return defineComponent({
|
|
29
|
+
components: { UiToggleGroup, UiToggleGroupItem },
|
|
30
|
+
setup() {
|
|
31
|
+
return { modelValue, disabledValue };
|
|
32
|
+
},
|
|
33
|
+
template: `
|
|
34
|
+
<UiToggleGroup v-model="modelValue" type="${type}" ${groupProps}>
|
|
35
|
+
<UiToggleGroupItem value="a" :disabled="disabledValue === 'a'">A</UiToggleGroupItem>
|
|
36
|
+
<UiToggleGroupItem value="b" :disabled="disabledValue === 'b'">B</UiToggleGroupItem>
|
|
37
|
+
<UiToggleGroupItem value="c" :disabled="disabledValue === 'c'">C</UiToggleGroupItem>
|
|
38
|
+
</UiToggleGroup>
|
|
39
|
+
`,
|
|
39
40
|
});
|
|
41
|
+
}
|
|
40
42
|
|
|
43
|
+
describe('UiToggleGroup', () => {
|
|
41
44
|
describe('Single Selection Behavior', () => {
|
|
42
45
|
test('clicking an item selects it', async () => {
|
|
43
46
|
const user = userEvent.setup();
|
|
44
47
|
const modelValue = ref<string>('');
|
|
45
|
-
|
|
46
|
-
const Component = defineComponent({
|
|
47
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
48
|
-
setup() {
|
|
49
|
-
return { modelValue };
|
|
50
|
-
},
|
|
51
|
-
template: `
|
|
52
|
-
<UiToggleGroup v-model="modelValue" type="single">
|
|
53
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
54
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
55
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
56
|
-
</UiToggleGroup>
|
|
57
|
-
`,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const { getByText } = render(Component);
|
|
48
|
+
const { getByText } = render(createGroup({ type: 'single', modelValue }));
|
|
61
49
|
|
|
62
50
|
await user.click(getByText('A'));
|
|
63
51
|
await nextTick();
|
|
@@ -65,198 +53,83 @@ describe('UiToggleGroup', () => {
|
|
|
65
53
|
expect(modelValue.value).toBe('a');
|
|
66
54
|
});
|
|
67
55
|
|
|
68
|
-
test('
|
|
56
|
+
test('selecting a different item replaces the previous selection', async () => {
|
|
69
57
|
const user = userEvent.setup();
|
|
70
58
|
const modelValue = ref<string>('a');
|
|
71
|
-
|
|
72
|
-
const Component = defineComponent({
|
|
73
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
74
|
-
setup() {
|
|
75
|
-
return { modelValue };
|
|
76
|
-
},
|
|
77
|
-
template: `
|
|
78
|
-
<UiToggleGroup v-model="modelValue" type="single">
|
|
79
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
80
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
81
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
82
|
-
</UiToggleGroup>
|
|
83
|
-
`,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const { getByText } = render(Component);
|
|
87
|
-
|
|
88
|
-
expect(modelValue.value).toBe('a');
|
|
89
|
-
|
|
90
|
-
await user.click(getByText('B'));
|
|
91
|
-
await nextTick();
|
|
92
|
-
|
|
93
|
-
expect(modelValue.value).toBe('b');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('only one item shows pressed state at a time', async () => {
|
|
97
|
-
const user = userEvent.setup();
|
|
98
|
-
const modelValue = ref<string>('a');
|
|
99
|
-
|
|
100
|
-
const Component = defineComponent({
|
|
101
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
102
|
-
setup() {
|
|
103
|
-
return { modelValue };
|
|
104
|
-
},
|
|
105
|
-
template: `
|
|
106
|
-
<UiToggleGroup v-model="modelValue" type="single">
|
|
107
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
108
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
109
|
-
</UiToggleGroup>
|
|
110
|
-
`,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const { getByText } = render(Component);
|
|
114
|
-
|
|
59
|
+
const { getByText } = render(createGroup({ type: 'single', modelValue }));
|
|
115
60
|
const itemA = getByText('A').closest('button');
|
|
116
61
|
const itemB = getByText('B').closest('button');
|
|
117
62
|
|
|
118
|
-
expect(itemA).toHaveAttribute('
|
|
119
|
-
expect(itemB).toHaveAttribute('data-state', 'off');
|
|
63
|
+
expect(itemA).toHaveAttribute('aria-pressed', 'true');
|
|
120
64
|
|
|
121
65
|
await user.click(getByText('B'));
|
|
122
66
|
await nextTick();
|
|
123
67
|
|
|
124
|
-
expect(
|
|
125
|
-
expect(
|
|
68
|
+
expect(modelValue.value).toBe('b');
|
|
69
|
+
expect(itemA).toHaveAttribute('aria-pressed', 'false');
|
|
70
|
+
expect(itemB).toHaveAttribute('aria-pressed', 'true');
|
|
126
71
|
});
|
|
127
72
|
});
|
|
128
73
|
|
|
129
74
|
describe('Multiple Selection Behavior', () => {
|
|
130
|
-
test('
|
|
131
|
-
const user = userEvent.setup();
|
|
132
|
-
const modelValue = ref<string[]>([]);
|
|
133
|
-
|
|
134
|
-
const Component = defineComponent({
|
|
135
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
136
|
-
setup() {
|
|
137
|
-
return { modelValue };
|
|
138
|
-
},
|
|
139
|
-
template: `
|
|
140
|
-
<UiToggleGroup v-model="modelValue" type="multiple">
|
|
141
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
142
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
143
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
144
|
-
</UiToggleGroup>
|
|
145
|
-
`,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const { getByText } = render(Component);
|
|
149
|
-
|
|
150
|
-
await user.click(getByText('A'));
|
|
151
|
-
await nextTick();
|
|
152
|
-
|
|
153
|
-
expect(modelValue.value).toContain('a');
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('clicking multiple items selects all of them', async () => {
|
|
75
|
+
test('items accumulate in the selection', async () => {
|
|
157
76
|
const user = userEvent.setup();
|
|
158
77
|
const modelValue = ref<string[]>([]);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
setup() {
|
|
163
|
-
return { modelValue };
|
|
164
|
-
},
|
|
165
|
-
template: `
|
|
166
|
-
<UiToggleGroup v-model="modelValue" type="multiple">
|
|
167
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
168
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
169
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
170
|
-
</UiToggleGroup>
|
|
171
|
-
`,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const { getByText } = render(Component);
|
|
78
|
+
const { getByText } = render(
|
|
79
|
+
createGroup({ type: 'multiple', modelValue }),
|
|
80
|
+
);
|
|
175
81
|
|
|
176
82
|
await user.click(getByText('A'));
|
|
177
83
|
await user.click(getByText('B'));
|
|
178
84
|
await nextTick();
|
|
179
85
|
|
|
180
|
-
expect(modelValue.value).
|
|
181
|
-
expect(modelValue.value).toContain('b');
|
|
182
|
-
expect(modelValue.value).toHaveLength(2);
|
|
86
|
+
expect(modelValue.value).toEqual(['a', 'b']);
|
|
183
87
|
});
|
|
184
88
|
|
|
185
|
-
test('clicking a selected item removes it from selection', async () => {
|
|
89
|
+
test('clicking a selected item removes it from the selection', async () => {
|
|
186
90
|
const user = userEvent.setup();
|
|
187
91
|
const modelValue = ref<string[]>(['a', 'b']);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
setup() {
|
|
192
|
-
return { modelValue };
|
|
193
|
-
},
|
|
194
|
-
template: `
|
|
195
|
-
<UiToggleGroup v-model="modelValue" type="multiple">
|
|
196
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
197
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
198
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
199
|
-
</UiToggleGroup>
|
|
200
|
-
`,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const { getByText } = render(Component);
|
|
92
|
+
const { getByText } = render(
|
|
93
|
+
createGroup({ type: 'multiple', modelValue }),
|
|
94
|
+
);
|
|
204
95
|
|
|
205
96
|
await user.click(getByText('A'));
|
|
206
97
|
await nextTick();
|
|
207
98
|
|
|
208
|
-
expect(modelValue.value).
|
|
209
|
-
expect(modelValue.value).toContain('b');
|
|
99
|
+
expect(modelValue.value).toEqual(['b']);
|
|
210
100
|
});
|
|
211
101
|
|
|
212
|
-
test('
|
|
102
|
+
test('several items report the pressed state at once', () => {
|
|
213
103
|
const modelValue = ref<string[]>(['a', 'b']);
|
|
104
|
+
const { getByText } = render(
|
|
105
|
+
createGroup({ type: 'multiple', modelValue }),
|
|
106
|
+
);
|
|
214
107
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const { getByText } = render(Component);
|
|
230
|
-
|
|
231
|
-
const itemA = getByText('A').closest('button');
|
|
232
|
-
const itemB = getByText('B').closest('button');
|
|
233
|
-
const itemC = getByText('C').closest('button');
|
|
234
|
-
|
|
235
|
-
expect(itemA).toHaveAttribute('data-state', 'on');
|
|
236
|
-
expect(itemB).toHaveAttribute('data-state', 'on');
|
|
237
|
-
expect(itemC).toHaveAttribute('data-state', 'off');
|
|
108
|
+
expect(getByText('A').closest('button')).toHaveAttribute(
|
|
109
|
+
'aria-pressed',
|
|
110
|
+
'true',
|
|
111
|
+
);
|
|
112
|
+
expect(getByText('B').closest('button')).toHaveAttribute(
|
|
113
|
+
'aria-pressed',
|
|
114
|
+
'true',
|
|
115
|
+
);
|
|
116
|
+
expect(getByText('C').closest('button')).toHaveAttribute(
|
|
117
|
+
'aria-pressed',
|
|
118
|
+
'false',
|
|
119
|
+
);
|
|
238
120
|
});
|
|
239
121
|
});
|
|
240
122
|
|
|
241
123
|
describe('Disabled Group Behavior', () => {
|
|
242
|
-
test('disabled group
|
|
124
|
+
test('a disabled group disables every item and ignores clicks', async () => {
|
|
243
125
|
const user = userEvent.setup();
|
|
244
126
|
const modelValue = ref<string>('a');
|
|
127
|
+
const { getByText } = render(
|
|
128
|
+
createGroup({ type: 'single', modelValue, groupProps: 'disabled' }),
|
|
129
|
+
);
|
|
245
130
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
setup() {
|
|
249
|
-
return { modelValue };
|
|
250
|
-
},
|
|
251
|
-
template: `
|
|
252
|
-
<UiToggleGroup v-model="modelValue" type="single" disabled>
|
|
253
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
254
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
255
|
-
</UiToggleGroup>
|
|
256
|
-
`,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
const { getByText } = render(Component);
|
|
131
|
+
expect(getByText('A').closest('button')).toBeDisabled();
|
|
132
|
+
expect(getByText('B').closest('button')).toBeDisabled();
|
|
260
133
|
|
|
261
134
|
await user.click(getByText('B'));
|
|
262
135
|
await nextTick();
|
|
@@ -264,175 +137,94 @@ describe('UiToggleGroup', () => {
|
|
|
264
137
|
expect(modelValue.value).toBe('a');
|
|
265
138
|
});
|
|
266
139
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
`,
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const { getByText } = render(Component);
|
|
140
|
+
// A disabled group must not become a dead tab stop: reka takes the roving
|
|
141
|
+
// focus container out of the tab order along with its items.
|
|
142
|
+
test('a disabled group leaves the tab order', async () => {
|
|
143
|
+
const modelValue = ref<string>('a');
|
|
144
|
+
const { container, getByText } = render(
|
|
145
|
+
createGroup({ type: 'single', modelValue, groupProps: 'disabled' }),
|
|
146
|
+
);
|
|
147
|
+
await nextTick();
|
|
279
148
|
|
|
280
|
-
expect(
|
|
281
|
-
|
|
149
|
+
expect(
|
|
150
|
+
container.querySelector('[data-slot="toggle-group"]'),
|
|
151
|
+
).toHaveAttribute('tabindex', '-1');
|
|
152
|
+
expect(getByText('A').closest('button')).toHaveAttribute(
|
|
153
|
+
'tabindex',
|
|
154
|
+
'-1',
|
|
155
|
+
);
|
|
282
156
|
});
|
|
283
157
|
});
|
|
284
158
|
|
|
285
159
|
describe('Individual Disabled Item Behavior', () => {
|
|
286
|
-
test('disabled item
|
|
160
|
+
test('a disabled item ignores clicks while its siblings still work', async () => {
|
|
287
161
|
const user = userEvent.setup();
|
|
288
162
|
const modelValue = ref<string>('a');
|
|
163
|
+
const { getByText } = render(
|
|
164
|
+
createGroup({ type: 'single', modelValue, disabledValue: 'b' }),
|
|
165
|
+
);
|
|
289
166
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
setup() {
|
|
293
|
-
return { modelValue };
|
|
294
|
-
},
|
|
295
|
-
template: `
|
|
296
|
-
<UiToggleGroup v-model="modelValue" type="single">
|
|
297
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
298
|
-
<UiToggleGroupItem value="b" disabled>B</UiToggleGroupItem>
|
|
299
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
300
|
-
</UiToggleGroup>
|
|
301
|
-
`,
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
const { getByText } = render(Component);
|
|
167
|
+
expect(getByText('B').closest('button')).toBeDisabled();
|
|
168
|
+
expect(getByText('A').closest('button')).not.toBeDisabled();
|
|
305
169
|
|
|
306
170
|
await user.click(getByText('B'));
|
|
307
171
|
await nextTick();
|
|
308
|
-
|
|
309
172
|
expect(modelValue.value).toBe('a');
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
test('only disabled item has disabled attribute', () => {
|
|
313
|
-
const Component = defineComponent({
|
|
314
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
315
|
-
template: `
|
|
316
|
-
<UiToggleGroup type="single">
|
|
317
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
318
|
-
<UiToggleGroupItem value="b" disabled>B</UiToggleGroupItem>
|
|
319
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
320
|
-
</UiToggleGroup>
|
|
321
|
-
`,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
const { getByText } = render(Component);
|
|
325
|
-
|
|
326
|
-
expect(getByText('A').closest('button')).not.toBeDisabled();
|
|
327
|
-
expect(getByText('B').closest('button')).toBeDisabled();
|
|
328
|
-
expect(getByText('C').closest('button')).not.toBeDisabled();
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test('non-disabled items still work when one item is disabled', async () => {
|
|
332
|
-
const user = userEvent.setup();
|
|
333
|
-
const modelValue = ref<string>('a');
|
|
334
|
-
|
|
335
|
-
const Component = defineComponent({
|
|
336
|
-
components: { UiToggleGroup, UiToggleGroupItem },
|
|
337
|
-
setup() {
|
|
338
|
-
return { modelValue };
|
|
339
|
-
},
|
|
340
|
-
template: `
|
|
341
|
-
<UiToggleGroup v-model="modelValue" type="single">
|
|
342
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
343
|
-
<UiToggleGroupItem value="b" disabled>B</UiToggleGroupItem>
|
|
344
|
-
<UiToggleGroupItem value="c">C</UiToggleGroupItem>
|
|
345
|
-
</UiToggleGroup>
|
|
346
|
-
`,
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const { getByText } = render(Component);
|
|
350
173
|
|
|
351
174
|
await user.click(getByText('C'));
|
|
352
175
|
await nextTick();
|
|
353
|
-
|
|
354
176
|
expect(modelValue.value).toBe('c');
|
|
355
177
|
});
|
|
356
178
|
});
|
|
357
179
|
|
|
358
|
-
describe('
|
|
359
|
-
test('
|
|
360
|
-
const { container } = render(UiToggleGroup, {
|
|
361
|
-
props: { type: 'single' },
|
|
362
|
-
slots: {
|
|
363
|
-
default: {
|
|
364
|
-
components: { UiToggleGroupItem },
|
|
365
|
-
template:
|
|
366
|
-
'<UiToggleGroupItem value="test">Test</UiToggleGroupItem>',
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
global: {
|
|
370
|
-
components: { UiToggleGroupItem },
|
|
371
|
-
},
|
|
372
|
-
});
|
|
373
|
-
const item = container.querySelector('[data-slot="toggle-group-item"]');
|
|
374
|
-
expect(item).toBeInTheDocument();
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
test('items use muted-subtle hover fill', () => {
|
|
180
|
+
describe('Styling', () => {
|
|
181
|
+
test('maps the group variant onto its items', () => {
|
|
378
182
|
const { container } = render(UiToggleGroup, {
|
|
379
|
-
props: { type: 'single' },
|
|
183
|
+
props: { type: 'single', variant: 'soft' },
|
|
380
184
|
slots: {
|
|
381
185
|
default: {
|
|
382
186
|
components: { UiToggleGroupItem },
|
|
383
|
-
template:
|
|
384
|
-
'<UiToggleGroupItem value="test">Test</UiToggleGroupItem>',
|
|
187
|
+
template: '<UiToggleGroupItem value="a">A</UiToggleGroupItem>',
|
|
385
188
|
},
|
|
386
189
|
},
|
|
387
|
-
global: {
|
|
388
|
-
components: { UiToggleGroupItem },
|
|
389
|
-
},
|
|
190
|
+
global: { components: { UiToggleGroupItem } },
|
|
390
191
|
});
|
|
391
|
-
|
|
392
|
-
|
|
192
|
+
expect(
|
|
193
|
+
container.querySelector('[data-slot="toggle-group-item"]'),
|
|
194
|
+
).toHaveClass('data-[state=on]:bg-accent');
|
|
393
195
|
});
|
|
394
196
|
|
|
395
|
-
test('
|
|
197
|
+
test('maps the group size onto its items', () => {
|
|
396
198
|
const { container } = render(UiToggleGroup, {
|
|
397
|
-
props: { type: '
|
|
199
|
+
props: { type: 'single', size: 'lg' },
|
|
398
200
|
slots: {
|
|
399
201
|
default: {
|
|
400
202
|
components: { UiToggleGroupItem },
|
|
401
|
-
template:
|
|
402
|
-
<UiToggleGroupItem value="a">A</UiToggleGroupItem>
|
|
403
|
-
<UiToggleGroupItem value="b">B</UiToggleGroupItem>
|
|
404
|
-
`,
|
|
203
|
+
template: '<UiToggleGroupItem value="a">A</UiToggleGroupItem>',
|
|
405
204
|
},
|
|
406
205
|
},
|
|
407
|
-
global: {
|
|
408
|
-
components: { UiToggleGroupItem },
|
|
409
|
-
},
|
|
206
|
+
global: { components: { UiToggleGroupItem } },
|
|
410
207
|
});
|
|
411
|
-
|
|
412
|
-
'[data-slot="toggle-group-item"]',
|
|
413
|
-
);
|
|
414
|
-
expect(items).toHaveLength(2);
|
|
208
|
+
expect(
|
|
209
|
+
container.querySelector('[data-slot="toggle-group-item"]'),
|
|
210
|
+
).toHaveClass('h-10');
|
|
415
211
|
});
|
|
416
212
|
|
|
417
|
-
test('
|
|
213
|
+
test('lets an item override the group size', () => {
|
|
418
214
|
const { container } = render(UiToggleGroup, {
|
|
419
|
-
props: { type: 'single',
|
|
215
|
+
props: { type: 'single', size: 'lg' },
|
|
420
216
|
slots: {
|
|
421
217
|
default: {
|
|
422
218
|
components: { UiToggleGroupItem },
|
|
423
|
-
template:
|
|
219
|
+
template:
|
|
220
|
+
'<UiToggleGroupItem value="a" size="sm">A</UiToggleGroupItem>',
|
|
424
221
|
},
|
|
425
222
|
},
|
|
426
|
-
global: {
|
|
427
|
-
components: { UiToggleGroupItem },
|
|
428
|
-
},
|
|
223
|
+
global: { components: { UiToggleGroupItem } },
|
|
429
224
|
});
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
expect(item).toHaveClass('data-[state=on]:border-accent-default');
|
|
434
|
-
expect(item).toHaveClass('aria-pressed:bg-accent');
|
|
435
|
-
expect(item).toHaveClass('aria-pressed:border-accent-default');
|
|
225
|
+
expect(
|
|
226
|
+
container.querySelector('[data-slot="toggle-group-item"]'),
|
|
227
|
+
).toHaveClass('h-8');
|
|
436
228
|
});
|
|
437
229
|
});
|
|
438
230
|
});
|
|
@@ -27,11 +27,6 @@ export interface UiToggleGroupBaseProps {
|
|
|
27
27
|
* @default true
|
|
28
28
|
*/
|
|
29
29
|
rovingFocus?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* The orientation of the toggle group for keyboard navigation.
|
|
32
|
-
* @default 'horizontal'
|
|
33
|
-
*/
|
|
34
|
-
orientation?: 'horizontal' | 'vertical';
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
class?: HTMLAttributes['class'];
|
|
6
|
+
}>();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<nav aria-label="breadcrumb" data-slot="breadcrumb" :class="props.class">
|
|
11
|
+
<slot />
|
|
12
|
+
</nav>
|
|
13
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
import { MoreHorizontal } from 'lucide-vue-next';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
class?: HTMLAttributes['class'];
|
|
8
|
+
}>();
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<span
|
|
13
|
+
data-slot="breadcrumb-ellipsis"
|
|
14
|
+
role="presentation"
|
|
15
|
+
aria-hidden="true"
|
|
16
|
+
:class="cn('flex size-9 items-center justify-center', props.class)"
|
|
17
|
+
>
|
|
18
|
+
<slot>
|
|
19
|
+
<MoreHorizontal class="size-4" />
|
|
20
|
+
</slot>
|
|
21
|
+
<span class="sr-only">More</span>
|
|
22
|
+
</span>
|
|
23
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
class?: HTMLAttributes['class'];
|
|
7
|
+
}>();
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<li
|
|
12
|
+
data-slot="breadcrumb-item"
|
|
13
|
+
:class="cn('inline-flex items-center gap-1.5', props.class)"
|
|
14
|
+
>
|
|
15
|
+
<slot />
|
|
16
|
+
</li>
|
|
17
|
+
</template>
|