@pdanpdan/headless-combobox-vue 0.0.0-stage → 3.0.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.
@@ -0,0 +1,171 @@
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 · multiple · with filter';
4
+ export const description = 'Multiple selection capped with max; selecting toggles, dropdown stays open.';
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[]>([ 'Vue', 'Svelte' ]);
24
+ const labelId = useId();
25
+ const MAX = 3;
26
+ </script>
27
+
28
+ <template>
29
+ <div class="w-full max-w-sm">
30
+ <HeadlessCombobox
31
+ v-slot="{
32
+ filteredOptions, highlightedIndex, searchQuery,
33
+ clear, isSelected, canSelectMore, selectedCount,
34
+ cssAnchorName, popupStyle, triggerProps, inputProps, listboxProps, getOptionProps, setContainerRef,
35
+ setTriggerRef, setDropdownRef, setInputRef, setListRef, setOptionRef,
36
+ }"
37
+ v-model="selected"
38
+ :options="frameworks"
39
+ multiple
40
+ :max-length="MAX"
41
+ >
42
+ <fieldset
43
+ :ref="setContainerRef"
44
+ class="fieldset"
45
+ >
46
+ <legend :id="labelId" class="fieldset-legend">Frameworks (multiple, max {{ MAX }})</legend>
47
+ <button
48
+ :ref="setTriggerRef"
49
+ v-bind="triggerProps"
50
+ :aria-labelledby="labelId"
51
+ type="button"
52
+ class="
53
+ input flex h-auto min-h-10 w-full cursor-pointer items-center
54
+ justify-between py-1.5
55
+ "
56
+ :style="{ anchorName: cssAnchorName }"
57
+ >
58
+ <span v-if="selected.length" class="flex flex-wrap gap-1">
59
+ <span
60
+ v-for="item in selected"
61
+ :key="item"
62
+ class="badge badge-soft badge-sm"
63
+ >{{ item }}</span>
64
+ </span>
65
+ <span v-else class="text-base-content/70">Select frameworks…</span>
66
+ <span class="text-xs opacity-70">{{ selectedCount }}/{{ MAX }}</span>
67
+ </button>
68
+ </fieldset>
69
+
70
+ <div
71
+ :ref="setDropdownRef"
72
+ popover="manual"
73
+ class="
74
+ cbx-popup rounded-box border border-base-content/5 bg-base-200
75
+ shadow-xl
76
+ "
77
+ :style="[popupStyle, {
78
+ left: 'calc(anchor(left) - 0.25rem)',
79
+ width: 'calc(anchor-size(width) + 0.5rem)',
80
+ }]"
81
+ >
82
+ <div class="flex items-center gap-2 border-b border-base-content/10 p-2">
83
+ <input
84
+ :ref="setInputRef"
85
+ v-bind="inputProps"
86
+ :value="searchQuery"
87
+ type="text"
88
+ class="input flex-1 input-sm"
89
+ placeholder="Search…"
90
+ aria-label="Search frameworks"
91
+ />
92
+ <button
93
+ type="button"
94
+ class="btn btn-ghost btn-sm"
95
+ @click="clear"
96
+ >
97
+ Clear
98
+ </button>
99
+ </div>
100
+
101
+ <ul
102
+ :ref="setListRef"
103
+ v-bind="listboxProps"
104
+ class="menu max-h-60 w-full flex-nowrap gap-0.5 overflow-y-auto"
105
+ >
106
+ <li
107
+ v-for="(framework, index) in filteredOptions"
108
+ :key="framework"
109
+ >
110
+ <button
111
+ :ref="(el) => setOptionRef(framework, el)"
112
+ type="button"
113
+ v-bind="getOptionProps(framework, index)"
114
+ class="justify-between shadow-none"
115
+ :class="{
116
+ 'menu-active': isSelected(framework),
117
+ 'menu-focus': index === highlightedIndex,
118
+ }"
119
+ :disabled="!canSelectMore && !isSelected(framework)"
120
+ >
121
+ <span>{{ framework }}</span>
122
+ <svg
123
+ v-if="isSelected(framework)"
124
+ class="size-4"
125
+ fill="none"
126
+ stroke="currentColor"
127
+ viewBox="0 0 24 24"
128
+ >
129
+ <path
130
+ stroke-linecap="round"
131
+ stroke-linejoin="round"
132
+ stroke-width="2"
133
+ d="M4.5 12.75l6 6 9-13.5"
134
+ />
135
+ </svg>
136
+ </button>
137
+ </li>
138
+ </ul>
139
+ </div>
140
+ </HeadlessCombobox>
141
+ </div>
142
+ </template>
143
+
144
+ <style scoped>
145
+ /* Popup opens below the control: slide + fade via the Popover API. */
146
+ .cbx-popup {
147
+ inset: auto;
148
+ position-try: flip-block;
149
+ opacity: 0;
150
+ margin-block-start: 0;
151
+ transition:
152
+ opacity 0.15s ease,
153
+ margin-block-start 0.15s ease,
154
+ overlay 0.15s ease allow-discrete,
155
+ display 0.15s ease allow-discrete;
156
+
157
+ &:not(:popover-open) {
158
+ display: none;
159
+ }
160
+
161
+ &:popover-open {
162
+ opacity: 1;
163
+ margin-block-start: 0.5rem;
164
+
165
+ @starting-style {
166
+ opacity: 0;
167
+ margin-block-start: 0;
168
+ }
169
+ }
170
+ }
171
+ </style>
@@ -0,0 +1,192 @@
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 · multiple · removable chips';
4
+ export const description = 'Selected items as removable chips. The remove buttons live outside the combobox trigger, so the trigger stays a single focusable control.';
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[]>([ 'Vue', 'Svelte' ]);
24
+ const labelId = useId();
25
+ const MAX = 3;
26
+ </script>
27
+
28
+ <template>
29
+ <div class="w-full max-w-sm">
30
+ <HeadlessCombobox
31
+ v-slot="{
32
+ filteredOptions, highlightedIndex, searchQuery, select,
33
+ clear, isSelected, canSelectMore, selectedCount,
34
+ cssAnchorName, popupStyle, triggerProps, inputProps, listboxProps, getOptionProps, setContainerRef,
35
+ setTriggerRef, setDropdownRef, setInputRef, setListRef, setOptionRef,
36
+ }"
37
+ v-model="selected"
38
+ :options="frameworks"
39
+ multiple
40
+ :max-length="MAX"
41
+ >
42
+ <fieldset
43
+ :ref="setContainerRef"
44
+ class="fieldset"
45
+ >
46
+ <legend :id="labelId" class="fieldset-legend">Frameworks (multiple, max {{ MAX }})</legend>
47
+ <div v-if="selected.length" class="mb-1.5 flex flex-wrap gap-1">
48
+ <span
49
+ v-for="item in selected"
50
+ :key="item"
51
+ class="badge gap-1 badge-soft pr-0"
52
+ >
53
+ {{ item }}
54
+ <button
55
+ type="button"
56
+ class="btn btn-circle btn-ghost btn-xs"
57
+ :aria-label="`Remove ${ item }`"
58
+ @click="select(item)"
59
+ >
60
+ <svg
61
+ class="size-3"
62
+ fill="none"
63
+ stroke="currentColor"
64
+ viewBox="0 0 24 24"
65
+ aria-hidden="true"
66
+ >
67
+ <path
68
+ stroke-linecap="round"
69
+ stroke-linejoin="round"
70
+ stroke-width="2"
71
+ d="M6 18L18 6M6 6l12 12"
72
+ />
73
+ </svg>
74
+ </button>
75
+ </span>
76
+ </div>
77
+ <button
78
+ :ref="setTriggerRef"
79
+ v-bind="triggerProps"
80
+ :aria-labelledby="labelId"
81
+ type="button"
82
+ class="input flex w-full cursor-pointer items-center justify-between"
83
+ :style="{ anchorName: cssAnchorName }"
84
+ >
85
+ <span v-if="selected.length" class="text-base-content/70">{{ selected.length }} selected</span>
86
+ <span v-else class="text-base-content/70">Select frameworks…</span>
87
+ <span class="text-xs opacity-70">{{ selectedCount }}/{{ MAX }}</span>
88
+ </button>
89
+ </fieldset>
90
+
91
+ <div
92
+ :ref="setDropdownRef"
93
+ popover="manual"
94
+ class="
95
+ cbx-popup rounded-box border border-base-content/5 bg-base-200
96
+ shadow-xl
97
+ "
98
+ :style="[popupStyle, {
99
+ left: 'calc(anchor(left) - 0.25rem)',
100
+ width: 'calc(anchor-size(width) + 0.5rem)',
101
+ }]"
102
+ >
103
+ <div class="flex items-center gap-2 border-b border-base-content/10 p-2">
104
+ <input
105
+ :ref="setInputRef"
106
+ v-bind="inputProps"
107
+ :value="searchQuery"
108
+ type="text"
109
+ class="input flex-1 input-sm"
110
+ placeholder="Search…"
111
+ aria-label="Search frameworks"
112
+ />
113
+ <button
114
+ type="button"
115
+ class="btn btn-ghost btn-sm"
116
+ @click="clear"
117
+ >
118
+ Clear
119
+ </button>
120
+ </div>
121
+
122
+ <ul
123
+ :ref="setListRef"
124
+ v-bind="listboxProps"
125
+ class="menu max-h-60 w-full flex-nowrap gap-0.5 overflow-y-auto"
126
+ >
127
+ <li
128
+ v-for="(framework, index) in filteredOptions"
129
+ :key="framework"
130
+ >
131
+ <button
132
+ :ref="(el) => setOptionRef(framework, el)"
133
+ type="button"
134
+ v-bind="getOptionProps(framework, index)"
135
+ class="justify-between shadow-none"
136
+ :class="{
137
+ 'menu-active': isSelected(framework),
138
+ 'menu-focus': index === highlightedIndex,
139
+ }"
140
+ :disabled="!canSelectMore && !isSelected(framework)"
141
+ >
142
+ <span>{{ framework }}</span>
143
+ <svg
144
+ v-if="isSelected(framework)"
145
+ class="size-4"
146
+ fill="none"
147
+ stroke="currentColor"
148
+ viewBox="0 0 24 24"
149
+ >
150
+ <path
151
+ stroke-linecap="round"
152
+ stroke-linejoin="round"
153
+ stroke-width="2"
154
+ d="M4.5 12.75l6 6 9-13.5"
155
+ />
156
+ </svg>
157
+ </button>
158
+ </li>
159
+ </ul>
160
+ </div>
161
+ </HeadlessCombobox>
162
+ </div>
163
+ </template>
164
+
165
+ <style scoped>
166
+ /* Popup opens below the control: slide + fade via the Popover API. */
167
+ .cbx-popup {
168
+ inset: auto;
169
+ position-try: flip-block;
170
+ opacity: 0;
171
+ margin-block-start: 0;
172
+ transition:
173
+ opacity 0.15s ease,
174
+ margin-block-start 0.15s ease,
175
+ overlay 0.15s ease allow-discrete,
176
+ display 0.15s ease allow-discrete;
177
+
178
+ &:not(:popover-open) {
179
+ display: none;
180
+ }
181
+
182
+ &:popover-open {
183
+ opacity: 1;
184
+ margin-block-start: 0.5rem;
185
+
186
+ @starting-style {
187
+ opacity: 0;
188
+ margin-block-start: 0;
189
+ }
190
+ }
191
+ }
192
+ </style>
@@ -0,0 +1,162 @@
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 · multiple · custom options';
4
+ export const description = 'Each option renders its own checkbox for the selection state; the trigger shows the selected items as chips.';
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[]>([ 'Vue', 'Svelte' ]);
24
+ const labelId = useId();
25
+ const MAX = 3;
26
+ </script>
27
+
28
+ <template>
29
+ <div class="w-full max-w-sm">
30
+ <HeadlessCombobox
31
+ v-slot="{
32
+ filteredOptions, highlightedIndex, searchQuery,
33
+ clear, isSelected, canSelectMore, selectedCount,
34
+ cssAnchorName, popupStyle, triggerProps, inputProps, listboxProps, getOptionProps, setContainerRef,
35
+ setTriggerRef, setDropdownRef, setInputRef, setListRef, setOptionRef,
36
+ }"
37
+ v-model="selected"
38
+ :options="frameworks"
39
+ multiple
40
+ :max-length="MAX"
41
+ >
42
+ <fieldset
43
+ :ref="setContainerRef"
44
+ class="fieldset"
45
+ >
46
+ <legend :id="labelId" class="fieldset-legend">Frameworks (multiple, custom options)</legend>
47
+ <button
48
+ :ref="setTriggerRef"
49
+ v-bind="triggerProps"
50
+ :aria-labelledby="labelId"
51
+ type="button"
52
+ class="
53
+ input flex h-auto min-h-10 w-full cursor-pointer items-center
54
+ justify-between py-1.5
55
+ "
56
+ :style="{ anchorName: cssAnchorName }"
57
+ >
58
+ <span v-if="selected.length" class="flex flex-wrap gap-1">
59
+ <span
60
+ v-for="item in selected"
61
+ :key="item"
62
+ class="badge badge-soft badge-sm"
63
+ >{{ item }}</span>
64
+ </span>
65
+ <span v-else class="text-base-content/70">Select frameworks…</span>
66
+ <span class="text-xs opacity-70">{{ selectedCount }}/{{ MAX }}</span>
67
+ </button>
68
+ </fieldset>
69
+
70
+ <div
71
+ :ref="setDropdownRef"
72
+ popover="manual"
73
+ class="
74
+ cbx-popup rounded-box border border-base-content/5 bg-base-200
75
+ shadow-xl
76
+ "
77
+ :style="[popupStyle, {
78
+ left: 'calc(anchor(left) - 0.25rem)',
79
+ width: 'calc(anchor-size(width) + 0.5rem)',
80
+ }]"
81
+ >
82
+ <div class="flex items-center gap-2 border-b border-base-content/10 p-2">
83
+ <input
84
+ :ref="setInputRef"
85
+ v-bind="inputProps"
86
+ :value="searchQuery"
87
+ type="text"
88
+ class="input flex-1 input-sm"
89
+ placeholder="Search…"
90
+ aria-label="Search frameworks"
91
+ />
92
+ <button
93
+ type="button"
94
+ class="btn btn-ghost btn-sm"
95
+ @click="clear"
96
+ >
97
+ Clear
98
+ </button>
99
+ </div>
100
+
101
+ <ul
102
+ :ref="setListRef"
103
+ v-bind="listboxProps"
104
+ class="menu max-h-60 w-full flex-nowrap gap-0.5 overflow-y-auto"
105
+ >
106
+ <li
107
+ v-for="(framework, index) in filteredOptions"
108
+ :key="framework"
109
+ >
110
+ <button
111
+ :ref="(el) => setOptionRef(framework, el)"
112
+ type="button"
113
+ v-bind="getOptionProps(framework, index)"
114
+ class="justify-between gap-2 rounded-sm border-l-3 shadow-none"
115
+ :class="{
116
+ 'border-l-primary': index === highlightedIndex,
117
+ 'border-l-transparent': index !== highlightedIndex,
118
+ }"
119
+ :disabled="!canSelectMore && !isSelected(framework)"
120
+ >
121
+ <span>{{ framework }}</span>
122
+ <span
123
+ class="checkbox rounded-xs checkbox-xs checkbox-primary"
124
+ :aria-checked="isSelected(framework)"
125
+ aria-hidden="true"
126
+ />
127
+ </button>
128
+ </li>
129
+ </ul>
130
+ </div>
131
+ </HeadlessCombobox>
132
+ </div>
133
+ </template>
134
+
135
+ <style scoped>
136
+ /* Popup opens below the control: slide + fade via the Popover API. */
137
+ .cbx-popup {
138
+ inset: auto;
139
+ position-try: flip-block;
140
+ opacity: 0;
141
+ margin-block-start: 0;
142
+ transition:
143
+ opacity 0.15s ease,
144
+ margin-block-start 0.15s ease,
145
+ overlay 0.15s ease allow-discrete,
146
+ display 0.15s ease allow-discrete;
147
+
148
+ &:not(:popover-open) {
149
+ display: none;
150
+ }
151
+
152
+ &:popover-open {
153
+ opacity: 1;
154
+ margin-block-start: 0.5rem;
155
+
156
+ @starting-style {
157
+ opacity: 0;
158
+ margin-block-start: 0;
159
+ }
160
+ }
161
+ }
162
+ </style>
@@ -0,0 +1,148 @@
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 · select on tab';
4
+ export const description = 'Press Tab with an option highlighted: it is selected and the popup closes (selectOnTab).';
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>(null);
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
+ select-on-tab
38
+ >
39
+ <fieldset
40
+ :ref="setContainerRef"
41
+ class="fieldset"
42
+ >
43
+ <legend :id="labelId" class="fieldset-legend">Framework (single, select on tab)</legend>
44
+ <button
45
+ :ref="setTriggerRef"
46
+ v-bind="triggerProps"
47
+ :aria-labelledby="labelId"
48
+ type="button"
49
+ class="input flex w-full cursor-pointer items-center justify-between"
50
+ :style="{ anchorName: cssAnchorName }"
51
+ >
52
+ <span :class="{ 'text-base-content/70': selected == null }">{{ selected ?? 'Select a framework…' }}</span>
53
+ <svg
54
+ class="size-4 opacity-70"
55
+ fill="none"
56
+ stroke="currentColor"
57
+ viewBox="0 0 24 24"
58
+ >
59
+ <path
60
+ stroke-linecap="round"
61
+ stroke-linejoin="round"
62
+ stroke-width="2"
63
+ d="M8 9l4-4 4 4m0 6l-4 4-4-4"
64
+ />
65
+ </svg>
66
+ </button>
67
+ </fieldset>
68
+
69
+ <ul
70
+ :ref="(el) => { setDropdownRef(el); setListRef(el); }"
71
+ v-bind="listboxProps"
72
+ popover="manual"
73
+ class="
74
+ cbx-popup menu max-h-60 flex-nowrap gap-0.5 rounded-box border
75
+ border-base-content/5 bg-base-200 shadow-xl
76
+ "
77
+ :style="[popupStyle, {
78
+ left: 'calc(anchor(left) - 0.25rem)',
79
+ width: 'calc(anchor-size(width) + 0.5rem)',
80
+ }]"
81
+ >
82
+ <li
83
+ v-for="(framework, index) in filteredOptions"
84
+ :key="framework"
85
+ >
86
+ <button
87
+ :ref="(el) => setOptionRef(framework, el)"
88
+ type="button"
89
+ v-bind="getOptionProps(framework, index)"
90
+ class="justify-between shadow-none"
91
+ :class="{
92
+ 'menu-active': isSelected(framework),
93
+ 'menu-focus': index === highlightedIndex,
94
+ }"
95
+ >
96
+ <span>{{ framework }}</span>
97
+ <svg
98
+ v-if="isSelected(framework)"
99
+ class="size-4"
100
+ fill="none"
101
+ stroke="currentColor"
102
+ viewBox="0 0 24 24"
103
+ >
104
+ <path
105
+ stroke-linecap="round"
106
+ stroke-linejoin="round"
107
+ stroke-width="2"
108
+ d="M4.5 12.75l6 6 9-13.5"
109
+ />
110
+ </svg>
111
+ </button>
112
+ </li>
113
+ </ul>
114
+ </HeadlessCombobox>
115
+ </div>
116
+ </template>
117
+
118
+ <style scoped>
119
+ /* Popup opens below the control: slide + fade via the Popover API. */
120
+ .cbx-popup {
121
+ inset: auto;
122
+ position-try: flip-block;
123
+ opacity: 0;
124
+ margin-block-start: 0;
125
+
126
+ @media (prefers-reduced-motion: no-preference) {
127
+ transition:
128
+ opacity 0.15s ease,
129
+ margin-block-start 0.15s ease,
130
+ overlay 0.15s ease allow-discrete,
131
+ display 0.15s ease allow-discrete;
132
+ }
133
+
134
+ &:not(:popover-open) {
135
+ display: none;
136
+ }
137
+
138
+ &:popover-open {
139
+ opacity: 1;
140
+ margin-block-start: 0.5rem;
141
+
142
+ @starting-style {
143
+ opacity: 0;
144
+ margin-block-start: 0;
145
+ }
146
+ }
147
+ }
148
+ </style>