@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 CHANGED
@@ -24,11 +24,20 @@ interface HighlightChangeDetails<T extends CollectionItem = CollectionItem> {
24
24
  highligtedItem: T | null;
25
25
  }
26
26
  interface InputValueChangeDetails {
27
- value: string;
27
+ inputValue: string;
28
28
  }
29
29
  interface OpenChangeDetails {
30
30
  open: boolean;
31
31
  }
32
+ interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
33
+ inputValue: string;
34
+ selectedItems: T[];
35
+ valueAsString: string;
36
+ }
37
+ interface ScrollToIndexDetails {
38
+ index: number;
39
+ immediate?: boolean;
40
+ }
32
41
  interface IntlTranslations {
33
42
  triggerLabel?: string;
34
43
  clearTriggerLabel?: string;
@@ -47,6 +56,14 @@ type ElementIds = Partial<{
47
56
  itemGroupLabel(id: string | number): string;
48
57
  }>;
49
58
  interface PublicContext<T extends CollectionItem = CollectionItem> extends DirectionProperty, CommonProperties, InteractOutsideHandlers {
59
+ /**
60
+ * Whether the combobox is open
61
+ */
62
+ open?: boolean;
63
+ /**
64
+ * Whether the combobox open state is controlled by the user
65
+ */
66
+ "open.controlled"?: boolean;
50
67
  /**
51
68
  * The ids of the elements in the combobox. Useful for composition.
52
69
  */
@@ -103,10 +120,6 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
103
120
  * - `preserve`: The input value is preserved
104
121
  */
105
122
  selectionBehavior: "clear" | "replace" | "preserve";
106
- /**
107
- * Whether to select the higlighted item on interaction outside the combobox
108
- */
109
- selectOnBlur: boolean;
110
123
  /**
111
124
  * Whether to autofocus the input on mount
112
125
  */
@@ -116,13 +129,17 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
116
129
  */
117
130
  openOnClick?: boolean;
118
131
  /**
119
- * Whether to allow custom values or free values in the input
132
+ * Whether to show the combobox when the input value changes
133
+ */
134
+ openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean);
135
+ /**
136
+ * Whether to allow typing custom values in the input
120
137
  */
121
138
  allowCustomValue?: boolean;
122
139
  /**
123
140
  * Whether to loop the keyboard navigation through the items
124
141
  */
125
- loop?: boolean;
142
+ loopFocus?: boolean;
126
143
  /**
127
144
  * The positioning options to dynamically position the menu
128
145
  */
@@ -160,9 +177,31 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
160
177
  * Whether to close the combobox when an item is selected.
161
178
  */
162
179
  closeOnSelect?: boolean;
180
+ /**
181
+ * Function to get the display value of the selected item
182
+ */
183
+ getSelectionValue?: (details: SelectionValueDetails<T>) => string;
184
+ /**
185
+ * Whether to open the combobox on arrow key press
186
+ */
187
+ openOnKeyPress: boolean;
188
+ /**
189
+ * Function to scroll to a specific index
190
+ */
191
+ scrollToIndexFn?: (details: ScrollToIndexDetails) => void;
192
+ /**
193
+ * The underling `aria-haspopup` attribute to use for the combobox
194
+ * - `listbox`: The combobox has a listbox popup (default)
195
+ * - `dialog`: The combobox has a dialog popup. Useful when in select only mode
196
+ */
197
+ popup: "listbox" | "dialog";
198
+ /**
199
+ * Whether to register this combobox as a dismissable layer
200
+ */
201
+ dismissable: boolean;
163
202
  }
164
203
  type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
