@zag-js/combobox 1.34.0 → 1.35.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,455 +1,12 @@
1
- import { InteractOutsideHandlers } from '@zag-js/dismissable';
2
1
  export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from '@zag-js/dismissable';
3
- import * as _zag_js_anatomy from '@zag-js/anatomy';
4
- import { CollectionOptions, ListCollection, CollectionItem } from '@zag-js/collection';
2
+ export { anatomy } from './combobox.anatomy.mjs';
3
+ export { collection } from './combobox.collection.mjs';
4
+ export { connect } from './combobox.connect.mjs';
5
+ export { machine } from './combobox.machine.mjs';
6
+ export { itemGroupLabelProps, itemGroupProps, itemProps, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps } from './combobox.props.mjs';
7
+ export { ComboboxApi as Api, ElementIds, HighlightChangeDetails, InputValueChangeDetails, InputValueChangeReason, IntlTranslations, ItemGroupLabelProps, ItemGroupProps, ItemProps, ItemState, ComboboxMachine as Machine, NavigateDetails, OpenChangeDetails, OpenChangeReason, ComboboxProps as Props, ScrollToIndexDetails, SelectionDetails, ComboboxService as Service, TriggerProps, ValueChangeDetails } from './combobox.types.mjs';
5
8
  export { CollectionItem, CollectionOptions } from '@zag-js/collection';
6
- import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
7
- import * as _zag_js_core from '@zag-js/core';
8
- import { Machine, EventObject, Service } from '@zag-js/core';
9
- import { PositioningOptions, Placement } from '@zag-js/popper';
10
9
  export { Placement, PositioningOptions } from '@zag-js/popper';
