@zag-js/combobox 0.79.3 → 0.81.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
@@ -9,7 +9,7 @@ import { Machine, StateMachine } from '@zag-js/core';
9
9
  import { PositioningOptions } from '@zag-js/popper';
10
10
  export { Placement, PositioningOptions } from '@zag-js/popper';
11
11
 
12
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"input" | "label" | "root" | "content" | "item" | "list" | "clearTrigger" | "control" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "positioner" | "trigger">;
12
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"content" | "list" | "label" | "input" | "root" | "item" | "clearTrigger" | "control" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "positioner" | "trigger">;
13
13
 
14
14
  declare const collection: {
15
15
  <T extends unknown>(options: CollectionOptions<T>): ListCollection<T>;
@@ -34,6 +34,10 @@ interface ScrollToIndexDetails {
34
34
  index: number;
35
35
  immediate?: boolean | undefined;
36
36
  }
37
+ interface NavigateDetails {
38
+ value: string | null;
39
+ node: HTMLAnchorElement;
40
+ }
37
41
  interface IntlTranslations {
38
42
  triggerLabel?: string | undefined;
39
43
  clearTriggerLabel?: string | undefined;
@@ -205,6 +209,10 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
205
209
  * Whether to disable registering this a dismissable layer
206
210
  */
207
211
  disableLayer?: boolean | undefined;
212
+ /**
213
+ * Function to navigate to the selected item
214
+ */
215
+ navigate: (details: NavigateDetails) => void;
208
216
  }
209
217
  type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
210
218
  type ComputedContext = Readonly<{
@@ -401,4 +409,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
401
409
 
402
410
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
403
411
 
404
- 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 Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
412
+ 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 NavigateDetails, type OpenChangeDetails, type ScrollToIndexDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import { Machine, StateMachine } from '@zag-js/core';
9
9
  import { PositioningOptions } from '@zag-js/popper';
10
10
  export { Placement, PositioningOptions } from '@zag-js/popper';
11
11
 
12
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"input" | "label" | "root" | "content" | "item" | "list" | "clearTrigger" | "control" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "positioner" | "trigger">;
12
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"content" | "list" | "label" | "input" | "root" | "item" | "clearTrigger" | "control" | "itemGroup" | "itemGroupLabel" | "itemIndicator" | "itemText" | "positioner" | "trigger">;
13
13
 
14
14
  declare const collection: {
15
15
  <T extends unknown>(options: CollectionOptions<T>): ListCollection<T>;
@@ -34,6 +34,10 @@ interface ScrollToIndexDetails {
34
34
  index: number;
35
35
  immediate?: boolean | undefined;
36
36
  }
37
+ interface NavigateDetails {
38
+ value: string | null;
39
+ node: HTMLAnchorElement;
40
+ }
37
41
  interface IntlTranslations {
38
42
  triggerLabel?: string | undefined;
39
43
  clearTriggerLabel?: string | undefined;
@@ -205,6 +209,10 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
205
209
  * Whether to disable registering this a dismissable layer
206
210
  */
207
211
  disableLayer?: boolean | undefined;
212
+ /**
213
+ * Function to navigate to the selected item
214
+ */
215
+ navigate: (details: NavigateDetails) => void;
208
216
  }
209
217
  type UserDefinedContext<T extends CollectionItem = CollectionItem> = RequiredBy<PublicContext<T>, "id" | "collection">;
210
218
  type ComputedContext = Readonly<{
@@ -401,4 +409,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
401
409
 
402
410
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
403
411
 
404
- 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 Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
412
+ 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 NavigateDetails, type OpenChangeDetails, type ScrollToIndexDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var anatomy$1 = require('@zag-js/anatomy');
4
4
  var collection$1 = require('@zag-js/collection');
5
5
  var core = require('@zag-js/core');
6
- var domEvent = require('@zag-js/dom-event');
7
6
  var domQuery = require('@zag-js/dom-query');
8
7
  var popper = require('@zag-js/popper');
9
8
  var ariaHidden = require('@zag-js/aria-hidden');
@@ -270,14 +269,19 @@ function connect(state, send, normalize) {
270
269
  event2.preventDefault();
271
270
  }
272
271
  const itemEl = dom.getHighlightedItemEl(state.context);
273
- domEvent.clickIfLink(itemEl);
272
+ if (domQuery.isAnchorElement(itemEl)) {
273
+ state.context.navigate({
274
+ value: state.context.highlightedValue,
275
+ node: itemEl
276
+ });
277
+ }
274
278
  },
275
279
  Escape() {
276
280
  send({ type: "INPUT.ESCAPE", keypress });
277
281
  event.preventDefault();
278
282
  }
279
283
  };
280
- const key = domEvent.getEventKey(event, state.context);
284
+ const key = domQuery.getEventKey(event, state.context);
281
285
  const exec = keymap[key];
282
286
  exec?.(event);
283
287
  }
@@ -307,7 +311,7 @@ function connect(state, send, normalize) {
307
311
  onClick(event) {
308
312
  if (event.defaultPrevented) return;
309
313
  if (!interactive) return;
310
- if (!domEvent.isLeftClick(event)) return;
314
+ if (!domQuery.isLeftClick(event)) return;
311
315
  send("TRIGGER.CLICK");
312
316
  },
313
317
  onPointerDown(event) {
@@ -329,7 +333,7 @@ function connect(state, send, normalize) {
329
333
  send({ type: "INPUT.ARROW_UP", src: "trigger" });
330
334
  }
331
335
  };
332
- const key = domEvent.getEventKey(event, state.context);
336
+ const key = domQuery.getEventKey(event, state.context);
333
337
  const exec = keyMap[key];
334
338
  if (exec) {
335
339
  exec(event);
@@ -416,7 +420,7 @@ function connect(state, send, normalize) {
416
420
  onClick(event) {
417
421
  if (domQuery.isDownloadingEvent(event)) return;
418
422
  if (domQuery.isOpeningInNewTab(event)) return;
419
- if (domEvent.isContextMenuEvent(event)) return;
423
+ if (domQuery.isContextMenuEvent(event)) return;
420
424
  if (itemState.disabled) return;
421
425
  send({ type: "ITEM.CLICK", src: "click", value });
422
426
  }
@@ -484,6 +488,9 @@ function machine(userContext) {
484
488
  composite: true,
485
489
  readOnly: false,
486
490
  disabled: false,
491
+ navigate({ node }) {
492
+ domQuery.clickIfLink(node);
493
+ },
487
494
  ...ctx,
488
495
  highlightedItem: null,
489
496
  selectedItems: [],
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
2
  import { ListCollection } from '@zag-js/collection';
3
3
  import { ref, createMachine, guards } from '@zag-js/core';
4
- import { getEventKey, isLeftClick, isContextMenuEvent, clickIfLink } from '@zag-js/dom-event';
5
- import { createScope, query, dataAttr, ariaAttr, isComposingEvent, isDownloadingEvent, isOpeningInNewTab, observeChildren, raf, observeAttributes, scrollIntoView } from '@zag-js/dom-query';
4
+ import { createScope, query, dataAttr, ariaAttr, isComposingEvent, getEventKey, isLeftClick, isDownloadingEvent, isOpeningInNewTab, isContextMenuEvent, clickIfLink, observeChildren, raf, observeAttributes, scrollIntoView, isAnchorElement } from '@zag-js/dom-query';
6
5
  import { getPlacementStyles, getPlacement } from '@zag-js/popper';
7
6
  import { ariaHidden } from '@zag-js/aria-hidden';
8
7
  import { trackDismissableElement } from '@zag-js/dismissable';
@@ -268,7 +267,12 @@ function connect(state, send, normalize) {
268
267
  event2.preventDefault();
269
268
  }
270
269
  const itemEl = dom.getHighlightedItemEl(state.context);
271
- clickIfLink(itemEl);
270
+ if (isAnchorElement(itemEl)) {
271
+ state.context.navigate({
272
+ value: state.context.highlightedValue,
273
+ node: itemEl
274
+ });
275
+ }
272
276
  },
273
277
  Escape() {
274
278
  send({ type: "INPUT.ESCAPE", keypress });
@@ -482,6 +486,9 @@ function machine(userContext) {
482
486
  composite: true,
483
487
  readOnly: false,
484
488
  disabled: false,
489
+ navigate({ node }) {
490
+ clickIfLink(node);
491
+ },
485
492
  ...ctx,
486
493
  highlightedItem: null,
487
494
  selectedItems: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/combobox",
3
- "version": "0.79.3",
3
+ "version": "0.81.0",
4
4
  "description": "Core logic for the combobox widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,16 +26,15 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "0.79.3",
30
- "@zag-js/aria-hidden": "0.79.3",
31
- "@zag-js/collection": "0.79.3",
32
- "@zag-js/core": "0.79.3",
33
- "@zag-js/dismissable": "0.79.3",
34
- "@zag-js/dom-query": "0.79.3",
35
- "@zag-js/dom-event": "0.79.3",
36
- "@zag-js/utils": "0.79.3",
37
- "@zag-js/popper": "0.79.3",
38
- "@zag-js/types": "0.79.3"
29
+ "@zag-js/anatomy": "0.81.0",
30
+ "@zag-js/aria-hidden": "0.81.0",
31
+ "@zag-js/collection": "0.81.0",
32
+ "@zag-js/core": "0.81.0",
33
+ "@zag-js/dismissable": "0.81.0",
34
+ "@zag-js/dom-query": "0.81.0",
35
+ "@zag-js/utils": "0.81.0",
36
+ "@zag-js/popper": "0.81.0",
37
+ "@zag-js/types": "0.81.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "clean-package": "2.2.0"