@zag-js/combobox 1.0.0 → 1.0.2

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
@@ -3,9 +3,9 @@ export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from
3
3
  import * as _zag_js_anatomy from '@zag-js/anatomy';
4
4
  import { CollectionOptions, ListCollection, CollectionItem } from '@zag-js/collection';
5
5
  export { CollectionItem, CollectionOptions } from '@zag-js/collection';
6
- import { DirectionProperty, CommonProperties, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
6
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
7
7
  import * as _zag_js_core from '@zag-js/core';
8
- import { Service, EventObject } from '@zag-js/core';
8
+ import { Service, Machine, EventObject } from '@zag-js/core';
9
9
  import { PositioningOptions, Placement } from '@zag-js/popper';
10
10
  export { Placement, PositioningOptions } from '@zag-js/popper';
11
11
 
@@ -198,7 +198,7 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
198
198
  /**
199
199
  * The collection of items
200
200
  */
201
- collection?: ListCollection<any> | undefined;
201
+ collection?: ListCollection<T> | undefined;
202
202
  /**
203
203
  * Whether to allow multiple selection.
204
204
  *
@@ -234,7 +234,6 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
234
234
  navigate?: ((details: NavigateDetails) => void) | undefined;
235
235
  }
236
236
  type PropsWithDefault = "openOnChange" | "openOnKeyPress" | "composite" | "navigate" | "loopFocus" | "positioning" | "openOnClick" | "openOnChange" | "inputBehavior" | "collection" | "selectionBehavior" | "closeOnSelect" | "translations" | "positioning";
237
- type ComboboxService<T extends CollectionItem = CollectionItem> = Service<ComboboxSchema<T>>;
238
237
  interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
239
238
  props: RequiredBy<ComboboxProps<T>, PropsWithDefault>;
240
239
  state: "idle" | "focused" | "suggesting" | "interacting";
@@ -260,6 +259,8 @@ interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
260
259
  effect: string;
261
260
  guard: string;
262
261
  }
262
+ type ComboboxService<T extends CollectionItem = CollectionItem> = Service<ComboboxSchema<T>>;
263
+ type ComboboxMachine<T extends CollectionItem = CollectionItem> = Machine<ComboboxSchema<T>>;
263
264
  interface TriggerProps {
264
265
  /**
265
266
  * Whether the trigger is focusable
@@ -408,7 +409,7 @@ interface ComboboxApi<T extends PropTypes = PropTypes, V extends CollectionItem
408
409
 
409
410
  declare function connect<T extends PropTypes, V extends CollectionItem>(service: ComboboxService<V>, normalize: NormalizeProps<T>): ComboboxApi<T, V>;
410
411
 
411
- declare const machine: _zag_js_core.MachineConfig<ComboboxSchema<any>>;
412
+ declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
412
413
 
413
414
  declare const props: (keyof ComboboxProps<any>)[];
414
415
  declare const splitProps: <Props extends Partial<ComboboxProps<any>>>(props: Props) => [Partial<ComboboxProps<any>>, Omit<Props, keyof ComboboxProps<any>>];
@@ -419,4 +420,4 @@ declare const splitItemGroupProps: <Props extends ItemGroupProps>(props: Props)
419
420
  declare const itemProps: (keyof ItemProps)[];
420
421
  declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
421
422
 
422
- export { type ComboboxApi as Api, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type IntlTranslations, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type NavigateDetails, type OpenChangeDetails, type ComboboxProps as Props, type ScrollToIndexDetails, type ComboboxService as Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, itemGroupLabelProps, itemGroupProps, itemProps, machine, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps };
423
+ export { type ComboboxApi as Api, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type IntlTranslations, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type ComboboxMachine as Machine, type NavigateDetails, type OpenChangeDetails, type ComboboxProps as Props, type ScrollToIndexDetails, type ComboboxService as Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, itemGroupLabelProps, itemGroupProps, itemProps, machine, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps };
package/dist/index.d.ts CHANGED
@@ -3,9 +3,9 @@ export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from
3
3
  import * as _zag_js_anatomy from '@zag-js/anatomy';
4
4
  import { CollectionOptions, ListCollection, CollectionItem } from '@zag-js/collection';
5
5
  export { CollectionItem, CollectionOptions } from '@zag-js/collection';
6
- import { DirectionProperty, CommonProperties, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
6
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
7
7
  import * as _zag_js_core from '@zag-js/core';
8
- import { Service, EventObject } from '@zag-js/core';
8
+ import { Service, Machine, EventObject } from '@zag-js/core';
9
9
  import { PositioningOptions, Placement } from '@zag-js/popper';
10
10
  export { Placement, PositioningOptions } from '@zag-js/popper';
11
11
 
@@ -198,7 +198,7 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
198
198
  /**
199
199
  * The collection of items
200
200
  */
201
- collection?: ListCollection<any> | undefined;
201
+ collection?: ListCollection<T> | undefined;
202
202
  /**
203
203
  * Whether to allow multiple selection.
204
204
  *
@@ -234,7 +234,6 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
234
234
  navigate?: ((details: NavigateDetails) => void) | undefined;
235
235
  }
236
236
  type PropsWithDefault = "openOnChange" | "openOnKeyPress" | "composite" | "navigate" | "loopFocus" | "positioning" | "openOnClick" | "openOnChange" | "inputBehavior" | "collection" | "selectionBehavior" | "closeOnSelect" | "translations" | "positioning";
237
- type ComboboxService<T extends CollectionItem = CollectionItem> = Service<ComboboxSchema<T>>;
238
237
  interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
239
238
  props: RequiredBy<ComboboxProps<T>, PropsWithDefault>;
240
239
  state: "idle" | "focused" | "suggesting" | "interacting";
@@ -260,6 +259,8 @@ interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
260
259
  effect: string;
261
260
  guard: string;
262
261
  }
262
+ type ComboboxService<T extends CollectionItem = CollectionItem> = Service<ComboboxSchema<T>>;
263
+ type ComboboxMachine<T extends CollectionItem = CollectionItem> = Machine<ComboboxSchema<T>>;
263
264
  interface TriggerProps {
264
265
  /**
265
266
  * Whether the trigger is focusable
@@ -408,7 +409,7 @@ interface ComboboxApi<T extends PropTypes = PropTypes, V extends CollectionItem
408
409
 
409
410
  declare function connect<T extends PropTypes, V extends CollectionItem>(service: ComboboxService<V>, normalize: NormalizeProps<T>): ComboboxApi<T, V>;
410
411
 
411
- declare const machine: _zag_js_core.MachineConfig<ComboboxSchema<any>>;
412
+ declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
412
413
 
413
414
  declare const props: (keyof ComboboxProps<any>)[];
414
415
  declare const splitProps: <Props extends Partial<ComboboxProps<any>>>(props: Props) => [Partial<ComboboxProps<any>>, Omit<Props, keyof ComboboxProps<any>>];
@@ -419,4 +420,4 @@ declare const splitItemGroupProps: <Props extends ItemGroupProps>(props: Props)
419
420
  declare const itemProps: (keyof ItemProps)[];
420
421
  declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
421
422
 
422
- export { type ComboboxApi as Api, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type IntlTranslations, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type NavigateDetails, type OpenChangeDetails, type ComboboxProps as Props, type ScrollToIndexDetails, type ComboboxService as Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, itemGroupLabelProps, itemGroupProps, itemProps, machine, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps };
423
+ export { type ComboboxApi as Api, type ElementIds, type HighlightChangeDetails, type InputValueChangeDetails, type IntlTranslations, type ItemGroupLabelProps, type ItemGroupProps, type ItemProps, type ItemState, type ComboboxMachine as Machine, type NavigateDetails, type OpenChangeDetails, type ComboboxProps as Props, type ScrollToIndexDetails, type ComboboxService as Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, itemGroupLabelProps, itemGroupProps, itemProps, machine, props, splitItemGroupLabelProps, splitItemGroupProps, splitItemProps, splitProps };
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ var anatomy$1 = require('@zag-js/anatomy');
4
4
  var collection$1 = require('@zag-js/collection');
5
5
  var domQuery = require('@zag-js/dom-query');
6
6
  var popper = require('@zag-js/popper');
7
+ var utils = require('@zag-js/utils');
7
8
  var ariaHidden = require('@zag-js/aria-hidden');
8
9
  var core = require('@zag-js/core');
9
10
  var dismissable = require('@zag-js/dismissable');
10
- var utils = require('@zag-js/utils');
11
11
  var types = require('@zag-js/types');
12
12
 
13
13
  // src/combobox.anatomy.ts
@@ -87,6 +87,7 @@ function connect(service, normalize) {
87
87
  function getItemState(props2) {
88
88
  const disabled2 = collection2.getItemDisabled(props2.item);
89
89
  const value = collection2.getItemValue(props2.item);
90
+ utils.ensure(value, `[zag-js] No value found for item ${JSON.stringify(props2.item)}`);
90
91
  return {
91
92
  value,
92
93
  disabled: Boolean(disabled2 || disabled2),
@@ -479,7 +480,7 @@ var machine = core.createMachine({
479
480
  domQuery.clickIfLink(node);
480
481
  },
481
482
  collection: collection.empty(),
482
- ...utils.compact(props2),
483
+ ...props2,
483
484
  positioning: {
484
485
  placement: "bottom",
485
486
  sameWidth: true,
@@ -1313,21 +1314,20 @@ var machine = core.createMachine({
1313
1314
  invokeOnClose({ prop }) {
1314
1315
  prop("onOpenChange")?.({ open: false });
1315
1316
  },
1316
- highlightFirstItem({ context, prop }) {
1317
- domQuery.raf(() => {
1317
+ highlightFirstItem({ context, prop, scope }) {
1318
+ const exec = getContentEl(scope) ? queueMicrotask : domQuery.raf;
1319
+ exec(() => {
1318
1320
  const value = prop("collection").firstValue;
1319
- context.set("highlightedValue", value);
1321
+ if (value) context.set("highlightedValue", value);
1320
1322
  });
1321
1323
  },
1322
- highlightFirstItemIfNeeded({ context, prop, computed }) {
1324
+ highlightFirstItemIfNeeded({ computed, action }) {
1323
1325
  if (!computed("autoHighlight")) return;
1324
- domQuery.raf(() => {
1325
- const value = prop("collection").firstValue;
1326
- if (value) context.set("highlightedValue", value);
1327
- });
1326
+ action(["highlightFirstItem"]);
1328
1327
  },
1329
- highlightLastItem({ context, prop }) {
1330
- domQuery.raf(() => {
1328
+ highlightLastItem({ context, prop, scope }) {
1329
+ const exec = getContentEl(scope) ? queueMicrotask : domQuery.raf;
1330
+ exec(() => {
1331
1331
  const value = prop("collection").lastValue;
1332
1332
  if (value) context.set("highlightedValue", value);
1333
1333
  });
package/dist/index.mjs CHANGED
@@ -2,10 +2,10 @@ import { createAnatomy } from '@zag-js/anatomy';
2
2
  import { ListCollection } from '@zag-js/collection';
3
3
  import { clickIfLink, observeChildren, raf, observeAttributes, dataAttr, ariaAttr, isComposingEvent, getEventKey, isLeftClick, isDownloadingEvent, isOpeningInNewTab, isContextMenuEvent, scrollIntoView, query, isAnchorElement } from '@zag-js/dom-query';
4
4
  import { getPlacement, getPlacementStyles } from '@zag-js/popper';
5
+ import { match, isBoolean, addOrRemove, remove, createSplitProps, ensure } from '@zag-js/utils';
5
6
  import { ariaHidden } from '@zag-js/aria-hidden';
6
7
  import { createGuards, createMachine } from '@zag-js/core';
7
8
  import { trackDismissableElement } from '@zag-js/dismissable';
8
- import { compact, match, isBoolean, addOrRemove, remove, createSplitProps } from '@zag-js/utils';
9
9
  import { createProps } from '@zag-js/types';
10
10
 
11
11
  // src/combobox.anatomy.ts
@@ -85,6 +85,7 @@ function connect(service, normalize) {
85
85
  function getItemState(props2) {
86
86
  const disabled2 = collection2.getItemDisabled(props2.item);
87
87
  const value = collection2.getItemValue(props2.item);
88
+ ensure(value, `[zag-js] No value found for item ${JSON.stringify(props2.item)}`);
88
89
  return {
89
90
  value,
90
91
  disabled: Boolean(disabled2 || disabled2),
@@ -477,7 +478,7 @@ var machine = createMachine({
477
478
  clickIfLink(node);
478
479
  },
479
480
  collection: collection.empty(),
480
- ...compact(props2),
481
+ ...props2,
481
482
  positioning: {
482
483
  placement: "bottom",
483
484
  sameWidth: true,
@@ -1311,21 +1312,20 @@ var machine = createMachine({
1311
1312
  invokeOnClose({ prop }) {
1312
1313
  prop("onOpenChange")?.({ open: false });
1313
1314
  },
1314
- highlightFirstItem({ context, prop }) {
1315
- raf(() => {
1315
+ highlightFirstItem({ context, prop, scope }) {
1316
+ const exec = getContentEl(scope) ? queueMicrotask : raf;
1317
+ exec(() => {
1316
1318
  const value = prop("collection").firstValue;
1317
- context.set("highlightedValue", value);
1319
+ if (value) context.set("highlightedValue", value);
1318
1320
  });
1319
1321
  },
1320
- highlightFirstItemIfNeeded({ context, prop, computed }) {
1322
+ highlightFirstItemIfNeeded({ computed, action }) {
1321
1323
  if (!computed("autoHighlight")) return;
1322
- raf(() => {
1323
- const value = prop("collection").firstValue;
1324
- if (value) context.set("highlightedValue", value);
1325
- });
1324
+ action(["highlightFirstItem"]);
1326
1325
  },
1327
- highlightLastItem({ context, prop }) {
1328
- raf(() => {
1326
+ highlightLastItem({ context, prop, scope }) {
1327
+ const exec = getContentEl(scope) ? queueMicrotask : raf;
1328
+ exec(() => {
1329
1329
  const value = prop("collection").lastValue;
1330
1330
  if (value) context.set("highlightedValue", value);
1331
1331
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/combobox",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Core logic for the combobox widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,15 +26,15 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.0.0",
30
- "@zag-js/aria-hidden": "1.0.0",
31
- "@zag-js/collection": "1.0.0",
32
- "@zag-js/core": "1.0.0",
33
- "@zag-js/dismissable": "1.0.0",
34
- "@zag-js/dom-query": "1.0.0",
35
- "@zag-js/utils": "1.0.0",
36
- "@zag-js/popper": "1.0.0",
37
- "@zag-js/types": "1.0.0"
29
+ "@zag-js/anatomy": "1.0.2",
30
+ "@zag-js/aria-hidden": "1.0.2",
31
+ "@zag-js/collection": "1.0.2",
32
+ "@zag-js/core": "1.0.2",
33
+ "@zag-js/dismissable": "1.0.2",
34
+ "@zag-js/dom-query": "1.0.2",
35
+ "@zag-js/utils": "1.0.2",
36
+ "@zag-js/popper": "1.0.2",
37
+ "@zag-js/types": "1.0.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "clean-package": "2.2.0"