@pdanpdan/headless-combobox-vue 0.0.0-stage → 3.0.1
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/LICENSE +21 -0
- package/README.md +330 -2
- package/dist/HeadlessCombobox.vue.d.ts +27 -0
- package/dist/HeadlessCombobox.vue.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +183 -0
- package/dist/index.mjs.map +1 -0
- package/dist/useHeadlessCombobox.d.ts +61 -0
- package/dist/useHeadlessCombobox.d.ts.map +1 -0
- package/examples/ComposableProgrammatic.vue +195 -0
- package/examples/ComposableSingle.vue +206 -0
- package/examples/NiceSelect.vue +149 -0
- package/examples/ObjectMultipleValidated.vue +192 -0
- package/examples/ObjectSingle.vue +189 -0
- package/examples/ObjectValueSingle.vue +148 -0
- package/examples/TextInternal.vue +148 -0
- package/examples/TextMultiple.vue +171 -0
- package/examples/TextMultipleChips.vue +192 -0
- package/examples/TextMultipleCustom.vue +162 -0
- package/examples/TextSelectOnTab.vue +148 -0
- package/examples/TextSingle.vue +144 -0
- package/examples/TextTypeahead.vue +184 -0
- package/examples/TextTypeaheadChips.vue +218 -0
- package/package.json +79 -3
- package/src/HeadlessCombobox.vue +124 -0
- package/src/index.ts +15 -0
- package/src/useHeadlessCombobox.ts +239 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/* eslint-disable import/first -- the exports below precede the setup imports in the compiled module */
|
|
3
|
+
export const title = 'Text options · single · no filter';
|
|
4
|
+
export const description = 'A list of plain string options, single selection, no search input.';
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { HeadlessCombobox } from '@pdanpdan/headless-combobox-vue';
|
|
9
|
+
import { ref, useId } from 'vue';
|
|
10
|
+
|
|
11
|
+
const frameworks = [
|
|
12
|
+
'Vue',
|
|
13
|
+
'React',
|
|
14
|
+
'Svelte',
|
|
15
|
+
'Solid',
|
|
16
|
+
'Angular',
|
|
17
|
+
'Preact',
|
|
18
|
+
'Lit',
|
|
19
|
+
'Alpine',
|
|
20
|
+
'Ember',
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const selected = ref<string | null>('Vue');
|
|
24
|
+
const labelId = useId();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div class="w-full max-w-sm">
|
|
29
|
+
<HeadlessCombobox
|
|
30
|
+
v-slot="{
|
|
31
|
+
filteredOptions, highlightedIndex, isSelected,
|
|
32
|
+
cssAnchorName, popupStyle, triggerProps, listboxProps,
|
|
33
|
+
getOptionProps, setContainerRef, setTriggerRef, setDropdownRef, setListRef, setOptionRef,
|
|
34
|
+
}"
|
|
35
|
+
v-model="selected"
|
|
36
|
+
:options="frameworks"
|
|
37
|
+
>
|
|
38
|
+
<fieldset
|
|
39
|
+
:ref="setContainerRef"
|
|
40
|
+
class="fieldset"
|
|
41
|
+
>
|
|
42
|
+
<legend :id="labelId" class="fieldset-legend">Framework (single, no filter)</legend>
|
|
43
|
+
<button
|
|
44
|
+
:ref="setTriggerRef"
|
|
45
|
+
v-bind="triggerProps"
|
|
46
|
+
:aria-labelledby="labelId"
|
|
47
|
+
type="button"
|
|
48
|
+
class="input flex w-full cursor-pointer items-center justify-between"
|
|
49
|
+
:style="{ anchorName: cssAnchorName }"
|
|
50
|
+
>
|
|
51
|
+
<span :class="{ 'text-base-content/70': selected == null }">{{ selected ?? 'Select a framework…' }}</span>
|
|
52
|
+
<svg
|
|
53
|
+
class="size-4 opacity-70"
|
|
54
|
+
fill="none"
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
viewBox="0 0 24 24"
|
|
57
|
+
>
|
|
58
|
+
<path
|
|
59
|
+
stroke-linecap="round"
|
|
60
|
+
stroke-linejoin="round"
|
|
61
|
+
stroke-width="2"
|
|
62
|
+
d="M8 9l4-4 4 4m0 6l-4 4-4-4"
|
|
63
|
+
/>
|
|
64
|
+
</svg>
|
|
65
|
+
</button>
|
|
66
|
+
</fieldset>
|
|
67
|
+
|
|
68
|
+
<ul
|
|
69
|
+
:ref="(el) => { setDropdownRef(el); setListRef(el); }"
|
|
70
|
+
v-bind="listboxProps"
|
|
71
|
+
popover="manual"
|
|
72
|
+
class="
|
|
73
|
+
cbx-popup menu max-h-60 flex-nowrap gap-0.5 rounded-box border
|
|
74
|
+
border-base-content/5 bg-base-200 shadow-xl
|
|
75
|
+
"
|
|
76
|
+
:style="[popupStyle, {
|
|
77
|
+
left: 'calc(anchor(left) - 0.25rem)',
|
|
78
|
+
width: 'calc(anchor-size(width) + 0.5rem)',
|
|
79
|
+
}]"
|
|
80
|
+
>
|
|
81
|
+
<li
|
|
82
|
+
v-for="(framework, index) in filteredOptions"
|
|
83
|
+
:key="framework"
|
|
84
|
+
>
|
|
85
|
+
<button
|
|
86
|
+
:ref="(el) => setOptionRef(framework, el)"
|
|
87
|
+
type="button"
|
|
88
|
+
v-bind="getOptionProps(framework, index)"
|
|
89
|
+
class="justify-between shadow-none"
|
|
90
|
+
:class="{
|
|
91
|
+
'menu-active': isSelected(framework),
|
|
92
|
+
'menu-focus': index === highlightedIndex,
|
|
93
|
+
}"
|
|
94
|
+
>
|
|
95
|
+
<span>{{ framework }}</span>
|
|
96
|
+
<svg
|
|
97
|
+
v-if="isSelected(framework)"
|
|
98
|
+
class="size-4"
|
|
99
|
+
fill="none"
|
|
100
|
+
stroke="currentColor"
|
|
101
|
+
viewBox="0 0 24 24"
|
|
102
|
+
>
|
|
103
|
+
<path
|
|
104
|
+
stroke-linecap="round"
|
|
105
|
+
stroke-linejoin="round"
|
|
106
|
+
stroke-width="2"
|
|
107
|
+
d="M4.5 12.75l6 6 9-13.5"
|
|
108
|
+
/>
|
|
109
|
+
</svg>
|
|
110
|
+
</button>
|
|
111
|
+
</li>
|
|
112
|
+
</ul>
|
|
113
|
+
</HeadlessCombobox>
|
|
114
|
+
</div>
|
|
115
|
+
</template>
|
|
116
|
+
|
|
117
|
+
<style scoped>
|
|
118
|
+
/* Popup opens below the control: slide + fade via the Popover API. */
|
|
119
|
+
.cbx-popup {
|
|
120
|
+
inset: auto;
|
|
121
|
+
position-try: flip-block;
|
|
122
|
+
opacity: 0;
|
|
123
|
+
margin-block-start: 0;
|
|
124
|
+
transition:
|
|
125
|
+
opacity 0.15s ease,
|
|
126
|
+
margin-block-start 0.15s ease,
|
|
127
|
+
overlay 0.15s ease allow-discrete,
|
|
128
|
+
display 0.15s ease allow-discrete;
|
|
129
|
+
|
|
130
|
+
&:not(:popover-open) {
|
|
131
|
+
display: none;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
&:popover-open {
|
|
135
|
+
opacity: 1;
|
|
136
|
+
margin-block-start: 0.5rem;
|
|
137
|
+
|
|
138
|
+
@starting-style {
|
|
139
|
+
opacity: 0;
|
|
140
|
+
margin-block-start: 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
</style>
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/* eslint-disable import/first -- the exports below precede the setup imports in the compiled module */
|
|
3
|
+
export const title = 'Typeahead (editable combobox)';
|
|
4
|
+
export const description = 'Canonical APG editable pattern: the text input itself is the combobox (role=combobox); type to filter.';
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { HeadlessCombobox } from '@pdanpdan/headless-combobox-vue';
|
|
9
|
+
import { ref, useId } from 'vue';
|
|
10
|
+
|
|
11
|
+
const languages = [
|
|
12
|
+
'JavaScript',
|
|
13
|
+
'TypeScript',
|
|
14
|
+
'Python',
|
|
15
|
+
'Rust',
|
|
16
|
+
'Go',
|
|
17
|
+
'Java',
|
|
18
|
+
'C#',
|
|
19
|
+
'C++',
|
|
20
|
+
'Ruby',
|
|
21
|
+
'PHP',
|
|
22
|
+
'Swift',
|
|
23
|
+
'Kotlin',
|
|
24
|
+
'Dart',
|
|
25
|
+
'Elixir',
|
|
26
|
+
'Haskell',
|
|
27
|
+
'Scala',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const selected = ref<string | null>(null);
|
|
31
|
+
const labelId = useId();
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div class="w-full max-w-sm">
|
|
36
|
+
<HeadlessCombobox
|
|
37
|
+
v-slot="{
|
|
38
|
+
isOpen, filteredOptions, highlightedIndex, searchQuery, toggle, open,
|
|
39
|
+
isSelected, handleKeydown, cssAnchorName, popupStyle,
|
|
40
|
+
comboboxInputProps, listboxProps, getOptionProps, setContainerRef, setTriggerRef,
|
|
41
|
+
setInputRef, setDropdownRef, setListRef, setOptionRef,
|
|
42
|
+
}"
|
|
43
|
+
v-model="selected"
|
|
44
|
+
:options="languages"
|
|
45
|
+
>
|
|
46
|
+
<fieldset
|
|
47
|
+
:ref="setContainerRef"
|
|
48
|
+
class="fieldset"
|
|
49
|
+
>
|
|
50
|
+
<legend :id="labelId" class="fieldset-legend">Language (typeahead, editable)</legend>
|
|
51
|
+
<!-- eslint-disable-next-line vue-a11y/click-events-have-key-events, vue-a11y/no-static-element-interactions -- the inner input is the keyboard-operable control; this only widens the pointer target -->
|
|
52
|
+
<div
|
|
53
|
+
class="input relative flex w-full items-center"
|
|
54
|
+
:style="{ anchorName: cssAnchorName }"
|
|
55
|
+
@click.self="open"
|
|
56
|
+
>
|
|
57
|
+
<input
|
|
58
|
+
:ref="(el) => { setTriggerRef(el); setInputRef(el); }"
|
|
59
|
+
v-bind="comboboxInputProps"
|
|
60
|
+
:aria-labelledby="labelId"
|
|
61
|
+
:value="searchQuery ?? (selected ?? '')"
|
|
62
|
+
type="text"
|
|
63
|
+
class="w-full pe-6"
|
|
64
|
+
placeholder="Search a language…"
|
|
65
|
+
@keydown="(e) => { if (e.key !== ' ') { handleKeydown(e); } }"
|
|
66
|
+
/>
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
tabindex="-1"
|
|
70
|
+
class="
|
|
71
|
+
absolute top-1/2 right-2 -translate-y-1/2 cursor-pointer
|
|
72
|
+
text-base-content/70
|
|
73
|
+
"
|
|
74
|
+
aria-label="Toggle suggestions"
|
|
75
|
+
@click.stop="toggle"
|
|
76
|
+
>
|
|
77
|
+
<svg
|
|
78
|
+
class="
|
|
79
|
+
size-4
|
|
80
|
+
motion-safe:transition-transform
|
|
81
|
+
"
|
|
82
|
+
:class="{ 'rotate-180': isOpen }"
|
|
83
|
+
fill="none"
|
|
84
|
+
stroke="currentColor"
|
|
85
|
+
viewBox="0 0 24 24"
|
|
86
|
+
>
|
|
87
|
+
<path
|
|
88
|
+
stroke-linecap="round"
|
|
89
|
+
stroke-linejoin="round"
|
|
90
|
+
stroke-width="2"
|
|
91
|
+
d="M19 9l-7 7-7-7"
|
|
92
|
+
/>
|
|
93
|
+
</svg>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
</fieldset>
|
|
97
|
+
|
|
98
|
+
<ul
|
|
99
|
+
:ref="(el) => { setDropdownRef(el); setListRef(el); }"
|
|
100
|
+
v-bind="listboxProps"
|
|
101
|
+
popover="manual"
|
|
102
|
+
class="
|
|
103
|
+
cbx-popup menu max-h-60 flex-nowrap gap-0.5 rounded-box border
|
|
104
|
+
border-base-content/5 bg-base-200 shadow-xl
|
|
105
|
+
"
|
|
106
|
+
:style="[popupStyle, {
|
|
107
|
+
left: 'calc(anchor(left) - 0.25rem)',
|
|
108
|
+
width: 'calc(anchor-size(width) + 0.5rem)',
|
|
109
|
+
}]"
|
|
110
|
+
>
|
|
111
|
+
<li
|
|
112
|
+
v-for="(language, index) in filteredOptions"
|
|
113
|
+
:key="language"
|
|
114
|
+
>
|
|
115
|
+
<button
|
|
116
|
+
:ref="(el) => setOptionRef(language, el)"
|
|
117
|
+
type="button"
|
|
118
|
+
v-bind="getOptionProps(language, index)"
|
|
119
|
+
class="justify-between shadow-none"
|
|
120
|
+
:class="{
|
|
121
|
+
'menu-active': isSelected(language),
|
|
122
|
+
'menu-focus': index === highlightedIndex,
|
|
123
|
+
}"
|
|
124
|
+
>
|
|
125
|
+
<span>{{ language }}</span>
|
|
126
|
+
<svg
|
|
127
|
+
v-if="isSelected(language)"
|
|
128
|
+
class="size-4"
|
|
129
|
+
fill="none"
|
|
130
|
+
stroke="currentColor"
|
|
131
|
+
viewBox="0 0 24 24"
|
|
132
|
+
>
|
|
133
|
+
<path
|
|
134
|
+
stroke-linecap="round"
|
|
135
|
+
stroke-linejoin="round"
|
|
136
|
+
stroke-width="2"
|
|
137
|
+
d="M4.5 12.75l6 6 9-13.5"
|
|
138
|
+
/>
|
|
139
|
+
</svg>
|
|
140
|
+
</button>
|
|
141
|
+
</li>
|
|
142
|
+
|
|
143
|
+
<li
|
|
144
|
+
v-if="filteredOptions.length === 0"
|
|
145
|
+
class="
|
|
146
|
+
pointer-events-none p-4 text-center text-sm text-base-content/70
|
|
147
|
+
"
|
|
148
|
+
role="presentation"
|
|
149
|
+
>
|
|
150
|
+
No matches.
|
|
151
|
+
</li>
|
|
152
|
+
</ul>
|
|
153
|
+
</HeadlessCombobox>
|
|
154
|
+
</div>
|
|
155
|
+
</template>
|
|
156
|
+
|
|
157
|
+
<style scoped>
|
|
158
|
+
/* Popup opens below the control: slide + fade via the Popover API. */
|
|
159
|
+
.cbx-popup {
|
|
160
|
+
inset: auto;
|
|
161
|
+
position-try: flip-block;
|
|
162
|
+
opacity: 0;
|
|
163
|
+
margin-block-start: 0;
|
|
164
|
+
transition:
|
|
165
|
+
opacity 0.15s ease,
|
|
166
|
+
margin-block-start 0.15s ease,
|
|
167
|
+
overlay 0.15s ease allow-discrete,
|
|
168
|
+
display 0.15s ease allow-discrete;
|
|
169
|
+
|
|
170
|
+
&:not(:popover-open) {
|
|
171
|
+
display: none;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
&:popover-open {
|
|
175
|
+
opacity: 1;
|
|
176
|
+
margin-block-start: 0.5rem;
|
|
177
|
+
|
|
178
|
+
@starting-style {
|
|
179
|
+
opacity: 0;
|
|
180
|
+
margin-block-start: 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
</style>
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/* eslint-disable import/first -- the exports below precede the setup imports in the compiled module */
|
|
3
|
+
export const title = 'Typeahead · chips inside the field';
|
|
4
|
+
export const description = 'GitHub-style topic input: chips and the text input share one bordered field. The field is a plain container, so each chip can carry a remove button without nesting controls.';
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { HeadlessCombobox } from '@pdanpdan/headless-combobox-vue';
|
|
9
|
+
import { nextTick, ref, useId, watch } from 'vue';
|
|
10
|
+
|
|
11
|
+
const languages = [
|
|
12
|
+
'JavaScript',
|
|
13
|
+
'TypeScript',
|
|
14
|
+
'Python',
|
|
15
|
+
'Rust',
|
|
16
|
+
'Go',
|
|
17
|
+
'Java',
|
|
18
|
+
'C#',
|
|
19
|
+
'C++',
|
|
20
|
+
'Ruby',
|
|
21
|
+
'PHP',
|
|
22
|
+
'Swift',
|
|
23
|
+
'Kotlin',
|
|
24
|
+
'Dart',
|
|
25
|
+
'Elixir',
|
|
26
|
+
'Haskell',
|
|
27
|
+
'Scala',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const selected = ref<string[]>([ 'TypeScript' ]);
|
|
31
|
+
const labelId = useId();
|
|
32
|
+
const chipsRef = ref<HTMLElement | null>(null);
|
|
33
|
+
|
|
34
|
+
// Keep the newest chip in view when the chip row overflows.
|
|
35
|
+
watch(selected, () => {
|
|
36
|
+
nextTick(() => {
|
|
37
|
+
const el = chipsRef.value;
|
|
38
|
+
if (el) {
|
|
39
|
+
el.scrollTo({ left: el.scrollWidth });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<div class="w-full max-w-sm">
|
|
47
|
+
<HeadlessCombobox
|
|
48
|
+
v-slot="{
|
|
49
|
+
isOpen, filteredOptions, highlightedIndex, searchQuery, open,
|
|
50
|
+
select, isSelected, canSelectMore, handleKeydown, cssAnchorName, popupStyle,
|
|
51
|
+
comboboxInputProps, listboxProps, getOptionProps, setContainerRef, setTriggerRef,
|
|
52
|
+
setInputRef, setDropdownRef, setListRef, setOptionRef,
|
|
53
|
+
}"
|
|
54
|
+
v-model="selected"
|
|
55
|
+
:options="languages"
|
|
56
|
+
multiple
|
|
57
|
+
:max-length="3"
|
|
58
|
+
>
|
|
59
|
+
<fieldset
|
|
60
|
+
:ref="setContainerRef"
|
|
61
|
+
class="fieldset"
|
|
62
|
+
>
|
|
63
|
+
<legend :id="labelId" class="fieldset-legend">Topics (typeahead, removable chips in the field)</legend>
|
|
64
|
+
<!-- eslint-disable-next-line vue-a11y/click-events-have-key-events, vue-a11y/no-static-element-interactions -- the inner input is the keyboard-operable control; this only widens the pointer target -->
|
|
65
|
+
<div
|
|
66
|
+
class="
|
|
67
|
+
input flex h-auto min-h-10 w-full min-w-0 items-center gap-1 py-1.5
|
|
68
|
+
"
|
|
69
|
+
:style="{ anchorName: cssAnchorName }"
|
|
70
|
+
@click.self="open"
|
|
71
|
+
>
|
|
72
|
+
<div
|
|
73
|
+
ref="chipsRef"
|
|
74
|
+
class="
|
|
75
|
+
flex min-h-10 min-w-0 scrollbar-thin items-center gap-1
|
|
76
|
+
overflow-x-auto
|
|
77
|
+
"
|
|
78
|
+
>
|
|
79
|
+
<span
|
|
80
|
+
v-for="item in selected"
|
|
81
|
+
:key="item"
|
|
82
|
+
class="badge gap-1 badge-soft pr-0"
|
|
83
|
+
>
|
|
84
|
+
{{ item }}
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
class="btn btn-circle btn-ghost btn-xs"
|
|
88
|
+
:aria-label="`Remove ${ item }`"
|
|
89
|
+
@mousedown.prevent
|
|
90
|
+
@click.stop="select(item)"
|
|
91
|
+
>
|
|
92
|
+
<svg
|
|
93
|
+
class="size-3"
|
|
94
|
+
fill="none"
|
|
95
|
+
stroke="currentColor"
|
|
96
|
+
viewBox="0 0 24 24"
|
|
97
|
+
aria-hidden="true"
|
|
98
|
+
>
|
|
99
|
+
<path
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
stroke-width="2"
|
|
103
|
+
d="M6 18L18 6M6 6l12 12"
|
|
104
|
+
/>
|
|
105
|
+
</svg>
|
|
106
|
+
</button>
|
|
107
|
+
</span>
|
|
108
|
+
</div>
|
|
109
|
+
<input
|
|
110
|
+
:ref="(el) => { setTriggerRef(el); setInputRef(el); }"
|
|
111
|
+
v-bind="comboboxInputProps"
|
|
112
|
+
:aria-labelledby="labelId"
|
|
113
|
+
:value="isOpen ? searchQuery : ''"
|
|
114
|
+
type="text"
|
|
115
|
+
class="min-w-24 flex-1"
|
|
116
|
+
placeholder="Add a topic…"
|
|
117
|
+
@keydown="(e) => {
|
|
118
|
+
if (e.key === 'Backspace' && !searchQuery && selected.length > 0) {
|
|
119
|
+
const last = selected[selected.length - 1];
|
|
120
|
+
if (last) { select(last); }
|
|
121
|
+
}
|
|
122
|
+
else if (e.key !== ' ') {
|
|
123
|
+
handleKeydown(e);
|
|
124
|
+
}
|
|
125
|
+
}"
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
</fieldset>
|
|
129
|
+
|
|
130
|
+
<ul
|
|
131
|
+
:ref="(el) => { setDropdownRef(el); setListRef(el); }"
|
|
132
|
+
v-bind="listboxProps"
|
|
133
|
+
popover="manual"
|
|
134
|
+
class="
|
|
135
|
+
cbx-popup menu max-h-60 flex-nowrap gap-0.5 rounded-box border
|
|
136
|
+
border-base-content/5 bg-base-200 shadow-xl
|
|
137
|
+
"
|
|
138
|
+
:style="[popupStyle, {
|
|
139
|
+
left: 'calc(anchor(left) - 0.25rem)',
|
|
140
|
+
width: 'calc(anchor-size(width) + 0.5rem)',
|
|
141
|
+
}]"
|
|
142
|
+
>
|
|
143
|
+
<li
|
|
144
|
+
v-for="(language, index) in filteredOptions"
|
|
145
|
+
:key="language"
|
|
146
|
+
>
|
|
147
|
+
<button
|
|
148
|
+
:ref="(el) => setOptionRef(language, el)"
|
|
149
|
+
type="button"
|
|
150
|
+
v-bind="getOptionProps(language, index)"
|
|
151
|
+
class="justify-between shadow-none"
|
|
152
|
+
:class="{
|
|
153
|
+
'menu-active': isSelected(language),
|
|
154
|
+
'menu-focus': index === highlightedIndex,
|
|
155
|
+
'cursor-pointer': canSelectMore || isSelected(language),
|
|
156
|
+
}"
|
|
157
|
+
:disabled="!canSelectMore && !isSelected(language)"
|
|
158
|
+
>
|
|
159
|
+
<span>{{ language }}</span>
|
|
160
|
+
<svg
|
|
161
|
+
v-if="isSelected(language)"
|
|
162
|
+
class="size-4"
|
|
163
|
+
fill="none"
|
|
164
|
+
stroke="currentColor"
|
|
165
|
+
viewBox="0 0 24 24"
|
|
166
|
+
>
|
|
167
|
+
<path
|
|
168
|
+
stroke-linecap="round"
|
|
169
|
+
stroke-linejoin="round"
|
|
170
|
+
stroke-width="2"
|
|
171
|
+
d="M4.5 12.75l6 6 9-13.5"
|
|
172
|
+
/>
|
|
173
|
+
</svg>
|
|
174
|
+
</button>
|
|
175
|
+
</li>
|
|
176
|
+
|
|
177
|
+
<li
|
|
178
|
+
v-if="filteredOptions.length === 0"
|
|
179
|
+
class="
|
|
180
|
+
pointer-events-none p-4 text-center text-sm text-base-content/70
|
|
181
|
+
"
|
|
182
|
+
role="presentation"
|
|
183
|
+
>
|
|
184
|
+
No matches.
|
|
185
|
+
</li>
|
|
186
|
+
</ul>
|
|
187
|
+
</HeadlessCombobox>
|
|
188
|
+
</div>
|
|
189
|
+
</template>
|
|
190
|
+
|
|
191
|
+
<style scoped>
|
|
192
|
+
/* Popup opens below the control: slide + fade via the Popover API. */
|
|
193
|
+
.cbx-popup {
|
|
194
|
+
inset: auto;
|
|
195
|
+
position-try: flip-block;
|
|
196
|
+
opacity: 0;
|
|
197
|
+
margin-block-start: 0;
|
|
198
|
+
transition:
|
|
199
|
+
opacity 0.15s ease,
|
|
200
|
+
margin-block-start 0.15s ease,
|
|
201
|
+
overlay 0.15s ease allow-discrete,
|
|
202
|
+
display 0.15s ease allow-discrete;
|
|
203
|
+
|
|
204
|
+
&:not(:popover-open) {
|
|
205
|
+
display: none;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&:popover-open {
|
|
209
|
+
opacity: 1;
|
|
210
|
+
margin-block-start: 0.5rem;
|
|
211
|
+
|
|
212
|
+
@starting-style {
|
|
213
|
+
opacity: 0;
|
|
214
|
+
margin-block-start: 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
</style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdanpdan/headless-combobox-vue",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "3.0.1",
|
|
5
|
+
"description": "Accessible renderless combobox for Vue 3, built on the framework-independent core",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://pdanpdan.github.io/headless-components",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/pdanpdan/headless-components.git",
|
|
12
|
+
"directory": "packages/headless-combobox-vue"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pdanpdan/headless-components/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"vue",
|
|
19
|
+
"vue3",
|
|
20
|
+
"combobox",
|
|
21
|
+
"headless",
|
|
22
|
+
"renderless",
|
|
23
|
+
"select",
|
|
24
|
+
"autocomplete",
|
|
25
|
+
"accessibility",
|
|
26
|
+
"typescript"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./source": {
|
|
36
|
+
"types": "./src/index.ts",
|
|
37
|
+
"import": "./src/index.ts"
|
|
38
|
+
},
|
|
39
|
+
"./HeadlessCombobox.vue": "./src/HeadlessCombobox.vue",
|
|
40
|
+
"./examples/*": "./examples/*"
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.cjs",
|
|
43
|
+
"module": "./dist/index.mjs",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"examples",
|
|
48
|
+
"src"
|
|
49
|
+
],
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"vue": "^3.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public",
|
|
55
|
+
"registry": "https://registry.npmjs.org/"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@pdanpdan/headless-combobox-core": "3.0.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@vitejs/plugin-vue": "^6.0.11",
|
|
62
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
63
|
+
"@vue/test-utils": "^2.6.0",
|
|
64
|
+
"jsdom": "^31.0.1",
|
|
65
|
+
"typescript": "^6.0.3",
|
|
66
|
+
"vite": "^8.3.8",
|
|
67
|
+
"vite-plugin-dts": "^5.1.2",
|
|
68
|
+
"vitest": "^5.1.1",
|
|
69
|
+
"vue": "^3.5.46",
|
|
70
|
+
"vue-tsc": "^3.3.14"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "vite build",
|
|
74
|
+
"lint": "pnpm --dir ../.. lint",
|
|
75
|
+
"test": "vitest run",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"test:coverage": "vitest run --coverage",
|
|
78
|
+
"typecheck": "vue-tsc -p tsconfig.app.json --noEmit && vue-tsc -p tsconfig.vitest.json --noEmit",
|
|
79
|
+
"test:all": "pnpm lint && pnpm typecheck && pnpm test && pnpm test:coverage",
|
|
80
|
+
"release:npm": "pnpm publish"
|
|
81
|
+
}
|
|
6
82
|
}
|