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