@zag-js/combobox 0.74.2 → 0.76.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/index.d.mts +29 -29
- package/dist/index.d.ts +29 -29
- package/dist/index.js +21 -17
- package/dist/index.mjs +21 -17
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -37,11 +37,11 @@ interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
|
|
|
37
37
|
}
|
|
38
38
|
interface ScrollToIndexDetails {
|
|
39
39
|
index: number;
|
|
40
|
-
immediate?: boolean;
|
|
40
|
+
immediate?: boolean | undefined;
|
|
41
41
|
}
|
|
42
42
|
interface IntlTranslations {
|
|
43
|
-
triggerLabel?: string;
|
|
44
|
-
clearTriggerLabel?: string;
|
|
43
|
+
triggerLabel?: string | undefined;
|
|
44
|
+
clearTriggerLabel?: string | undefined;
|
|
45
45
|
}
|
|
46
46
|
type ElementIds = Partial<{
|
|
47
47
|
root: string;
|
|
@@ -60,15 +60,15 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
60
60
|
/**
|
|
61
61
|
* Whether the combobox is open
|
|
62
62
|
*/
|
|
63
|
-
open?: boolean;
|
|
63
|
+
open?: boolean | undefined;
|
|
64
64
|
/**
|
|
65
65
|
* Whether the combobox open state is controlled by the user
|
|
66
66
|
*/
|
|
67
|
-
"open.controlled"?: boolean;
|
|
67
|
+
"open.controlled"?: boolean | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* The ids of the elements in the combobox. Useful for composition.
|
|
70
70
|
*/
|
|
71
|
-
ids?: ElementIds;
|
|
71
|
+
ids?: ElementIds | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* The current value of the combobox's input
|
|
74
74
|
*/
|
|
@@ -76,32 +76,32 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
76
76
|
/**
|
|
77
77
|
* The `name` attribute of the combobox's input. Useful for form submission
|
|
78
78
|
*/
|
|
79
|
-
name?: string;
|
|
79
|
+
name?: string | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* The associate form of the combobox.
|
|
82
82
|
*/
|
|
83
|
-
form?: string;
|
|
83
|
+
form?: string | undefined;
|
|
84
84
|
/**
|
|
85
85
|
* Whether the combobox is disabled
|
|
86
86
|
*/
|
|
87
|
-
disabled?: boolean;
|
|
87
|
+
disabled?: boolean | undefined;
|
|
88
88
|
/**
|
|
89
89
|
* Whether the combobox is readonly. This puts the combobox in a "non-editable" mode
|
|
90
90
|
* but the user can still interact with it
|
|
91
91
|
*/
|
|
92
|
-
readOnly?: boolean;
|
|
92
|
+
readOnly?: boolean | undefined;
|
|
93
93
|
/**
|
|
94
94
|
* Whether the combobox is invalid
|
|
95
95
|
*/
|
|
96
|
-
invalid?: boolean;
|
|
96
|
+
invalid?: boolean | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* Whether the combobox is required
|
|
99
99
|
*/
|
|
100
|
-
required?: boolean;
|
|
100
|
+
required?: boolean | undefined;
|
|
101
101
|
/**
|
|
102
102
|
* The placeholder text of the combobox's input
|
|
103
103
|
*/
|
|
104
|
-
placeholder?: string;
|
|
104
|
+
placeholder?: string | undefined;
|
|
105
105
|
/**
|
|
106
106
|
* The active item's id. Used to set the `aria-activedescendant` attribute
|
|
107
107
|
*/
|
|
@@ -132,26 +132,26 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
132
132
|
/**
|
|
133
133
|
* Whether to autofocus the input on mount
|
|
134
134
|
*/
|
|
135
|
-
autoFocus?: boolean;
|
|
135
|
+
autoFocus?: boolean | undefined;
|
|
136
136
|
/**
|
|
137
137
|
* Whether to open the combobox popup on initial click on the input
|
|
138
138
|
* @default false
|
|
139
139
|
*/
|
|
140
|
-
openOnClick?: boolean;
|
|
140
|
+
openOnClick?: boolean | undefined;
|
|
141
141
|
/**
|
|
142
142
|
* Whether to show the combobox when the input value changes
|
|
143
143
|
* @default true
|
|
144
144
|
*/
|
|
145
|
-
openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean);
|
|
145
|
+
openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean) | undefined;
|
|
146
146
|
/**
|
|
147
147
|
* Whether to allow typing custom values in the input
|
|
148
148
|
*/
|
|
149
|
-
allowCustomValue?: boolean;
|
|
149
|
+
allowCustomValue?: boolean | undefined;
|
|
150
150
|
/**
|
|
151
151
|
* Whether to loop the keyboard navigation through the items
|
|
152
152
|
* @default true
|
|
153
153
|
*/
|
|
154
|
-
loopFocus?: boolean;
|
|
154
|
+
loopFocus?: boolean | undefined;
|
|
155
155
|
/**
|
|
156
156
|
* The positioning options to dynamically position the menu
|
|
157
157
|
*/
|
|
@@ -159,20 +159,20 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
159
159
|
/**
|
|
160
160
|
* Function called when the input's value changes
|
|
161
161
|
*/
|
|
162
|
-
onInputValueChange?: (details: InputValueChangeDetails) => void;
|
|
162
|
+
onInputValueChange?: ((details: InputValueChangeDetails) => void) | undefined;
|
|
163
163
|
/**
|
|
164
164
|
* Function called when a new item is selected
|
|
165
165
|
*/
|
|
166
|
-
onValueChange?: (details: ValueChangeDetails<T>) => void;
|
|
166
|
+
onValueChange?: ((details: ValueChangeDetails<T>) => void) | undefined;
|
|
167
167
|
/**
|
|
168
168
|
* Function called when an item is highlighted using the pointer
|
|
169
169
|
* or keyboard navigation.
|
|
170
170
|
*/
|
|
171
|
-
onHighlightChange?: (details: HighlightChangeDetails<T>) => void;
|
|
171
|
+
onHighlightChange?: ((details: HighlightChangeDetails<T>) => void) | undefined;
|
|
172
172
|
/**
|
|
173
173
|
* Function called when the popup is opened
|
|
174
174
|
*/
|
|
175
|
-
onOpenChange?: (details: OpenChangeDetails) => void;
|
|
175
|
+
onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
|
|
176
176
|
/**
|
|
177
177
|
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
178
178
|
*/
|
|
@@ -187,15 +187,15 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
187
187
|
* **Good to know:** When `multiple` is `true`, the `selectionBehavior` is automatically set to `clear`.
|
|
188
188
|
* It is recommended to render the selected items in a separate container.
|
|
189
189
|
*/
|
|
190
|
-
multiple?: boolean;
|
|
190
|
+
multiple?: boolean | undefined;
|
|
191
191
|
/**
|
|
192
192
|
* Whether to close the combobox when an item is selected.
|
|
193
193
|
*/
|
|
194
|
-
closeOnSelect?: boolean;
|
|
194
|
+
closeOnSelect?: boolean | undefined;
|
|
195
195
|
/**
|
|
196
196
|
* Function to get the display value of the selected item
|
|
197
197
|
*/
|
|
198
|
-
getSelectionValue?: (details: SelectionValueDetails<T>) => string;
|
|
198
|
+
getSelectionValue?: ((details: SelectionValueDetails<T>) => string) | undefined;
|
|
199
199
|
/**
|
|
200
200
|
* Whether to open the combobox on arrow key press
|
|
201
201
|
* @default true
|
|
@@ -204,7 +204,7 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
204
204
|
/**
|
|
205
205
|
* Function to scroll to a specific index
|
|
206
206
|
*/
|
|
207
|
-
scrollToIndexFn?: (details: ScrollToIndexDetails) => void;
|
|
207
|
+
scrollToIndexFn?: ((details: ScrollToIndexDetails) => void) | undefined;
|
|
208
208
|
/**
|
|
209
209
|
* Whether the combobox is a composed with other composite widgets like tabs
|
|
210
210
|
* @default true
|
|
@@ -213,7 +213,7 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
213
213
|
/**
|
|
214
214
|
* Whether to disable registering this a dismissable layer
|
|
215
215
|
*/
|
|
216
|
-
disableLayer?: boolean;
|
|
216
|
+
disableLayer?: boolean | undefined;
|
|
217
217
|
}
|
|
218
218
|
type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
|
|
219
219
|
type ComputedContext = Readonly<{
|
|
@@ -270,13 +270,13 @@ interface TriggerProps {
|
|
|
270
270
|
/**
|
|
271
271
|
* Whether the trigger is focusable
|
|
272
272
|
*/
|
|
273
|
-
focusable?: boolean;
|
|
273
|
+
focusable?: boolean | undefined;
|
|
274
274
|
}
|
|
275
275
|
interface ItemProps {
|
|
276
276
|
/**
|
|
277
277
|
* Whether hovering outside should clear the highlighted state
|
|
278
278
|
*/
|
|
279
|
-
persistFocus?: boolean;
|
|
279
|
+
persistFocus?: boolean | undefined;
|
|
280
280
|
/**
|
|
281
281
|
* The item to render
|
|
282
282
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -37,11 +37,11 @@ interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
|
|
|
37
37
|
}
|
|
38
38
|
interface ScrollToIndexDetails {
|
|
39
39
|
index: number;
|
|
40
|
-
immediate?: boolean;
|
|
40
|
+
immediate?: boolean | undefined;
|
|
41
41
|
}
|
|
42
42
|
interface IntlTranslations {
|
|
43
|
-
triggerLabel?: string;
|
|
44
|
-
clearTriggerLabel?: string;
|
|
43
|
+
triggerLabel?: string | undefined;
|
|
44
|
+
clearTriggerLabel?: string | undefined;
|
|
45
45
|
}
|
|
46
46
|
type ElementIds = Partial<{
|
|
47
47
|
root: string;
|
|
@@ -60,15 +60,15 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
60
60
|
/**
|
|
61
61
|
* Whether the combobox is open
|
|
62
62
|
*/
|
|
63
|
-
open?: boolean;
|
|
63
|
+
open?: boolean | undefined;
|
|
64
64
|
/**
|
|
65
65
|
* Whether the combobox open state is controlled by the user
|
|
66
66
|
*/
|
|
67
|
-
"open.controlled"?: boolean;
|
|
67
|
+
"open.controlled"?: boolean | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* The ids of the elements in the combobox. Useful for composition.
|
|
70
70
|
*/
|
|
71
|
-
ids?: ElementIds;
|
|
71
|
+
ids?: ElementIds | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* The current value of the combobox's input
|
|
74
74
|
*/
|
|
@@ -76,32 +76,32 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
76
76
|
/**
|
|
77
77
|
* The `name` attribute of the combobox's input. Useful for form submission
|
|
78
78
|
*/
|
|
79
|
-
name?: string;
|
|
79
|
+
name?: string | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* The associate form of the combobox.
|
|
82
82
|
*/
|
|
83
|
-
form?: string;
|
|
83
|
+
form?: string | undefined;
|
|
84
84
|
/**
|
|
85
85
|
* Whether the combobox is disabled
|
|
86
86
|
*/
|
|
87
|
-
disabled?: boolean;
|
|
87
|
+
disabled?: boolean | undefined;
|
|
88
88
|
/**
|
|
89
89
|
* Whether the combobox is readonly. This puts the combobox in a "non-editable" mode
|
|
90
90
|
* but the user can still interact with it
|
|
91
91
|
*/
|
|
92
|
-
readOnly?: boolean;
|
|
92
|
+
readOnly?: boolean | undefined;
|
|
93
93
|
/**
|
|
94
94
|
* Whether the combobox is invalid
|
|
95
95
|
*/
|
|
96
|
-
invalid?: boolean;
|
|
96
|
+
invalid?: boolean | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* Whether the combobox is required
|
|
99
99
|
*/
|
|
100
|
-
required?: boolean;
|
|
100
|
+
required?: boolean | undefined;
|
|
101
101
|
/**
|
|
102
102
|
* The placeholder text of the combobox's input
|
|
103
103
|
*/
|
|
104
|
-
placeholder?: string;
|
|
104
|
+
placeholder?: string | undefined;
|
|
105
105
|
/**
|
|
106
106
|
* The active item's id. Used to set the `aria-activedescendant` attribute
|
|
107
107
|
*/
|
|
@@ -132,26 +132,26 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
132
132
|
/**
|
|
133
133
|
* Whether to autofocus the input on mount
|
|
134
134
|
*/
|
|
135
|
-
autoFocus?: boolean;
|
|
135
|
+
autoFocus?: boolean | undefined;
|
|
136
136
|
/**
|
|
137
137
|
* Whether to open the combobox popup on initial click on the input
|
|
138
138
|
* @default false
|
|
139
139
|
*/
|
|
140
|
-
openOnClick?: boolean;
|
|
140
|
+
openOnClick?: boolean | undefined;
|
|
141
141
|
/**
|
|
142
142
|
* Whether to show the combobox when the input value changes
|
|
143
143
|
* @default true
|
|
144
144
|
*/
|
|
145
|
-
openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean);
|
|
145
|
+
openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean) | undefined;
|
|
146
146
|
/**
|
|
147
147
|
* Whether to allow typing custom values in the input
|
|
148
148
|
*/
|
|
149
|
-
allowCustomValue?: boolean;
|
|
149
|
+
allowCustomValue?: boolean | undefined;
|
|
150
150
|
/**
|
|
151
151
|
* Whether to loop the keyboard navigation through the items
|
|
152
152
|
* @default true
|
|
153
153
|
*/
|
|
154
|
-
loopFocus?: boolean;
|
|
154
|
+
loopFocus?: boolean | undefined;
|
|
155
155
|
/**
|
|
156
156
|
* The positioning options to dynamically position the menu
|
|
157
157
|
*/
|
|
@@ -159,20 +159,20 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
159
159
|
/**
|
|
160
160
|
* Function called when the input's value changes
|
|
161
161
|
*/
|
|
162
|
-
onInputValueChange?: (details: InputValueChangeDetails) => void;
|
|
162
|
+
onInputValueChange?: ((details: InputValueChangeDetails) => void) | undefined;
|
|
163
163
|
/**
|
|
164
164
|
* Function called when a new item is selected
|
|
165
165
|
*/
|
|
166
|
-
onValueChange?: (details: ValueChangeDetails<T>) => void;
|
|
166
|
+
onValueChange?: ((details: ValueChangeDetails<T>) => void) | undefined;
|
|
167
167
|
/**
|
|
168
168
|
* Function called when an item is highlighted using the pointer
|
|
169
169
|
* or keyboard navigation.
|
|
170
170
|
*/
|
|
171
|
-
onHighlightChange?: (details: HighlightChangeDetails<T>) => void;
|
|
171
|
+
onHighlightChange?: ((details: HighlightChangeDetails<T>) => void) | undefined;
|
|
172
172
|
/**
|
|
173
173
|
* Function called when the popup is opened
|
|
174
174
|
*/
|
|
175
|
-
onOpenChange?: (details: OpenChangeDetails) => void;
|
|
175
|
+
onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
|
|
176
176
|
/**
|
|
177
177
|
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
178
178
|
*/
|
|
@@ -187,15 +187,15 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
187
187
|
* **Good to know:** When `multiple` is `true`, the `selectionBehavior` is automatically set to `clear`.
|
|
188
188
|
* It is recommended to render the selected items in a separate container.
|
|
189
189
|
*/
|
|
190
|
-
multiple?: boolean;
|
|
190
|
+
multiple?: boolean | undefined;
|
|
191
191
|
/**
|
|
192
192
|
* Whether to close the combobox when an item is selected.
|
|
193
193
|
*/
|
|
194
|
-
closeOnSelect?: boolean;
|
|
194
|
+
closeOnSelect?: boolean | undefined;
|
|
195
195
|
/**
|
|
196
196
|
* Function to get the display value of the selected item
|
|
197
197
|
*/
|
|
198
|
-
getSelectionValue?: (details: SelectionValueDetails<T>) => string;
|
|
198
|
+
getSelectionValue?: ((details: SelectionValueDetails<T>) => string) | undefined;
|
|
199
199
|
/**
|
|
200
200
|
* Whether to open the combobox on arrow key press
|
|
201
201
|
* @default true
|
|
@@ -204,7 +204,7 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
204
204
|
/**
|
|
205
205
|
* Function to scroll to a specific index
|
|
206
206
|
*/
|
|
207
|
-
scrollToIndexFn?: (details: ScrollToIndexDetails) => void;
|
|
207
|
+
scrollToIndexFn?: ((details: ScrollToIndexDetails) => void) | undefined;
|
|
208
208
|
/**
|
|
209
209
|
* Whether the combobox is a composed with other composite widgets like tabs
|
|
210
210
|
* @default true
|
|
@@ -213,7 +213,7 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
|
|
|
213
213
|
/**
|
|
214
214
|
* Whether to disable registering this a dismissable layer
|
|
215
215
|
*/
|
|
216
|
-
disableLayer?: boolean;
|
|
216
|
+
disableLayer?: boolean | undefined;
|
|
217
217
|
}
|
|
218
218
|
type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
|
|
219
219
|
type ComputedContext = Readonly<{
|
|
@@ -270,13 +270,13 @@ interface TriggerProps {
|
|
|
270
270
|
/**
|
|
271
271
|
* Whether the trigger is focusable
|
|
272
272
|
*/
|
|
273
|
-
focusable?: boolean;
|
|
273
|
+
focusable?: boolean | undefined;
|
|
274
274
|
}
|
|
275
275
|
interface ItemProps {
|
|
276
276
|
/**
|
|
277
277
|
* Whether hovering outside should clear the highlighted state
|
|
278
278
|
*/
|
|
279
|
-
persistFocus?: boolean;
|
|
279
|
+
persistFocus?: boolean | undefined;
|
|
280
280
|
/**
|
|
281
281
|
* The item to render
|
|
282
282
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1143,15 +1143,18 @@ function machine(userContext) {
|
|
|
1143
1143
|
},
|
|
1144
1144
|
selectHighlightedItem(ctx2) {
|
|
1145
1145
|
set.value(ctx2, ctx2.highlightedValue);
|
|
1146
|
+
set.inputValue(ctx2, getInputValue(ctx2, true));
|
|
1146
1147
|
},
|
|
1147
1148
|
selectItem(ctx2, evt) {
|
|
1148
1149
|
if (evt.value == null) return;
|
|
1149
1150
|
set.value(ctx2, evt.value);
|
|
1151
|
+
set.inputValue(ctx2, getInputValue(ctx2, true));
|
|
1150
1152
|
},
|
|
1151
1153
|
clearItem(ctx2, evt) {
|
|
1152
1154
|
if (evt.value == null) return;
|
|
1153
1155
|
const value = ctx2.value.filter((v) => v !== evt.value);
|
|
1154
1156
|
set.value(ctx2, value);
|
|
1157
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1155
1158
|
},
|
|
1156
1159
|
setInitialFocus(ctx2) {
|
|
1157
1160
|
domQuery.raf(() => {
|
|
@@ -1214,9 +1217,11 @@ function machine(userContext) {
|
|
|
1214
1217
|
setSelectedItems(ctx2, evt) {
|
|
1215
1218
|
if (!utils.isArray(evt.value)) return;
|
|
1216
1219
|
set.value(ctx2, evt.value);
|
|
1220
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1217
1221
|
},
|
|
1218
1222
|
clearSelectedItems(ctx2) {
|
|
1219
1223
|
set.value(ctx2, []);
|
|
1224
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1220
1225
|
},
|
|
1221
1226
|
scrollContentToTop(ctx2) {
|
|
1222
1227
|
if (ctx2.scrollToIndexFn) {
|
|
@@ -1313,6 +1318,7 @@ function machine(userContext) {
|
|
|
1313
1318
|
},
|
|
1314
1319
|
syncSelectedItems(ctx2) {
|
|
1315
1320
|
sync.valueChange(ctx2);
|
|
1321
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1316
1322
|
},
|
|
1317
1323
|
syncHighlightedItem(ctx2) {
|
|
1318
1324
|
sync.highlightChange(ctx2);
|
|
@@ -1324,6 +1330,20 @@ function machine(userContext) {
|
|
|
1324
1330
|
}
|
|
1325
1331
|
);
|
|
1326
1332
|
}
|
|
1333
|
+
function getInputValue(ctx, selection) {
|
|
1334
|
+
if (ctx.getSelectionValue && selection) {
|
|
1335
|
+
return ctx.getSelectionValue({
|
|
1336
|
+
inputValue: ctx.inputValue,
|
|
1337
|
+
selectedItems: Array.from(ctx.selectedItems),
|
|
1338
|
+
valueAsString: ctx.valueAsString
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
return utils.match(ctx.selectionBehavior, {
|
|
1342
|
+
preserve: ctx.inputValue,
|
|
1343
|
+
replace: ctx.valueAsString,
|
|
1344
|
+
clear: ""
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1327
1347
|
var sync = {
|
|
1328
1348
|
valueChange: (ctx) => {
|
|
1329
1349
|
const prevSelectedItems = ctx.selectedItems;
|
|
@@ -1332,23 +1352,7 @@ var sync = {
|
|
|
1332
1352
|
if (foundItem) return foundItem;
|
|
1333
1353
|
return ctx.collection.find(v);
|
|
1334
1354
|
});
|
|
1335
|
-
|
|
1336
|
-
ctx.valueAsString = valueAsString;
|
|
1337
|
-
let inputValue;
|
|
1338
|
-
if (ctx.getSelectionValue) {
|
|
1339
|
-
inputValue = ctx.getSelectionValue({
|
|
1340
|
-
inputValue: ctx.inputValue,
|
|
1341
|
-
selectedItems: Array.from(ctx.selectedItems),
|
|
1342
|
-
valueAsString
|
|
1343
|
-
});
|
|
1344
|
-
} else {
|
|
1345
|
-
inputValue = utils.match(ctx.selectionBehavior, {
|
|
1346
|
-
replace: ctx.valueAsString,
|
|
1347
|
-
preserve: ctx.inputValue,
|
|
1348
|
-
clear: ""
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
set.inputValue(ctx, inputValue);
|
|
1355
|
+
ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
|
|
1352
1356
|
},
|
|
1353
1357
|
highlightChange: (ctx) => {
|
|
1354
1358
|
ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue);
|
package/dist/index.mjs
CHANGED
|
@@ -1141,15 +1141,18 @@ function machine(userContext) {
|
|
|
1141
1141
|
},
|
|
1142
1142
|
selectHighlightedItem(ctx2) {
|
|
1143
1143
|
set.value(ctx2, ctx2.highlightedValue);
|
|
1144
|
+
set.inputValue(ctx2, getInputValue(ctx2, true));
|
|
1144
1145
|
},
|
|
1145
1146
|
selectItem(ctx2, evt) {
|
|
1146
1147
|
if (evt.value == null) return;
|
|
1147
1148
|
set.value(ctx2, evt.value);
|
|
1149
|
+
set.inputValue(ctx2, getInputValue(ctx2, true));
|
|
1148
1150
|
},
|
|
1149
1151
|
clearItem(ctx2, evt) {
|
|
1150
1152
|
if (evt.value == null) return;
|
|
1151
1153
|
const value = ctx2.value.filter((v) => v !== evt.value);
|
|
1152
1154
|
set.value(ctx2, value);
|
|
1155
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1153
1156
|
},
|
|
1154
1157
|
setInitialFocus(ctx2) {
|
|
1155
1158
|
raf(() => {
|
|
@@ -1212,9 +1215,11 @@ function machine(userContext) {
|
|
|
1212
1215
|
setSelectedItems(ctx2, evt) {
|
|
1213
1216
|
if (!isArray(evt.value)) return;
|
|
1214
1217
|
set.value(ctx2, evt.value);
|
|
1218
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1215
1219
|
},
|
|
1216
1220
|
clearSelectedItems(ctx2) {
|
|
1217
1221
|
set.value(ctx2, []);
|
|
1222
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1218
1223
|
},
|
|
1219
1224
|
scrollContentToTop(ctx2) {
|
|
1220
1225
|
if (ctx2.scrollToIndexFn) {
|
|
@@ -1311,6 +1316,7 @@ function machine(userContext) {
|
|
|
1311
1316
|
},
|
|
1312
1317
|
syncSelectedItems(ctx2) {
|
|
1313
1318
|
sync.valueChange(ctx2);
|
|
1319
|
+
set.inputValue(ctx2, getInputValue(ctx2));
|
|
1314
1320
|
},
|
|
1315
1321
|
syncHighlightedItem(ctx2) {
|
|
1316
1322
|
sync.highlightChange(ctx2);
|
|
@@ -1322,6 +1328,20 @@ function machine(userContext) {
|
|
|
1322
1328
|
}
|
|
1323
1329
|
);
|
|
1324
1330
|
}
|
|
1331
|
+
function getInputValue(ctx, selection) {
|
|
1332
|
+
if (ctx.getSelectionValue && selection) {
|
|
1333
|
+
return ctx.getSelectionValue({
|
|
1334
|
+
inputValue: ctx.inputValue,
|
|
1335
|
+
selectedItems: Array.from(ctx.selectedItems),
|
|
1336
|
+
valueAsString: ctx.valueAsString
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
return match(ctx.selectionBehavior, {
|
|
1340
|
+
preserve: ctx.inputValue,
|
|
1341
|
+
replace: ctx.valueAsString,
|
|
1342
|
+
clear: ""
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1325
1345
|
var sync = {
|
|
1326
1346
|
valueChange: (ctx) => {
|
|
1327
1347
|
const prevSelectedItems = ctx.selectedItems;
|
|
@@ -1330,23 +1350,7 @@ var sync = {
|
|
|
1330
1350
|
if (foundItem) return foundItem;
|
|
1331
1351
|
return ctx.collection.find(v);
|
|
1332
1352
|
});
|
|
1333
|
-
|
|
1334
|
-
ctx.valueAsString = valueAsString;
|
|
1335
|
-
let inputValue;
|
|
1336
|
-
if (ctx.getSelectionValue) {
|
|
1337
|
-
inputValue = ctx.getSelectionValue({
|
|
1338
|
-
inputValue: ctx.inputValue,
|
|
1339
|
-
selectedItems: Array.from(ctx.selectedItems),
|
|
1340
|
-
valueAsString
|
|
1341
|
-
});
|
|
1342
|
-
} else {
|
|
1343
|
-
inputValue = match(ctx.selectionBehavior, {
|
|
1344
|
-
replace: ctx.valueAsString,
|
|
1345
|
-
preserve: ctx.inputValue,
|
|
1346
|
-
clear: ""
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
|
-
set.inputValue(ctx, inputValue);
|
|
1353
|
+
ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
|
|
1350
1354
|
},
|
|
1351
1355
|
highlightChange: (ctx) => {
|
|
1352
1356
|
ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/combobox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.0",
|
|
4
4
|
"description": "Core logic for the combobox widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/anatomy": "0.
|
|
30
|
-
"@zag-js/aria-hidden": "0.
|
|
31
|
-
"@zag-js/collection": "0.
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/dismissable": "0.
|
|
34
|
-
"@zag-js/dom-query": "0.
|
|
35
|
-
"@zag-js/dom-event": "0.
|
|
36
|
-
"@zag-js/utils": "0.
|
|
37
|
-
"@zag-js/popper": "0.
|
|
38
|
-
"@zag-js/types": "0.
|
|
29
|
+
"@zag-js/anatomy": "0.76.0",
|
|
30
|
+
"@zag-js/aria-hidden": "0.76.0",
|
|
31
|
+
"@zag-js/collection": "0.76.0",
|
|
32
|
+
"@zag-js/core": "0.76.0",
|
|
33
|
+
"@zag-js/dismissable": "0.76.0",
|
|
34
|
+
"@zag-js/dom-query": "0.76.0",
|
|
35
|
+
"@zag-js/dom-event": "0.76.0",
|
|
36
|
+
"@zag-js/utils": "0.76.0",
|
|
37
|
+
"@zag-js/popper": "0.76.0",
|
|
38
|
+
"@zag-js/types": "0.76.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"clean-package": "2.2.0"
|