@zag-js/combobox 0.47.0 → 0.48.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 +86 -31
- package/dist/index.d.ts +86 -31
- package/dist/index.js +627 -276
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +637 -280
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/src/combobox.connect.ts +158 -108
- package/src/combobox.dom.ts +2 -0
- package/src/combobox.machine.ts +480 -174
- package/src/combobox.props.ts +11 -4
- package/src/combobox.types.ts +91 -39
- package/src/index.ts +2 -0
package/src/combobox.props.ts
CHANGED
|
@@ -6,18 +6,20 @@ export const props = createProps<UserDefinedContext>()([
|
|
|
6
6
|
"allowCustomValue",
|
|
7
7
|
"autoFocus",
|
|
8
8
|
"closeOnSelect",
|
|
9
|
+
"collection",
|
|
9
10
|
"dir",
|
|
10
11
|
"disabled",
|
|
12
|
+
"dismissable",
|
|
11
13
|
"form",
|
|
12
14
|
"getRootNode",
|
|
15
|
+
"getSelectionValue",
|
|
13
16
|
"highlightedValue",
|
|
14
17
|
"id",
|
|
15
18
|
"ids",
|
|
16
19
|
"inputBehavior",
|
|
17
|
-
"collection",
|
|
18
20
|
"inputValue",
|
|
19
21
|
"invalid",
|
|
20
|
-
"
|
|
22
|
+
"loopFocus",
|
|
21
23
|
"multiple",
|
|
22
24
|
"name",
|
|
23
25
|
"onFocusOutside",
|
|
@@ -28,13 +30,18 @@ export const props = createProps<UserDefinedContext>()([
|
|
|
28
30
|
"onOpenChange",
|
|
29
31
|
"onPointerDownOutside",
|
|
30
32
|
"onValueChange",
|
|
33
|
+
"open.controlled",
|
|
34
|
+
"open",
|
|
31
35
|
"openOnClick",
|
|
36
|
+
"openOnChange",
|
|
37
|
+
"openOnKeyPress",
|
|
32
38
|
"placeholder",
|
|
33
39
|
"positioning",
|
|
34
40
|
"readOnly",
|
|
41
|
+
"scrollToIndexFn",
|
|
35
42
|
"selectionBehavior",
|
|
36
|
-
"selectOnBlur",
|
|
37
43
|
"translations",
|
|
44
|
+
"popup",
|
|
38
45
|
"value",
|
|
39
46
|
])
|
|
40
47
|
export const splitProps = createSplitProps<Partial<UserDefinedContext>>(props)
|
|
@@ -45,5 +52,5 @@ export const splitItemGroupLabelProps = createSplitProps<ItemGroupLabelProps>(it
|
|
|
45
52
|
export const itemGroupProps = createProps<ItemGroupProps>()(["id"])
|
|
46
53
|
export const splitItemGroupProps = createSplitProps<ItemGroupProps>(itemGroupProps)
|
|
47
54
|
|
|
48
|
-
export const itemProps = createProps<ItemProps>()(["item"])
|
|
55
|
+
export const itemProps = createProps<ItemProps>()(["item", "persistFocus"])
|
|
49
56
|
export const splitItemProps = createSplitProps<ItemProps>(itemProps)
|
package/src/combobox.types.ts
CHANGED
|
@@ -19,13 +19,24 @@ export interface HighlightChangeDetails<T extends CollectionItem = CollectionIte
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface InputValueChangeDetails {
|
|
22
|
-
|
|
22
|
+
inputValue: string
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface OpenChangeDetails {
|
|
26
26
|
open: boolean
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
|
|
30
|
+
inputValue: string
|
|
31
|
+
selectedItems: T[]
|
|
32
|
+
valueAsString: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ScrollToIndexDetails {
|
|
36
|
+
index: number
|
|
37
|
+
immediate?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/* -----------------------------------------------------------------------------
|
|
30
41
|
* Machine context
|
|
31
42
|
* -----------------------------------------------------------------------------*/
|
|
@@ -53,6 +64,14 @@ interface PublicContext<T extends CollectionItem = CollectionItem>
|
|
|
53
64
|
extends DirectionProperty,
|
|
54
65
|
CommonProperties,
|
|
55
66
|
InteractOutsideHandlers {
|
|
67
|
+
/**
|
|
68
|
+
* Whether the combobox is open
|
|
69
|
+
*/
|
|
70
|
+
open?: boolean
|
|
71
|
+
/**
|
|
72
|
+
* Whether the combobox open state is controlled by the user
|
|
73
|
+
*/
|
|
74
|
+
"open.controlled"?: boolean
|
|
56
75
|
/**
|
|
57
76
|
* The ids of the elements in the combobox. Useful for composition.
|
|
58
77
|
*/
|
|
@@ -109,10 +128,6 @@ interface PublicContext<T extends CollectionItem = CollectionItem>
|
|
|
109
128
|
* - `preserve`: The input value is preserved
|
|
110
129
|
*/
|
|
111
130
|
selectionBehavior: "clear" | "replace" | "preserve"
|
|
112
|
-
/**
|
|
113
|
-
* Whether to select the higlighted item on interaction outside the combobox
|
|
114
|
-
*/
|
|
115
|
-
selectOnBlur: boolean
|
|
116
131
|
/**
|
|
117
132
|
* Whether to autofocus the input on mount
|
|
118
133
|
*/
|
|
@@ -122,13 +137,17 @@ interface PublicContext<T extends CollectionItem = CollectionItem>
|
|
|
122
137
|
*/
|
|
123
138
|
openOnClick?: boolean
|
|
124
139
|
/**
|
|
125
|
-
* Whether to
|
|
140
|
+
* Whether to show the combobox when the input value changes
|
|
141
|
+
*/
|
|
142
|
+
openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean)
|
|
143
|
+
/**
|
|
144
|
+
* Whether to allow typing custom values in the input
|
|
126
145
|
*/
|
|
127
146
|
allowCustomValue?: boolean
|
|
128
147
|
/**
|
|
129
148
|
* Whether to loop the keyboard navigation through the items
|
|
130
149
|
*/
|
|
131
|
-
|
|
150
|
+
loopFocus?: boolean
|
|
132
151
|
/**
|
|
133
152
|
* The positioning options to dynamically position the menu
|
|
134
153
|
*/
|
|
@@ -166,6 +185,28 @@ interface PublicContext<T extends CollectionItem = CollectionItem>
|
|
|
166
185
|
* Whether to close the combobox when an item is selected.
|
|
167
186
|
*/
|
|
168
187
|
closeOnSelect?: boolean
|
|
188
|
+
/**
|
|
189
|
+
* Function to get the display value of the selected item
|
|
190
|
+
*/
|
|
191
|
+
getSelectionValue?: (details: SelectionValueDetails<T>) => string
|
|
192
|
+
/**
|
|
193
|
+
* Whether to open the combobox on arrow key press
|
|
194
|
+
*/
|
|
195
|
+
openOnKeyPress: boolean
|
|
196
|
+
/**
|
|
197
|
+
* Function to scroll to a specific index
|
|
198
|
+
*/
|
|
199
|
+
scrollToIndexFn?: (details: ScrollToIndexDetails) => void
|
|
200
|
+
/**
|
|
201
|
+
* The underling `aria-haspopup` attribute to use for the combobox
|
|
202
|
+
* - `listbox`: The combobox has a listbox popup (default)
|
|
203
|
+
* - `dialog`: The combobox has a dialog popup. Useful when in select only mode
|
|
204
|
+
*/
|
|
205
|
+
popup: "listbox" | "dialog"
|
|
206
|
+
/**
|
|
207
|
+
* Whether to register this combobox as a dismissable layer
|
|
208
|
+
*/
|
|
209
|
+
dismissable: boolean
|
|
169
210
|
}
|
|
170
211
|
|
|
171
212
|
export type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<
|
|
@@ -173,7 +214,7 @@ export type UserDefinedContext<T extends CollectionItem = CollectionItem> = Requ
|
|
|
173
214
|
"id" | "collection"
|
|
174
215
|
>
|
|
175
216
|
|
|
176
|
-
type ComputedContext
|
|
217
|
+
type ComputedContext = Readonly<{
|
|
177
218
|
/**
|
|
178
219
|
* @computed
|
|
179
220
|
* Whether the input's value is empty
|
|
@@ -192,38 +233,33 @@ type ComputedContext<T extends CollectionItem = CollectionItem> = Readonly<{
|
|
|
192
233
|
* @computed
|
|
193
234
|
*/
|
|
194
235
|
autoHighlight: boolean
|
|
195
|
-
/**
|
|
196
|
-
* The highlighted item
|
|
197
|
-
*/
|
|
198
|
-
highlightedItem: T | null
|
|
199
|
-
/**
|
|
200
|
-
* @computed
|
|
201
|
-
* The selected items
|
|
202
|
-
*/
|
|
203
|
-
selectedItems: T[]
|
|
204
236
|
/**
|
|
205
237
|
* @computed
|
|
206
238
|
* Whether there's a selected option
|
|
207
239
|
*/
|
|
208
240
|
hasSelectedItems: boolean
|
|
209
|
-
/**
|
|
210
|
-
* @computed
|
|
211
|
-
* The display value of the combobox (based on the selected items)
|
|
212
|
-
*/
|
|
213
|
-
valueAsString: string
|
|
214
241
|
}>
|
|
215
242
|
|
|
216
|
-
interface PrivateContext {
|
|
243
|
+
interface PrivateContext<T extends CollectionItem = CollectionItem> {
|
|
217
244
|
/**
|
|
218
245
|
* @internal
|
|
219
246
|
* The placement of the combobox popover.
|
|
220
247
|
*/
|
|
221
248
|
currentPlacement?: Placement
|
|
222
249
|
/**
|
|
223
|
-
*
|
|
224
|
-
|
|
250
|
+
* The highlighted item
|
|
251
|
+
*/
|
|
252
|
+
highlightedItem: T | null
|
|
253
|
+
/**
|
|
254
|
+
* @interal
|
|
255
|
+
* The selected items
|
|
256
|
+
*/
|
|
257
|
+
selectedItems: T[]
|
|
258
|
+
/**
|
|
259
|
+
* @interal
|
|
260
|
+
* The display value of the combobox (based on the selected items)
|
|
225
261
|
*/
|
|
226
|
-
|
|
262
|
+
valueAsString: string
|
|
227
263
|
}
|
|
228
264
|
|
|
229
265
|
export interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
|
|
@@ -242,14 +278,33 @@ export type Send = S.Send<S.AnyEventObject>
|
|
|
242
278
|
* -----------------------------------------------------------------------------*/
|
|
243
279
|
|
|
244
280
|
export interface ItemProps {
|
|
281
|
+
/**
|
|
282
|
+
* Whether hovering outside should clear the highlighted state
|
|
283
|
+
*/
|
|
284
|
+
persistFocus?: boolean
|
|
285
|
+
/**
|
|
286
|
+
* The item to render
|
|
287
|
+
*/
|
|
245
288
|
item: CollectionItem
|
|
246
289
|
}
|
|
247
290
|
|
|
248
291
|
export interface ItemState {
|
|
292
|
+
/**
|
|
293
|
+
* The value of the item
|
|
294
|
+
*/
|
|
249
295
|
value: string
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
296
|
+
/**
|
|
297
|
+
* Whether the item is disabled
|
|
298
|
+
*/
|
|
299
|
+
disabled: boolean
|
|
300
|
+
/**
|
|
301
|
+
* Whether the item is selected
|
|
302
|
+
*/
|
|
303
|
+
selected: boolean
|
|
304
|
+
/**
|
|
305
|
+
* Whether the item is highlighted via pointer or keyboard navigation
|
|
306
|
+
*/
|
|
307
|
+
highlighted: boolean
|
|
253
308
|
}
|
|
254
309
|
|
|
255
310
|
export interface ItemGroupProps {
|
|
@@ -264,15 +319,15 @@ export interface MachineApi<T extends PropTypes = PropTypes, V extends Collectio
|
|
|
264
319
|
/**
|
|
265
320
|
* Whether the combobox is focused
|
|
266
321
|
*/
|
|
267
|
-
|
|
322
|
+
focused: boolean
|
|
268
323
|
/**
|
|
269
324
|
* Whether the combobox is open
|
|
270
325
|
*/
|
|
271
|
-
|
|
326
|
+
open: boolean
|
|
272
327
|
/**
|
|
273
328
|
* Whether the combobox input value is empty
|
|
274
329
|
*/
|
|
275
|
-
|
|
330
|
+
inputEmpty: boolean
|
|
276
331
|
/**
|
|
277
332
|
* The value of the combobox input
|
|
278
333
|
*/
|
|
@@ -330,13 +385,9 @@ export interface MachineApi<T extends PropTypes = PropTypes, V extends Collectio
|
|
|
330
385
|
*/
|
|
331
386
|
getItemState(props: ItemProps): ItemState
|
|
332
387
|
/**
|
|
333
|
-
* Function to open the combobox
|
|
334
|
-
*/
|
|
335
|
-
open(): void
|
|
336
|
-
/**
|
|
337
|
-
* Function to close the combobox
|
|
388
|
+
* Function to open or close the combobox
|
|
338
389
|
*/
|
|
339
|
-
|
|
390
|
+
setOpen(open: boolean): void
|
|
340
391
|
/**
|
|
341
392
|
* Function to toggle the combobox
|
|
342
393
|
*/
|
|
@@ -348,7 +399,7 @@ export interface MachineApi<T extends PropTypes = PropTypes, V extends Collectio
|
|
|
348
399
|
/**
|
|
349
400
|
* Function to set the positioning options
|
|
350
401
|
*/
|
|
351
|
-
reposition(options
|
|
402
|
+
reposition(options?: Partial<PositioningOptions>): void
|
|
352
403
|
|
|
353
404
|
rootProps: T["element"]
|
|
354
405
|
labelProps: T["label"]
|
|
@@ -358,6 +409,7 @@ export interface MachineApi<T extends PropTypes = PropTypes, V extends Collectio
|
|
|
358
409
|
contentProps: T["element"]
|
|
359
410
|
triggerProps: T["button"]
|
|
360
411
|
clearTriggerProps: T["button"]
|
|
412
|
+
listProps: T["element"]
|
|
361
413
|
getItemProps(props: ItemProps): T["element"]
|
|
362
414
|
getItemTextProps(props: ItemProps): T["element"]
|
|
363
415
|
getItemIndicatorProps(props: ItemProps): T["element"]
|