@zag-js/combobox 1.39.0 → 1.40.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.
@@ -4,6 +4,7 @@ import { CollectionItem } from '@zag-js/collection';
4
4
  import '@zag-js/core';
5
5
  import '@zag-js/dismissable';
6
6
  import '@zag-js/popper';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare function connect<T extends PropTypes, V extends CollectionItem>(service: ComboboxService<V>, normalize: NormalizeProps<T>): ComboboxApi<T, V>;
9
10
 
@@ -4,6 +4,7 @@ import { CollectionItem } from '@zag-js/collection';
4
4
  import '@zag-js/core';
5
5
  import '@zag-js/dismissable';
6
6
  import '@zag-js/popper';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare function connect<T extends PropTypes, V extends CollectionItem>(service: ComboboxService<V>, normalize: NormalizeProps<T>): ComboboxApi<T, V>;
9
10
 
@@ -4,6 +4,7 @@ import '@zag-js/collection';
4
4
  import '@zag-js/dismissable';
5
5
  import '@zag-js/popper';
6
6
  import '@zag-js/types';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
9
10
 
@@ -4,6 +4,7 @@ import '@zag-js/collection';
4
4
  import '@zag-js/dismissable';
5
5
  import '@zag-js/popper';
6
6
  import '@zag-js/types';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
9
10
 
@@ -33,12 +33,13 @@ __export(combobox_machine_exports, {
33
33
  machine: () => machine
34
34
  });
35
35
  module.exports = __toCommonJS(combobox_machine_exports);
36
+ var import_collection = require("@zag-js/collection");
36
37
  var import_core = require("@zag-js/core");
37
38
  var import_dismissable = require("@zag-js/dismissable");
38
39
  var import_dom_query = require("@zag-js/dom-query");
39
40
  var import_focus_visible = require("@zag-js/focus-visible");
41
+ var import_live_region = require("@zag-js/live-region");
40
42
  var import_popper = require("@zag-js/popper");
41
- var import_collection = require("@zag-js/collection");
42
43
  var import_utils = require("@zag-js/utils");
43
44
  var import_combobox = require("./combobox.collection.js");
44
45
  var dom = __toESM(require("./combobox.dom.js"));
@@ -179,7 +180,7 @@ var machine = createMachine({
179
180
  action(["syncInputValue"]);
180
181
  });
181
182
  track([() => context.get("highlightedValue")], () => {
182
- action(["syncHighlightedItem", "autofillInputValue"]);
183
+ action(["syncHighlightedItem", "autofillInputValue", "announceHighlightedItem"]);
183
184
  });
