@zag-js/combobox 1.22.1 → 1.24.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
@@ -180,6 +180,12 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
180
180
  * Whether to allow typing custom values in the input
181
181
  */
182
182
  allowCustomValue?: boolean | undefined;
183
+ /**
184
+ * Whether to always submit on Enter key press, even if popup is open.
185
+ * Useful for single-field autocomplete forms where Enter should submit the form.
186
+ * @default false
187
+ */
188
+ alwaysSubmitOnEnter?: boolean | undefined;
183
189
  /**
184
190
  * Whether to loop the keyboard navigation through the items
185
191
  * @default true
package/dist/index.d.ts CHANGED
@@ -180,6 +180,12 @@ interface ComboboxProps<T extends CollectionItem = CollectionItem> extends Direc
180
180
  * Whether to allow typing custom values in the input
181
181
  */
182
182
  allowCustomValue?: boolean | undefined;
183
+ /**
184
+ * Whether to always submit on Enter key press, even if popup is open.
185
+ * Useful for single-field autocomplete forms where Enter should submit the form.
186
+ * @default false
187
+ */
188
+ alwaysSubmitOnEnter?: boolean | undefined;
183
189
  /**
184
190
  * Whether to loop the keyboard navigation through the items
185
191
  * @default true
package/dist/index.js CHANGED
@@ -72,10 +72,11 @@ function connect(service, normalize) {
72
72
  const { context, prop, state, send, scope, computed, event } = service;
73
73
  const translations = prop("translations");
74
74
  const collection2 = prop("collection");
75
- const disabled = prop("disabled");
75
+ const disabled = !!prop("disabled");
76
76
  const interactive = computed("isInteractive");
77
- const invalid = prop("invalid");
78
- const readOnly = prop("readOnly");
77
+ const invalid = !!prop("invalid");
78
+ const required = !!prop("required");
79
+ const readOnly = !!prop("readOnly");
79
80
  const open = state.hasTag("open");
80
81
  const focused = state.hasTag("focused");
81
82
  const composite = prop("composite");
@@ -162,6 +163,7 @@ function connect(service, normalize) {
162
163
  "data-readonly": domQuery.dataAttr(readOnly),
163
164
  "data-disabled": domQuery.dataAttr(disabled),
164
165
  "data-invalid": domQuery.dataAttr(invalid),
166
+ "data-required": domQuery.dataAttr(required),
165
167
  "data-focus": domQuery.dataAttr(focused),
166
168
  onClick(event2) {
167
169
  if (composite) return;
@@ -267,7 +269,9 @@ function connect(service, normalize) {
267
269
  Enter(event3) {
268
270
  send({ type: "INPUT.ENTER", keypress, src: "item-select" });
269
271
  const submittable = computed("isCustomValue") && prop("allowCustomValue");
270
- if (open && !submittable) {
272
+ const hasHighlight = highlightedValue != null;
273
+ const alwaysSubmit = prop("alwaysSubmitOnEnter");
274
+ if (open && !submittable && !alwaysSubmit && hasHighlight) {
271
275
  event3.preventDefault();
272
276
  }
273
277
  if (highlightedValue == null) return;
@@ -484,6 +488,7 @@ var machine = createMachine({
484
488
  defaultValue: [],
485
489
  closeOnSelect: !props2.multiple,
486
490
  allowCustomValue: false,
491
+ alwaysSubmitOnEnter: false,
487
492
  inputBehavior: "none",
488
493
  selectionBehavior: props2.multiple ? "clear" : "replace",
489
494
  openOnKeyPress: true,
@@ -1152,6 +1157,7 @@ var machine = createMachine({
1152
1157
  if (prop("disableLayer")) return;
1153
1158
  const contentEl = () => getContentEl(scope);
1154
1159
  return dismissable.trackDismissableElement(contentEl, {
1160
+ type: "listbox",
1155
1161
  defer: true,
1156
1162
  exclude: () => [getInputEl(scope), getTriggerEl(scope), getClearTriggerEl(scope)],
1157
1163
  onFocusOutside: prop("onFocusOutside"),
@@ -1549,7 +1555,8 @@ var props = types.createProps()([
1549
1555
  "scrollToIndexFn",
1550
1556
  "selectionBehavior",
1551
1557
  "translations",
1552
- "value"
1558
+ "value",
1559
+ "alwaysSubmitOnEnter"
1553
1560
  ]);
1554
1561
  var splitProps = utils.createSplitProps(props);
1555
1562
  var itemGroupLabelProps = types.createProps()(["htmlFor"]);
package/dist/index.mjs CHANGED
@@ -70,10 +70,11 @@ function connect(service, normalize) {
70
70
  const { context, prop, state, send, scope, computed, event } = service;
71
71
  const translations = prop("translations");
72
72
  const collection2 = prop("collection");
73
- const disabled = prop("disabled");
73
+ const disabled = !!prop("disabled");
74
74
  const interactive = computed("isInteractive");
75
- const invalid = prop("invalid");
76
- const readOnly = prop("readOnly");
75
+ const invalid = !!prop("invalid");
76
+ const required = !!prop("required");
77
+ const readOnly = !!prop("readOnly");
77
78
  const open = state.hasTag("open");
78
79
  const focused = state.hasTag("focused");
79
80
  const composite = prop("composite");
@@ -160,6 +161,7 @@ function connect(service, normalize) {
160
161
  "data-readonly": dataAttr(readOnly),
161
162
  "data-disabled": dataAttr(disabled),
162
163
  "data-invalid": dataAttr(invalid),
164
+ "data-required": dataAttr(required),
163
165
  "data-focus": dataAttr(focused),
164
166
  onClick(event2) {
165
167
  if (composite) return;
@@ -265,7 +267,9 @@ function connect(service, normalize) {
265
267
  Enter(event3) {
266
268
  send({ type: "INPUT.ENTER", keypress, src: "item-select" });
267
269
  const submittable = computed("isCustomValue") && prop("allowCustomValue");
268
- if (open && !submittable) {
270
+ const hasHighlight = highlightedValue != null;
271
+ const alwaysSubmit = prop("alwaysSubmitOnEnter");
272
+ if (open && !submittable && !alwaysSubmit && hasHighlight) {
269
273
  event3.preventDefault();
270
274
  }
271
275
  if (highlightedValue == null) return;
@@ -482,6 +486,7 @@ var machine = createMachine({
482
486
  defaultValue: [],
483
487
  closeOnSelect: !props2.multiple,
484
488
  allowCustomValue: false,
489
+ alwaysSubmitOnEnter: false,
485
490
  inputBehavior: "none",
486
491
  selectionBehavior: props2.multiple ? "clear" : "replace",
487
492
  openOnKeyPress: true,
@@ -1150,6 +1155,7 @@ var machine = createMachine({
1150
1155
  if (prop("disableLayer")) return;
1151
1156
  const contentEl = () => getContentEl(scope);
1152
1157
  return trackDismissableElement(contentEl, {
1158
+ type: "listbox",
1153
1159
  defer: true,
1154
1160
  exclude: () => [getInputEl(scope), getTriggerEl(scope), getClearTriggerEl(scope)],
1155
1161
  onFocusOutside: prop("onFocusOutside"),
@@ -1547,7 +1553,8 @@ var props = createProps()([
1547
1553
  "scrollToIndexFn",
1548
1554
  "selectionBehavior",
1549
1555
  "translations",
1550
- "value"
1556
+ "value",
1557
+ "alwaysSubmitOnEnter"
1551
1558
  ]);
1552
1559
  var splitProps = createSplitProps(props);
1553
1560
  var itemGroupLabelProps = createProps()(["htmlFor"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/combobox",
3
- "version": "1.22.1",
3
+ "version": "1.24.0",
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.22.1",
30
- "@zag-js/aria-hidden": "1.22.1",
31
- "@zag-js/collection": "1.22.1",
32
- "@zag-js/core": "1.22.1",
33
- "@zag-js/dismissable": "1.22.1",
34
- "@zag-js/dom-query": "1.22.1",
35
- "@zag-js/utils": "1.22.1",
36
- "@zag-js/popper": "1.22.1",
37
- "@zag-js/types": "1.22.1"
29
+ "@zag-js/anatomy": "1.24.0",
30
+ "@zag-js/aria-hidden": "1.24.0",
31
+ "@zag-js/collection": "1.24.0",
32
+ "@zag-js/core": "1.24.0",
33
+ "@zag-js/dismissable": "1.24.0",
34
+ "@zag-js/dom-query": "1.24.0",
35
+ "@zag-js/utils": "1.24.0",
36
+ "@zag-js/popper": "1.24.0",
37
+ "@zag-js/types": "1.24.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "clean-package": "2.2.0"