11
-
12
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"content" | "list" | "label" | "input" | "root" | "item" | "clearTrigger" | "control" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "positioner" | "trigger">;
13
-
14
- declare const collection: {
15
- <T extends unknown>(options: CollectionOptions<T>): ListCollection<T>;
16
- empty(): ListCollection<CollectionItem>;
17
- };
18
-
19
- interface ValueChangeDetails<T extends CollectionItem = CollectionItem> {
20
- value: string[];
21
- items: T[];
22
- }
23
- interface HighlightChangeDetails<T extends CollectionItem = CollectionItem> {
24
- highlightedValue: string | null;
25
- highlightedItem: T | null;
26
- }
27
- /**
28
- * The reason for the input value change
29
- */
30
- type InputValueChangeReason = "input-change" | "item-select" | "clear-trigger" | "script" | "interact-outside";
31
- interface InputValueChangeDetails {
32
- inputValue: string;
33
- reason?: InputValueChangeReason | undefined;
34
- }
35
- /**
36
- * The reason for the combobox open/close state change
37
- */
38
- type OpenChangeReason = "input-click" | "trigger-click" | "script" | "arrow-key" | "input-change" | "interact-outside" | "escape-key" | "item-select" | "clear-trigger";
39
- interface OpenChangeDetails {
40
- open: boolean;
41
- reason?: OpenChangeReason | undefined;
42
- value: string[];
43
- }
44
- interface ScrollToIndexDetails {
45
- index: number;
46
- immediate?: boolean | undefined;
47
- getElement: () => HTMLElement | null;
48
- }
49
- interface NavigateDetails {
50
- value: string;
51
- node: HTMLAnchorElement;
52
- href: string;
53
- }
54
- interface SelectionDetails {
55
- value: string[];
56
- itemValue: string;
57
- }
58
- interface IntlTranslations {
59
- triggerLabel?: string | undefined;
60
- clearTriggerLabel?: string | undefined;
61
- }
62
- type ElementIds = Partial<{
63
- root: string;
64
- label: string;
65
- control: string;
66
- input: string;
67
- content: string;
68
- trigger: string;
69
- clearTrigger: string;
70
- item: (id: string, index?: number) => string;
71
- positioner: string;
72
- itemGroup: (id: string | number) => string;
73
- itemGroupLabel: (id: string | number) => string;
74
- }>;
75
- interface ComboboxProps<T extends CollectionItem = CollectionItem> extends DirectionProperty, CommonProperties, InteractOutsideHandlers {
76
- /**
77
- * The controlled open state of the combobox
78
- */
79
- open?: boolean | undefined;
80
- /**
81
- * The initial open state of the combobox when rendered.
82
- * Use when you don't need to control the open state of the combobox.
83
- */
84
- defaultOpen?: boolean | undefined;
85
- /**
86
- * The ids of the elements in the combobox. Useful for composition.
87
- */
88
- ids?: ElementIds | undefined;
89
- /**
90
- * The controlled value of the combobox's input
91
- */
92
- inputValue?: string | undefined;
93
- /**
94
- * The initial value of the combobox's input when rendered.
95
- * Use when you don't need to control the value of the combobox's input.
96
- * @default ""
97
- */
98
- defaultInputValue?: string | undefined;
99
- /**
100
- * The `name` attribute of the combobox's input. Useful for form submission
101
- */
102
- name?: string | undefined;
103
- /**
104
- * The associate form of the combobox.
105
- */
106
- form?: string | undefined;
107
- /**
108
- * Whether the combobox is disabled
109
- */
110
- disabled?: boolean | undefined;
111
- /**
112
- * Whether the combobox is readonly. This puts the combobox in a "non-editable" mode
113
- * but the user can still interact with it
114
- */
115
- readOnly?: boolean | undefined;
116
- /**
117
- * Whether the combobox is invalid
118
- */
119
- invalid?: boolean | undefined;
120
- /**
121
- * Whether the combobox is required
122
- */
123
- required?: boolean | undefined;
124
- /**
125
- * The placeholder text of the combobox's input
126
- */
127
- placeholder?: string | undefined;
128
- /**
129
- * The initial highlighted value of the combobox when rendered.
130
- * Use when you don't need to control the highlighted value of the combobox.
131
- */
132
- defaultHighlightedValue?: string | null | undefined;
133
- /**
134
- * The controlled highlighted value of the combobox
135
- */
136
- highlightedValue?: string | null | undefined;
137
- /**
138
- * The controlled value of the combobox's selected items
139
- */
140
- value?: string[] | undefined;
141
- /**
142
- * The initial value of the combobox's selected items when rendered.
143
- * Use when you don't need to control the value of the combobox's selected items.
144
- * @default []
145
- */
146
- defaultValue?: string[] | undefined;
147
- /**
148
- * Defines the auto-completion behavior of the combobox.
149
- *
150
- * - `autohighlight`: The first focused item is highlighted as the user types
151
- * - `autocomplete`: Navigating the listbox with the arrow keys selects the item and the input is updated
152
- *
153
- * @default "none"
154
- */
155
- inputBehavior?: "autohighlight" | "autocomplete" | "none" | undefined;
156
- /**
157
- * The behavior of the combobox input when an item is selected
158
- *
159
- * - `replace`: The selected item string is set as the input value
160
- * - `clear`: The input value is cleared
161
- * - `preserve`: The input value is preserved
162
- *
163
- * @default "replace"
164
- */
165
- selectionBehavior?: "clear" | "replace" | "preserve" | undefined;
166
- /**
167
- * Whether to autofocus the input on mount
168
- */
169
- autoFocus?: boolean | undefined;
170
- /**
171
- * Whether to open the combobox popup on initial click on the input
172
- * @default false
173
- */
174
- openOnClick?: boolean | undefined;
175
- /**
176
- * Whether to show the combobox when the input value changes
177
- * @default true
178
- */
179
- openOnChange?: boolean | ((details: InputValueChangeDetails) => boolean) | undefined;
180
- /**
181
- * Whether to allow typing custom values in the input
182
- */
183
- allowCustomValue?: boolean | undefined;
184
- /**
185
- * Whether to always submit on Enter key press, even if popup is open.
186
- * Useful for single-field autocomplete forms where Enter should submit the form.
187
- * @default false
188
- */
189
- alwaysSubmitOnEnter?: boolean | undefined;
190
- /**
191
- * Whether to loop the keyboard navigation through the items
192
- * @default true
193
- */
194
- loopFocus?: boolean | undefined;
195
- /**
196
- * The positioning options to dynamically position the menu
197
- * @default { placement: "bottom-start" }
198
- */
199
- positioning?: PositioningOptions | undefined;
200
- /**
201
- * Function called when the input's value changes
202
- */
203
- onInputValueChange?: ((details: InputValueChangeDetails) => void) | undefined;
204
- /**
205
- * Function called when a new item is selected
206
- */
207
- onValueChange?: ((details: ValueChangeDetails<T>) => void) | undefined;
208
- /**
209
- * Function called when an item is highlighted using the pointer
210
- * or keyboard navigation.
211
- */
212
- onHighlightChange?: ((details: HighlightChangeDetails<T>) => void) | undefined;
213
- /**
214
- * Function called when an item is selected
215
- */
216
- onSelect?: ((details: SelectionDetails) => void) | undefined;
217
- /**
218
- * Function called when the popup is opened
219
- */
220
- onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
221
- /**
222
- * Specifies the localized strings that identifies the accessibility elements and their states
223
- */
224
- translations?: IntlTranslations | undefined;
225
- /**
226
- * The collection of items
227
- */
228
- collection?: ListCollection<T> | undefined;
229
- /**
230
- * Whether to allow multiple selection.
231
- *
232
- * **Good to know:** When `multiple` is `true`, the `selectionBehavior` is automatically set to `clear`.
233
- * It is recommended to render the selected items in a separate container.
234
- */
235
- multiple?: boolean | undefined;
236
- /**
237
- * Whether to close the combobox when an item is selected.
238
- */
239
- closeOnSelect?: boolean | undefined;
240
- /**
241
- * Whether to open the combobox on arrow key press
242
- * @default true
243
- */
244
- openOnKeyPress?: boolean | undefined;
245
- /**
246
- * Function to scroll to a specific index
247
- */
248
- scrollToIndexFn?: ((details: ScrollToIndexDetails) => void) | undefined;
249
- /**
250
- * Whether the combobox is a composed with other composite widgets like tabs
251
- * @default true
252
- */
253
- composite?: boolean | undefined;
254
- /**
255
- * Whether to disable registering this a dismissable layer
256
- */
257
- disableLayer?: boolean | undefined;
258
- /**
259
- * Function to navigate to the selected item
260
- */
261
- navigate?: ((details: NavigateDetails) => void) | null | undefined;
262
- }
263
- type PropsWithDefault = "openOnChange" | "openOnKeyPress" | "composite" | "loopFocus" | "positioning" | "openOnClick" | "openOnChange" | "inputBehavior" | "collection" | "selectionBehavior" | "closeOnSelect" | "translations" | "positioning" | "defaultValue" | "defaultInputValue";
264
- interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
265
- props: RequiredBy<ComboboxProps<T>, PropsWithDefault>;
266
- state: "idle" | "focused" | "suggesting" | "interacting";
267
- tag: "open" | "focused" | "idle" | "closed";
268
- context: {
269
- value: string[];
270
- inputValue: string;
271
- highlightedValue: string | null;
272
- currentPlacement?: Placement | undefined;
273
- highlightedItem: T | null;
274
- selectedItems: T[];
275
- };
276
- computed: {
277
- isCustomValue: boolean;
278
- isInputValueEmpty: boolean;
279
- isInteractive: boolean;
280
- autoComplete: boolean;
281
- autoHighlight: boolean;
282
- hasSelectedItems: boolean;
283
- valueAsString: string;
284
- };
285
- event: EventObject;
286
- action: string;
287
- effect: string;
288
- guard: string;
289
- }
290
- type ComboboxService<T extends CollectionItem = CollectionItem> = Service<ComboboxSchema<T>>;
291
- type ComboboxMachine<T extends CollectionItem = CollectionItem> = Machine<ComboboxSchema<T>>;
292
- interface TriggerProps {
293
- /**
294
- * Whether the trigger is focusable
295
- */
296
- focusable?: boolean | undefined;
297
- }
298
- interface ItemProps {
299
- /**
300
- * Whether hovering outside should clear the highlighted state
301
- */
302
- persistFocus?: boolean | undefined;
303
- /**
304
- * The item to render
305
- */
306
- item: CollectionItem;
307
- }
308
- interface ItemState {
309
- /**
310
- * The value of the item
311
- */
312
- value: string;
313
- /**
314
- * Whether the item is disabled
315
- */
316
- disabled: boolean;
317
- /**
318
- * Whether the item is selected
319
- */
320
- selected: boolean;
321
- /**
322
- * Whether the item is highlighted via pointer or keyboard navigation
323
- */
324
- highlighted: boolean;
325
- }
326
- interface ItemGroupProps {
327
- id: string;
328
- }
329
- interface ItemGroupLabelProps {
330
- htmlFor: string;
331
- }
332
- interface ComboboxApi<T extends PropTypes = PropTypes, V extends CollectionItem = CollectionItem> {
333
- /**
334
- * Whether the combobox is focused
335
- */
336
- focused: boolean;
337
- /**
338
- * Whether the combobox is open
339
- */
340
- open: boolean;
341
- /**
342
- * The value of the combobox input
343
- */
344
- inputValue: string;
345
- /**
346
- * The value of the highlighted item
347
- */
348
- highlightedValue: string | null;
349
- /**
350
- * The highlighted item
351
- */
352
- highlightedItem: V | null;
353
- /**
354
- * The value of the combobox input
355
- */
356
- setHighlightValue: (value: string) => void;
357
- /**
358
- * Function to clear the highlighted value
359
- */
360
- clearHighlightValue: VoidFunction;
361
- /**
362
- * Function to sync the selected items with the value.
363
- * Useful when `value` is updated from async sources.
364
- */
365
- syncSelectedItems: VoidFunction;
366
- /**
367
- * The selected items
368
- */
369
- selectedItems: V[];
370
- /**
371
- * Whether there's a selected item
372
- */
373
- hasSelectedItems: boolean;
374
- /**
375
- * The selected item keys
376
- */
377
- value: string[];
378
- /**
379
- * The string representation of the selected items
380
- */
381
- valueAsString: string;
382
- /**
383
- * Function to select a value
384
- */
385
- selectValue: (value: string) => void;
386
- /**
387
- * Function to set the value of the combobox
388
- */
389
- setValue: (value: string[]) => void;
390
- /**
391
- * Function to clear the value of the combobox
392
- */
393
- clearValue: (value?: string) => void;
394
- /**
395
- * Function to focus on the combobox input
396
- */
397
- focus: VoidFunction;
398
- /**
399
- * Function to set the input value of the combobox
400
- */
401
- setInputValue: (value: string, reason?: InputValueChangeReason) => void;
402
- /**
403
- * Returns the state of a combobox item
404
- */
405
- getItemState: (props: ItemProps) => ItemState;
406
- /**
407
- * Function to open or close the combobox
408
- */
409
- setOpen: (open: boolean, reason?: OpenChangeReason) => void;
410
- /**
411
- * Function to toggle the combobox
412
- */
413
- collection: ListCollection<V>;
414
- /**
415
- * Function to set the positioning options
416
- */
417
- reposition: (options?: Partial<PositioningOptions>) => void;
418
- /**
419
- * Whether the combobox allows multiple selections
420
- */
421
- multiple: boolean;
422
- /**
423
- * Whether the combobox is disabled
424
- */
425
- disabled: boolean;
426
- getRootProps: () => T["element"];
427
- getLabelProps: () => T["label"];
428
- getControlProps: () => T["element"];
429
- getPositionerProps: () => T["element"];
430
- getInputProps: () => T["input"];
431
- getContentProps: () => T["element"];
432
- getTriggerProps: (props?: TriggerProps) => T["button"];
433
- getClearTriggerProps: () => T["button"];
434
- getListProps: () => T["element"];
435
- getItemProps: (props: ItemProps) => T["element"];
436
- getItemTextProps: (props: ItemProps) => T["element"];
437
- getItemIndicatorProps: (props: ItemProps) => T["element"];
438
- getItemGroupProps: (props: ItemGroupProps) => T["element"];
439
- getItemGroupLabelProps: (props: ItemGroupLabelProps) => T["element"];
440
- }
441
-
442
- declare function connect<T extends PropTypes, V extends CollectionItem>(service: ComboboxService<V>, normalize: NormalizeProps<T>): ComboboxApi<T, V>;
443
-
444
- declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
445
-
446
- declare const props: (keyof ComboboxProps<any>)[];
447
- declare const splitProps: <Props extends Partial<ComboboxProps<any>>>(props: Props) => [Partial<ComboboxProps<any>>, Omit<Props, keyof ComboboxProps<any>>];
448
- declare const itemGroupLabelProps: "htmlFor"[];
449
- declare const splitItemGroupLabelProps: <Props extends ItemGroupLabelProps>(props: Props) => [ItemGroupLabelProps, Omit<Props, "htmlFor">];
450
- declare const itemGroupProps: "id"[];
451
- declare const splitItemGroupProps: <Props extends ItemGroupProps>(props: Props) => [ItemGroupProps, Omit<Props, "id">];
452
- declare const itemProps: (keyof ItemProps)[];
453
- declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
454
-
455
- export { type ComboboxApi as Api, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type InputValueChangeReason, type IntlTranslations, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type ComboboxMachine as Machine, type NavigateDetails, type OpenChangeDetails, type OpenChangeReason, type ComboboxProps as Props, type ScrollToIndexDetails, type SelectionDetails, type ComboboxService as Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, itemGroupLabelProps, itemGroupProps, itemProps, machine, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps };
10
+ import '@zag-js/anatomy';
11
+ import '@zag-js/types';
12
+ import '@zag-js/core';