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