@aleph-alpha/ui-library 5.5.0 → 5.6.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/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
- package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
- package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
- package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
- package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
- package/dist/system/components/core/button-group/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +7850 -7728
- package/dist/system/story-sidebar-icons.json +3 -0
- package/package.json +1 -1
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +619 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
- package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
- package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
- package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
- package/src/components/UiButtonGroup/index.ts +2 -0
- package/src/components/UiButtonGroup/types.ts +21 -0
- package/src/components/UiSelect/UiSelect.stories.ts +769 -0
- package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
- package/src/components/core/button-group/ButtonGroup.vue +24 -0
- package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
- package/src/components/core/button-group/ButtonGroupText.vue +33 -0
- package/src/components/core/button-group/index.ts +25 -0
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/index.ts +1 -0
|
@@ -37,6 +37,7 @@ const props = withDefaults(defineProps<UiAutocompleteProps>(), {
|
|
|
37
37
|
|
|
38
38
|
const emit = defineEmits<UiAutocompleteEmits>();
|
|
39
39
|
|
|
40
|
+
const rootEl = ref<HTMLElement | null>(null);
|
|
40
41
|
const inputEl = ref<HTMLInputElement | null>(null);
|
|
41
42
|
const itemLabels = ref<Map<string, string>>(new Map());
|
|
42
43
|
const highlightedIndex = ref(-1);
|
|
@@ -143,7 +144,7 @@ const inputSlotProps = computed(() => ({
|
|
|
143
144
|
|
|
144
145
|
const shellClasses = computed(() =>
|
|
145
146
|
cn(
|
|
146
|
-
'border-input
|
|
147
|
+
'border-input ui-focus-ring-within aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex h-9 w-full min-w-0 items-center gap-2 rounded-md border bg-background-input-default px-3 py-2 label-14-regular transition-[color,box-shadow]',
|
|
147
148
|
props.disabled && 'pointer-events-none cursor-not-allowed opacity-50',
|
|
148
149
|
),
|
|
149
150
|
);
|
|
@@ -253,6 +254,21 @@ function handleFocus(event: FocusEvent) {
|
|
|
253
254
|
setOpen(true);
|
|
254
255
|
}
|
|
255
256
|
|
|
257
|
+
// Also open on click: an already-focused input fires no focus event, e.g.
|
|
258
|
+
// clicking the input again after dismissing the list with Escape.
|
|
259
|
+
function handleInputClick() {
|
|
260
|
+
setOpen(true);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// The input sits in the popover anchor, outside the floating content, so the
|
|
264
|
+
// dismissable layer would otherwise close the list on clicks/focus in our own shell.
|
|
265
|
+
function handleInteractOutside(event: CustomEvent) {
|
|
266
|
+
const target = event.target as Node | null;
|
|
267
|
+
if (target && rootEl.value?.contains(target)) {
|
|
268
|
+
event.preventDefault();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
256
272
|
function handleBlur(event: FocusEvent) {
|
|
257
273
|
emit('blur', event);
|
|
258
274
|
}
|
|
@@ -310,7 +326,7 @@ provideUiAutocompleteContext({
|
|
|
310
326
|
</script>
|
|
311
327
|
|
|
312
328
|
<template>
|
|
313
|
-
<div class="flex flex-col" :dir="props.dir">
|
|
329
|
+
<div ref="rootEl" class="flex flex-col" :dir="props.dir">
|
|
314
330
|
<ShadcnPopover v-model:open="openState">
|
|
315
331
|
<ShadcnPopoverAnchor as-child>
|
|
316
332
|
<div
|
|
@@ -354,6 +370,7 @@ provideUiAutocompleteContext({
|
|
|
354
370
|
"
|
|
355
371
|
@input="handleInput"
|
|
356
372
|
@focus="handleFocus"
|
|
373
|
+
@click="handleInputClick"
|
|
357
374
|
@blur="handleBlur"
|
|
358
375
|
@keydown="handleKeydown"
|
|
359
376
|
/>
|
|
@@ -383,14 +400,22 @@ provideUiAutocompleteContext({
|
|
|
383
400
|
</div>
|
|
384
401
|
</ShadcnPopoverAnchor>
|
|
385
402
|
|
|
403
|
+
<!--
|
|
404
|
+
Only external (slotted) items are force-mounted: they register their
|
|
405
|
+
labels on mount. Internal options come from props and can stay
|
|
406
|
+
unmounted while closed, keeping reka's focus guards out of the Tab
|
|
407
|
+
order.
|
|
408
|
+
-->
|
|
386
409
|
<ShadcnPopoverContent
|
|
387
410
|
data-slot="autocomplete-content"
|
|
411
|
+
aria-label="Suggestions"
|
|
388
412
|
side="bottom"
|
|
389
413
|
:side-offset="4"
|
|
390
414
|
align="start"
|
|
391
|
-
:force-mount="true"
|
|
415
|
+
:force-mount="hasInternalOptions ? undefined : true"
|
|
392
416
|
class="min-w-(--reka-popper-anchor-width) w-(--reka-popper-anchor-width) max-w-(--reka-popper-available-width) p-1 data-[state=closed]:hidden data-[state=closed]:pointer-events-none"
|
|
393
417
|
@open-auto-focus.prevent
|
|
418
|
+
@interact-outside="handleInteractOutside"
|
|
394
419
|
>
|
|
395
420
|
<div
|
|
396
421
|
role="listbox"
|
|
@@ -37,12 +37,10 @@ describe('UiAutocomplete', () => {
|
|
|
37
37
|
'[data-slot="autocomplete-trigger"]',
|
|
38
38
|
);
|
|
39
39
|
expect(trigger).toHaveAttribute('data-placeholder');
|
|
40
|
-
expect(trigger).toHaveClass(
|
|
41
|
-
'data-[placeholder]:bg-background-input-default',
|
|
42
|
-
);
|
|
40
|
+
expect(trigger).toHaveClass('bg-background-input-default');
|
|
43
41
|
});
|
|
44
42
|
|
|
45
|
-
test('
|
|
43
|
+
test('keeps the input surface in the filled state (value selected)', () => {
|
|
46
44
|
const { container } = render(UiAutocomplete, {
|
|
47
45
|
props: {
|
|
48
46
|
options,
|
|
@@ -55,29 +53,19 @@ describe('UiAutocomplete', () => {
|
|
|
55
53
|
'[data-slot="autocomplete-trigger"]',
|
|
56
54
|
);
|
|
57
55
|
expect(trigger).not.toHaveAttribute('data-placeholder');
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
// Filled state: same input surface as the empty state — only the muted
|
|
57
|
+
// placeholder text switches to regular value text. No accent background,
|
|
58
|
+
// and the focus-ring border stays reserved for focus.
|
|
59
|
+
expect(trigger).toHaveClass('bg-background-input-default');
|
|
60
|
+
expect(trigger).not.toHaveClass('bg-accent');
|
|
61
|
+
expect(trigger).not.toHaveClass(
|
|
60
62
|
'[&:not([data-placeholder])]:border-border-surface-focus-ring',
|
|
61
63
|
);
|
|
62
64
|
});
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
props: {
|
|
68
|
-
options,
|
|
69
|
-
placeholder: 'Search fruit',
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
await user.type(getByRole('textbox'), 'ban');
|
|
74
|
-
|
|
75
|
-
await waitFor(() => {
|
|
76
|
-
expect(getByRole('listbox')).toBeInTheDocument();
|
|
77
|
-
expect(getByRole('option', { name: 'Banana' })).toBeInTheDocument();
|
|
78
|
-
expect(queryByRole('option', { name: 'Apple' })).not.toBeInTheDocument();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
66
|
+
// Opening the suggestions, filtering by input text, choosing a value, and
|
|
67
|
+
// the disabled-option guard are covered by the `test - Filter And Select`
|
|
68
|
+
// play function in UiAutocomplete.stories.ts.
|
|
81
69
|
|
|
82
70
|
test('selects a single option and emits its value', async () => {
|
|
83
71
|
const user = userEvent.setup();
|
|
@@ -108,52 +96,9 @@ describe('UiAutocomplete', () => {
|
|
|
108
96
|
});
|
|
109
97
|
});
|
|
110
98
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
components: { UiAutocomplete },
|
|
115
|
-
template: `
|
|
116
|
-
<UiAutocomplete v-model="value" :options="options" placeholder="Search fruit" />
|
|
117
|
-
`,
|
|
118
|
-
setup() {
|
|
119
|
-
const value = ref('');
|
|
120
|
-
return { value, options };
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
await user.click(getByRole('textbox'));
|
|
125
|
-
await user.keyboard('{ArrowDown}');
|
|
126
|
-
|
|
127
|
-
await waitFor(() => {
|
|
128
|
-
expect(getByRole('option', { name: 'Apple' })).toHaveAttribute(
|
|
129
|
-
'data-highlighted',
|
|
130
|
-
'',
|
|
131
|
-
);
|
|
132
|
-
expect(
|
|
133
|
-
document.querySelector('[data-slot="autocomplete-value"]'),
|
|
134
|
-
).not.toBeInTheDocument();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
await user.keyboard('{ArrowDown}');
|
|
138
|
-
|
|
139
|
-
await waitFor(() => {
|
|
140
|
-
expect(getByRole('option', { name: 'Banana' })).toHaveAttribute(
|
|
141
|
-
'data-highlighted',
|
|
142
|
-
'',
|
|
143
|
-
);
|
|
144
|
-
expect(
|
|
145
|
-
document.querySelector('[data-slot="autocomplete-value"]'),
|
|
146
|
-
).not.toBeInTheDocument();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
await user.keyboard('{Enter}');
|
|
150
|
-
|
|
151
|
-
await waitFor(() => {
|
|
152
|
-
expect(
|
|
153
|
-
document.querySelector('[data-slot="autocomplete-value"]'),
|
|
154
|
-
).toHaveTextContent('Banana');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
99
|
+
// Keyboard navigation through internal options (arrow-key highlight, Enter
|
|
100
|
+
// selection, Escape dismissal) is covered by the `test - Keyboard
|
|
101
|
+
// Navigation` play function in UiAutocomplete.stories.ts.
|
|
157
102
|
|
|
158
103
|
test('starts keyboard navigation from the selected internal option when open', async () => {
|
|
159
104
|
const user = userEvent.setup();
|