184
185
  track([() => prop("open")], () => {
185
186
  action(["toggleVisibility"]);
@@ -390,7 +391,13 @@ var machine = createMachine({
390
391
  open: {
391
392
  tags: ["open", "focused"],
392
393
  entry: ["setInitialFocus"],
393
- effects: ["trackFocusVisible", "scrollToHighlightedItem", "trackDismissableLayer", "trackPlacement"],
394
+ effects: [
395
+ "trackFocusVisible",
396
+ "scrollToHighlightedItem",
397
+ "trackDismissableLayer",
398
+ "trackPlacement",
399
+ "trackLiveRegion"
400
+ ],
394
401
  on: {
395
402
  "CONTROLLED.CLOSE": [
396
403
  {
@@ -675,6 +682,14 @@ var machine = createMachine({
675
682
  }
676
683
  });
677
684
  },
685
+ trackLiveRegion({ refs, scope }) {
686
+ const liveRegion = (0, import_live_region.createLiveRegion)({
687
+ level: "assertive",
688
+ document: scope.getDoc()
689
+ });
690
+ refs.set("liveRegion", liveRegion);
691
+ return () => liveRegion.destroy();
692
+ },
678
693
  trackPlacement({ context, prop, scope }) {
679
694
  const anchorEl = () => dom.getControlEl(scope) || dom.getTriggerEl(scope);
680
695
  const positionerEl = () => dom.getPositionerEl(scope);
@@ -997,6 +1012,14 @@ var machine = createMachine({
997
1012
  const item = prop("collection").find(context.get("highlightedValue"));
998
1013
  context.set("highlightedItem", item);
999
1014
  },
1015
+ announceHighlightedItem({ context, prop, refs }) {
1016
+ if (!(0, import_dom_query.isApple)()) return;
1017
+ const value = context.get("highlightedValue");
1018
+ const optionText = value ? prop("collection").stringifyItem(prop("collection").find(value)) : null;
1019
+ if (!optionText) return;
1020
+ const isSelected = value ? context.get("value").includes(value) : false;
1021
+ refs.get("liveRegion")?.announce(isSelected ? `${optionText}, selected` : optionText);
1022
+ },
1000
1023
  toggleVisibility({ event, send, prop }) {
1001
1024
  send({ type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: event });
1002
1025
  }
@@ -1,14 +1,23 @@
1
1
  // src/combobox.machine.ts
2
- import { setup } from "@zag-js/core";
3
- import { trackDismissableElement } from "@zag-js/dismissable";
4
- import { clickIfLink, nextTick, observeAttributes, raf, scrollIntoView, setCaretToEnd } from "@zag-js/dom-query";
5
- import { getInteractionModality, setInteractionModality, trackFocusVisible } from "@zag-js/focus-visible";
6
- import { getPlacement } from "@zag-js/popper";
7
2
  import {
8
3
  createSelectedItemMap,
9
4
  deriveSelectionState,
10
5
  resolveSelectedItems
11
6
  } from "@zag-js/collection";
7
+ import { setup } from "@zag-js/core";
8
+ import { trackDismissableElement } from "@zag-js/dismissable";
9
+ import {
10
+ clickIfLink,
11
+ isApple,
12
+ nextTick,
13
+ observeAttributes,
14
+ raf,
15
+ scrollIntoView,
16
+ setCaretToEnd
17
+ } from "@zag-js/dom-query";
18
+ import { getInteractionModality, setInteractionModality, trackFocusVisible } from "@zag-js/focus-visible";
19
+ import { createLiveRegion } from "@zag-js/live-region";
20
+ import { getPlacement } from "@zag-js/popper";
12
21
  import { addOrRemove, isBoolean, isEqual, match, remove } from "@zag-js/utils";
13
22
  import { collection } from "./combobox.collection.mjs";
14
23
  import * as dom from "./combobox.dom.mjs";
@@ -149,7 +158,7 @@ var machine = createMachine({
149
158
  action(["syncInputValue"]);
150
159
  });
151
160
  track([() => context.get("highlightedValue")], () => {
152
- action(["syncHighlightedItem", "autofillInputValue"]);
161
+ action(["syncHighlightedItem", "autofillInputValue", "announceHighlightedItem"]);
153
162
  });
154
163
  track([() => prop("open")], () => {
155
164
  action(["toggleVisibility"]);
@@ -360,7 +369,13 @@ var machine = createMachine({
360
369
  open: {
361
370
  tags: ["open", "focused"],
362
371
  entry: ["setInitialFocus"],
363
- effects: ["trackFocusVisible", "scrollToHighlightedItem", "trackDismissableLayer", "trackPlacement"],
372
+ effects: [
373
+ "trackFocusVisible",
374
+ "scrollToHighlightedItem",
375
+ "trackDismissableLayer",
376
+ "trackPlacement",
377
+ "trackLiveRegion"
378
+ ],
364
379
  on: {
365
380
  "CONTROLLED.CLOSE": [
366
381
  {
@@ -645,6 +660,14 @@ var machine = createMachine({
645
660
  }
646
661
  });
647
662
  },
663
+ trackLiveRegion({ refs, scope }) {
664
+ const liveRegion = createLiveRegion({
665
+ level: "assertive",
666
+ document: scope.getDoc()
667
+ });
668
+ refs.set("liveRegion", liveRegion);
669
+ return () => liveRegion.destroy();
670
+ },
648
671
  trackPlacement({ context, prop, scope }) {
649
672
  const anchorEl = () => dom.getControlEl(scope) || dom.getTriggerEl(scope);
650
673
  const positionerEl = () => dom.getPositionerEl(scope);
@@ -967,6 +990,14 @@ var machine = createMachine({
967
990
  const item = prop("collection").find(context.get("highlightedValue"));
968
991
  context.set("highlightedItem", item);
969
992
  },
993
+ announceHighlightedItem({ context, prop, refs }) {
994
+ if (!isApple()) return;
995
+ const value = context.get("highlightedValue");
996
+ const optionText = value ? prop("collection").stringifyItem(prop("collection").find(value)) : null;
997
+ if (!optionText) return;
998
+ const isSelected = value ? context.get("value").includes(value) : false;
999
+ refs.get("liveRegion")?.announce(isSelected ? `${optionText}, selected` : optionText);
1000
+ },
970
1001
  toggleVisibility({ event, send, prop }) {
971
1002
  send({ type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: event });
972
1003
  }
@@ -4,6 +4,7 @@ import '@zag-js/core';
4
4
  import '@zag-js/dismissable';
5
5
  import '@zag-js/popper';
6
6
  import '@zag-js/types';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare const props: (keyof ComboboxProps<any>)[];
9
10
  declare const splitProps: <Props extends Partial<ComboboxProps<any>>>(props: Props) => [Partial<ComboboxProps<any>>, Omit<Props, keyof ComboboxProps<any>>];
@@ -4,6 +4,7 @@ import '@zag-js/core';
4
4
  import '@zag-js/dismissable';
5
5
  import '@zag-js/popper';
6
6
  import '@zag-js/types';
7
+ import '@zag-js/live-region';
7
8
 
8
9
  declare const props: (keyof ComboboxProps<any>)[];
9
10
  declare const splitProps: <Props extends Partial<ComboboxProps<any>>>(props: Props) => [Partial<ComboboxProps<any>>, Omit<Props, keyof ComboboxProps<any>>];
@@ -5,6 +5,7 @@ import { InteractOutsideHandlers } from '@zag-js/dismissable';
5
5
  import { PositioningOptions, Placement } from '@zag-js/popper';
6
6
  export { Placement, PositioningOptions } from '@zag-js/popper';
7
7
  import { RequiredBy, DirectionProperty, CommonProperties, PropTypes } from '@zag-js/types';
8
+ import { LiveRegion } from '@zag-js/live-region';
8
9
 
9
10
  interface ValueChangeDetails<T extends CollectionItem = CollectionItem> {
10
11
  value: string[];
@@ -263,6 +264,9 @@ interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
263
264
  highlightedItem: T | null;
264
265
  selectedItemMap: Map<string, T>;
265
266
  };
267
+ refs: {
268
+ liveRegion: LiveRegion | null;
269
+ };
266
270
  computed: {
267
271
  isCustomValue: boolean;
268
272
  isInputValueEmpty: boolean;
@@ -5,6 +5,7 @@ import { InteractOutsideHandlers } from '@zag-js/dismissable';
5
5
  import { PositioningOptions, Placement } from '@zag-js/popper';
6
6
  export { Placement, PositioningOptions } from '@zag-js/popper';
7
7
  import { RequiredBy, DirectionProperty, CommonProperties, PropTypes } from '@zag-js/types';
8
+ import { LiveRegion } from '@zag-js/live-region';
8
9
 
9
10
  interface ValueChangeDetails<T extends CollectionItem = CollectionItem> {
10
11
  value: string[];
@@ -263,6 +264,9 @@ interface ComboboxSchema<T extends CollectionItem = CollectionItem> {
263
264
  highlightedItem: T | null;
264
265
  selectedItemMap: Map<string, T>;
265
266
  };
267
+ refs: {
268
+ liveRegion: LiveRegion | null;
269
+ };
266
270
  computed: {
267
271
  isCustomValue: boolean;
268
272
  isInputValueEmpty: boolean;
package/dist/index.d.mts CHANGED
@@ -10,3 +10,4 @@ export { Placement, PositioningOptions } from '@zag-js/popper';
10
10
  import '@zag-js/anatomy';
11
11
  import '@zag-js/types';
12
12
  import '@zag-js/core';
13
+ import '@zag-js/live-region';
package/dist/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export { Placement, PositioningOptions } from '@zag-js/popper';
10
10
  import '@zag-js/anatomy';
11
11
  import '@zag-js/types';
12
12
  import '@zag-js/core';
13
+ import '@zag-js/live-region';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/combobox",
3
- "version": "1.39.0",
3
+ "version": "1.40.0",
4
4
  "description": "Core logic for the combobox widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,16 +26,16 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.39.0",
30
- "@zag-js/aria-hidden": "1.39.0",
31
- "@zag-js/collection": "1.39.0",
32
- "@zag-js/core": "1.39.0",
33
- "@zag-js/dismissable": "1.39.0",
34
- "@zag-js/dom-query": "1.39.0",
35
- "@zag-js/focus-visible": "1.39.0",
36
- "@zag-js/popper": "1.39.0",
37
- "@zag-js/types": "1.39.0",
38
- "@zag-js/utils": "1.39.0"
29
+ "@zag-js/anatomy": "1.40.0",
30
+ "@zag-js/collection": "1.40.0",
31
+ "@zag-js/core": "1.40.0",
32
+ "@zag-js/dismissable": "1.40.0",
33
+ "@zag-js/dom-query": "1.40.0",
34
+ "@zag-js/live-region": "1.40.0",
35
+ "@zag-js/popper": "1.40.0",
36
+ "@zag-js/types": "1.40.0",
37
+ "@zag-js/focus-visible": "1.40.0",
38
+ "@zag-js/utils": "1.40.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "clean-package": "2.2.0"