165
- type ComputedContext<T extends CollectionItem = CollectionItem> = Readonly<{
204
+ type ComputedContext = Readonly<{
166
205
  /**
167
206
  * @computed
168
207
  * Whether the input's value is empty
@@ -181,27 +220,27 @@ type ComputedContext<T extends CollectionItem = CollectionItem> = Readonly<{
181
220
  * @computed
182
221
  */
183
222
  autoHighlight: boolean;
223
+ /**
224
+ * @computed
225
+ * Whether there's a selected option
226
+ */
227
+ hasSelectedItems: boolean;
228
+ }>;
229
+ interface PrivateContext<T extends CollectionItem = CollectionItem> {
184
230
  /**
185
231
  * The highlighted item
186
232
  */
187
233
  highlightedItem: T | null;
188
234
  /**
189
- * @computed
235
+ * @interal
190
236
  * The selected items
191
237
  */
192
238
  selectedItems: T[];
193
239
  /**
194
- * @computed
195
- * Whether there's a selected option
196
- */
197
- hasSelectedItems: boolean;
198
- /**
199
- * @computed
240
+ * @interal
200
241
  * The display value of the combobox (based on the selected items)
201
242
  */
202
243
  valueAsString: string;
203
- }>;
204
- interface PrivateContext {
205
244
  }
206
245
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
207
246
  }
@@ -212,13 +251,32 @@ interface MachineState {
212
251
  type State = StateMachine.State<MachineContext, MachineState>;
213
252
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
214
253
  interface ItemProps {
254
+ /**
255
+ * Whether hovering outside should clear the highlighted state
256
+ */
257
+ persistFocus?: boolean;
258
+ /**
259
+ * The item to render
260
+ */
215
261
  item: CollectionItem;
216
262
  }
217
263
  interface ItemState {
264
+ /**
265
+ * The value of the item
266
+ */
218
267
  value: string;
219
- isDisabled: boolean;
220
- isSelected: boolean;
221
- isHighlighted: boolean;
268
+ /**
269
+ * Whether the item is disabled
270
+ */
271
+ disabled: boolean;
272
+ /**
273
+ * Whether the item is selected
274
+ */
275
+ selected: boolean;
276
+ /**
277
+ * Whether the item is highlighted via pointer or keyboard navigation
278
+ */
279
+ highlighted: boolean;
222
280
  }
223
281
  interface ItemGroupProps {
224
282
  id: string;
@@ -230,15 +288,15 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
230
288
  /**
231
289
  * Whether the combobox is focused
232
290
  */
233
- isFocused: boolean;
291
+ focused: boolean;
234
292
  /**
235
293
  * Whether the combobox is open
236
294
  */
237
- isOpen: boolean;
295
+ open: boolean;
238
296
  /**
239
297
  * Whether the combobox input value is empty
240
298
  */
241
- isInputValueEmpty: boolean;
299
+ inputEmpty: boolean;
242
300
  /**
243
301
  * The value of the combobox input
244
302
  */
@@ -296,13 +354,9 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
296
354
  */
297
355
  getItemState(props: ItemProps): ItemState;
298
356
  /**
299
- * Function to open the combobox
300
- */
301
- open(): void;
302
- /**
303
- * Function to close the combobox
357
+ * Function to open or close the combobox
304
358
  */
305
- close(): void;
359
+ setOpen(open: boolean): void;
306
360
  /**
307
361
  * Function to toggle the combobox
308
362
  */
@@ -314,7 +368,7 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
314
368
  /**
315
369
  * Function to set the positioning options
316
370
  */
317
- reposition(options: Partial<PositioningOptions>): void;
371
+ reposition(options?: Partial<PositioningOptions>): void;
318
372
  rootProps: T["element"];
319
373
  labelProps: T["label"];
320
374
  controlProps: T["element"];
@@ -323,6 +377,7 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
323
377
  contentProps: T["element"];
324
378
  triggerProps: T["button"];
325
379
  clearTriggerProps: T["button"];
380
+ listProps: T["element"];
326
381
  getItemProps(props: ItemProps): T["element"];
327
382
  getItemTextProps(props: ItemProps): T["element"];
328
383
  getItemIndicatorProps(props: ItemProps): T["element"];
@@ -334,4 +389,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
334
389
 
335
390
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
336
391
 
337
- export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type OpenChangeDetails, type ValueChangeDetails, anatomy, collection, connect, machine };
392
+ export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type OpenChangeDetails, type ScrollToIndexDetails, type SelectionValueDetails, type ValueChangeDetails, anatomy, collection, connect, machine };
package/dist/index.d.ts CHANGED
@@ -24,11 +24,20 @@ interface HighlightChangeDetails<T extends CollectionItem = CollectionItem> {
24
24
  highligtedItem: T | null;
25
25
  }
26
26
  interface InputValueChangeDetails {
27
- value: string;
27
+ inputValue: string;
28
28
  }
29
29
  interface OpenChangeDetails {
30
30
  open: boolean;
31
31
  }
32
+ interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
33
+ inputValue: string;
34
+ selectedItems: T[];
35
+ valueAsString: string;
36
+ }
37
+ interface ScrollToIndexDetails {
38
+ index: number;
39
+ immediate?: boolean;
40
+ }
32
41
  interface IntlTranslations {
33
42
  triggerLabel?: string;
34
43
  clearTriggerLabel?: string;
@@ -47,6 +56,14 @@ type ElementIds = Partial<{
47
56
  itemGroupLabel(id: string | number): string;
48
57
  }>;
49
58
  interface PublicContext<T extends CollectionItem = CollectionItem> extends DirectionProperty, CommonProperties, InteractOutsideHandlers {
59
+ /**
60
+ * Whether the combobox is open
61
+ */
62
+ open?: boolean;
63
+ /**
64
+ * Whether the combobox open state is controlled by the user
65
+ */
66
+ "open.controlled"?: boolean;
50
67
  /**
51
68
  * The ids of the elements in the combobox. Useful for composition.
52
69
  */
@@ -103,10 +120,6 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
103
120
  * - `preserve`: The input value is preserved
104
121
  */
105
122
  selectionBehavior: "clear" | "replace" | "preserve";
106
- /**
107
- * Whether to select the higlighted item on interaction outside the combobox
108
- */
109
- selectOnBlur: boolean;
110
123
  /**
111
124
  * Whether to autofocus the input on mount
112
125
  */
@@ -116,13 +129,17 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
116
129
  */
117
130
  openOnClick?: boolean;
118
131
  /**
119
- * Whether to allow custom values or free values in the input
132
+ * Whether to show the combobox when the input value changes
133
+ */
134
+ openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean);
135
+ /**
136
+ * Whether to allow typing custom values in the input
120
137
  */
121
138
  allowCustomValue?: boolean;
122
139
  /**
123
140
  * Whether to loop the keyboard navigation through the items
124
141
  */
125
- loop?: boolean;
142
+ loopFocus?: boolean;
126
143
  /**
127
144
  * The positioning options to dynamically position the menu
128
145
  */
@@ -160,9 +177,31 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
160
177
  * Whether to close the combobox when an item is selected.
161
178
  */
162
179
  closeOnSelect?: boolean;
180
+ /**
181
+ * Function to get the display value of the selected item
182
+ */
183
+ getSelectionValue?: (details: SelectionValueDetails<T>) => string;
184
+ /**
185
+ * Whether to open the combobox on arrow key press
186
+ */
187
+ openOnKeyPress: boolean;
188
+ /**
189
+ * Function to scroll to a specific index
190
+ */
191
+ scrollToIndexFn?: (details: ScrollToIndexDetails) => void;
192
+ /**
193
+ * The underling `aria-haspopup` attribute to use for the combobox
194
+ * - `listbox`: The combobox has a listbox popup (default)
195
+ * - `dialog`: The combobox has a dialog popup. Useful when in select only mode
196
+ */
197
+ popup: "listbox" | "dialog";
198
+ /**
199
+ * Whether to register this combobox as a dismissable layer
200
+ */
201
+ dismissable: boolean;
163
202
  }
164
203
  type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
165
- type ComputedContext<T extends CollectionItem = CollectionItem> = Readonly<{
204
+ type ComputedContext = Readonly<{
166
205
  /**
167
206
  * @computed
168
207
  * Whether the input's value is empty
@@ -181,27 +220,27 @@ type ComputedContext<T extends CollectionItem = CollectionItem> = Readonly<{
181
220
  * @computed
182
221
  */
183
222
  autoHighlight: boolean;
223
+ /**
224
+ * @computed
225
+ * Whether there's a selected option
226
+ */
227
+ hasSelectedItems: boolean;
228
+ }>;
229
+ interface PrivateContext<T extends CollectionItem = CollectionItem> {
184
230
  /**
185
231
  * The highlighted item
186
232
  */
187
233
  highlightedItem: T | null;
188
234
  /**
189
- * @computed
235
+ * @interal
190
236
  * The selected items
191
237
  */
192
238
  selectedItems: T[];
193
239
  /**
194
- * @computed
195
- * Whether there's a selected option
196
- */
197
- hasSelectedItems: boolean;
198
- /**
199
- * @computed
240
+ * @interal
200
241
  * The display value of the combobox (based on the selected items)
201
242
  */
202
243
  valueAsString: string;
203
- }>;
204
- interface PrivateContext {
205
244
  }
206
245
  interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
207
246
  }
@@ -212,13 +251,32 @@ interface MachineState {
212
251
  type State = StateMachine.State<MachineContext, MachineState>;
213
252
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
214
253
  interface ItemProps {
254
+ /**
255
+ * Whether hovering outside should clear the highlighted state
256
+ */
257
+ persistFocus?: boolean;
258
+ /**
259
+ * The item to render
260
+ */
215
261
  item: CollectionItem;
216
262
  }
217
263
  interface ItemState {
264
+ /**
265
+ * The value of the item
266
+ */
218
267
  value: string;
219
- isDisabled: boolean;
220
- isSelected: boolean;
221
- isHighlighted: boolean;
268
+ /**
269
+ * Whether the item is disabled
270
+ */
271
+ disabled: boolean;
272
+ /**
273
+ * Whether the item is selected
274
+ */
275
+ selected: boolean;
276
+ /**
277
+ * Whether the item is highlighted via pointer or keyboard navigation
278
+ */
279
+ highlighted: boolean;
222
280
  }
223
281
  interface ItemGroupProps {
224
282
  id: string;
@@ -230,15 +288,15 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
230
288
  /**
231
289
  * Whether the combobox is focused
232
290
  */
233
- isFocused: boolean;
291
+ focused: boolean;
234
292
  /**
235
293
  * Whether the combobox is open
236
294
  */
237
- isOpen: boolean;
295
+ open: boolean;
238
296
  /**
239
297
  * Whether the combobox input value is empty
240
298
  */
241
- isInputValueEmpty: boolean;
299
+ inputEmpty: boolean;
242
300
  /**
243
301
  * The value of the combobox input
244
302
  */
@@ -296,13 +354,9 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
296
354
  */
297
355
  getItemState(props: ItemProps): ItemState;
298
356
  /**
299
- * Function to open the combobox
300
- */
301
- open(): void;
302
- /**
303
- * Function to close the combobox
357
+ * Function to open or close the combobox
304
358
  */
305
- close(): void;
359
+ setOpen(open: boolean): void;
306
360
  /**
307
361
  * Function to toggle the combobox
308
362
  */
@@ -314,7 +368,7 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
314
368
  /**
315
369
  * Function to set the positioning options
316
370
  */
317
- reposition(options: Partial<PositioningOptions>): void;
371
+ reposition(options?: Partial<PositioningOptions>): void;
318
372
  rootProps: T["element"];
319
373
  labelProps: T["label"];
320
374
  controlProps: T["element"];
@@ -323,6 +377,7 @@ interface MachineApi<T extends PropTypes = PropTypes, V extends CollectionItem =
323
377
  contentProps: T["element"];
324
378
  triggerProps: T["button"];
325
379
  clearTriggerProps: T["button"];
380
+ listProps: T["element"];
326
381
  getItemProps(props: ItemProps): T["element"];
327
382
  getItemTextProps(props: ItemProps): T["element"];
328
383
  getItemIndicatorProps(props: ItemProps): T["element"];
@@ -334,4 +389,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
334
389
 
335
390
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
336
391
 
337
- export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type OpenChangeDetails, type ValueChangeDetails, anatomy, collection, connect, machine };
392
+ export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type OpenChangeDetails, type ScrollToIndexDetails, type SelectionValueDetails, type ValueChangeDetails, anatomy, collection, connect, machine };