@zag-js/combobox 0.75.0 → 0.77.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
@@ -30,11 +30,6 @@ interface InputValueChangeDetails {
30
30
  interface OpenChangeDetails {
31
31
  open: boolean;
32
32
  }
33
- interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
34
- inputValue: string;
35
- selectedItems: T[];
36
- valueAsString: string;
37
- }
38
33
  interface ScrollToIndexDetails {
39
34
  index: number;
40
35
  immediate?: boolean | undefined;
@@ -192,10 +187,6 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
192
187
  * Whether to close the combobox when an item is selected.
193
188
  */
194
189
  closeOnSelect?: boolean | undefined;
195
- /**
196
- * Function to get the display value of the selected item
197
- */
198
- getSelectionValue?: ((details: SelectionValueDetails<T>) => string) | undefined;
199
190
  /**
200
191
  * Whether to open the combobox on arrow key press
201
192
  * @default true
@@ -415,4 +406,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
415
406
 
416
407
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
417
408
 
418
- 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 SelectionValueDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
409
+ 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 };
package/dist/index.d.ts CHANGED
@@ -30,11 +30,6 @@ interface InputValueChangeDetails {
30
30
  interface OpenChangeDetails {
31
31
  open: boolean;
32
32
  }
33
- interface SelectionValueDetails<T extends CollectionItem = CollectionItem> {
34
- inputValue: string;
35
- selectedItems: T[];
36
- valueAsString: string;
37
- }
38
33
  interface ScrollToIndexDetails {
39
34
  index: number;
40
35
  immediate?: boolean | undefined;
@@ -192,10 +187,6 @@ interface PublicContext<T extends CollectionItem = CollectionItem> extends Direc
192
187
  * Whether to close the combobox when an item is selected.
193
188
  */
194
189
  closeOnSelect?: boolean | undefined;
195
- /**
196
- * Function to get the display value of the selected item
197
- */
198
- getSelectionValue?: ((details: SelectionValueDetails<T>) => string) | undefined;
199
190
  /**
200
191
  * Whether to open the combobox on arrow key press
201
192
  * @default true
@@ -415,4 +406,4 @@ declare function connect<T extends PropTypes, V extends CollectionItem>(state: S
415
406
 
416
407
  declare function machine<T extends CollectionItem>(userContext: UserDefinedContext<T>): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
417
408
 
418
- 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 SelectionValueDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, collection, connect, machine };
409
+ 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 };
package/dist/index.js CHANGED
@@ -1143,15 +1143,18 @@ function machine(userContext) {
1143
1143
  },
1144
1144
  selectHighlightedItem(ctx2) {
1145
1145
  set.value(ctx2, ctx2.highlightedValue);
1146
+ set.inputValue(ctx2, getInputValue(ctx2));
1146
1147
  },
1147
1148
  selectItem(ctx2, evt) {
1148
1149
  if (evt.value == null) return;
1149
1150
  set.value(ctx2, evt.value);
1151
+ set.inputValue(ctx2, getInputValue(ctx2));
1150
1152
  },
1151
1153
  clearItem(ctx2, evt) {
1152
1154
  if (evt.value == null) return;
1153
1155
  const value = ctx2.value.filter((v) => v !== evt.value);
1154
1156
  set.value(ctx2, value);
1157
+ set.inputValue(ctx2, getInputValue(ctx2));
1155
1158
  },
1156
1159
  setInitialFocus(ctx2) {
1157
1160
  domQuery.raf(() => {
@@ -1214,9 +1217,11 @@ function machine(userContext) {
1214
1217
  setSelectedItems(ctx2, evt) {
1215
1218
  if (!utils.isArray(evt.value)) return;
1216
1219
  set.value(ctx2, evt.value);
1220
+ set.inputValue(ctx2, getInputValue(ctx2));
1217
1221
  },
1218
1222
  clearSelectedItems(ctx2) {
1219
1223
  set.value(ctx2, []);
1224
+ set.inputValue(ctx2, getInputValue(ctx2));
1220
1225
  },
1221
1226
  scrollContentToTop(ctx2) {
1222
1227
  if (ctx2.scrollToIndexFn) {
@@ -1313,6 +1318,7 @@ function machine(userContext) {
1313
1318
  },
1314
1319
  syncSelectedItems(ctx2) {
1315
1320
  sync.valueChange(ctx2);
1321
+ set.inputValue(ctx2, getInputValue(ctx2));
1316
1322
  },
1317
1323
  syncHighlightedItem(ctx2) {
1318
1324
  sync.highlightChange(ctx2);
@@ -1324,6 +1330,13 @@ function machine(userContext) {
1324
1330
  }
1325
1331
  );
1326
1332
  }
1333
+ function getInputValue(ctx) {
1334
+ return utils.match(ctx.selectionBehavior, {
1335
+ preserve: ctx.inputValue,
1336
+ replace: ctx.valueAsString,
1337
+ clear: ""
1338
+ });
1339
+ }
1327
1340
  var sync = {
1328
1341
  valueChange: (ctx) => {
1329
1342
  const prevSelectedItems = ctx.selectedItems;
@@ -1332,23 +1345,7 @@ var sync = {
1332
1345
  if (foundItem) return foundItem;
1333
1346
  return ctx.collection.find(v);
1334
1347
  });
1335
- const valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1336
- ctx.valueAsString = valueAsString;
1337
- let inputValue;
1338
- if (ctx.getSelectionValue) {
1339
- inputValue = ctx.getSelectionValue({
1340
- inputValue: ctx.inputValue,
1341
- selectedItems: Array.from(ctx.selectedItems),
1342
- valueAsString
1343
- });
1344
- } else {
1345
- inputValue = utils.match(ctx.selectionBehavior, {
1346
- replace: ctx.valueAsString,
1347
- preserve: ctx.inputValue,
1348
- clear: ""
1349
- });
1350
- }
1351
- set.inputValue(ctx, inputValue);
1348
+ ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1352
1349
  },
1353
1350
  highlightChange: (ctx) => {
1354
1351
  ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue);
package/dist/index.mjs CHANGED
@@ -1141,15 +1141,18 @@ function machine(userContext) {
1141
1141
  },
1142
1142
  selectHighlightedItem(ctx2) {
1143
1143
  set.value(ctx2, ctx2.highlightedValue);
1144
+ set.inputValue(ctx2, getInputValue(ctx2));
1144
1145
  },
1145
1146
  selectItem(ctx2, evt) {
1146
1147
  if (evt.value == null) return;
1147
1148
  set.value(ctx2, evt.value);
1149
+ set.inputValue(ctx2, getInputValue(ctx2));
1148
1150
  },
1149
1151
  clearItem(ctx2, evt) {
1150
1152
  if (evt.value == null) return;
1151
1153
  const value = ctx2.value.filter((v) => v !== evt.value);
1152
1154
  set.value(ctx2, value);
1155
+ set.inputValue(ctx2, getInputValue(ctx2));
1153
1156
  },
1154
1157
  setInitialFocus(ctx2) {
1155
1158
  raf(() => {
@@ -1212,9 +1215,11 @@ function machine(userContext) {
1212
1215
  setSelectedItems(ctx2, evt) {
1213
1216
  if (!isArray(evt.value)) return;
1214
1217
  set.value(ctx2, evt.value);
1218
+ set.inputValue(ctx2, getInputValue(ctx2));
1215
1219
  },
1216
1220
  clearSelectedItems(ctx2) {
1217
1221
  set.value(ctx2, []);
1222
+ set.inputValue(ctx2, getInputValue(ctx2));
1218
1223
  },
1219
1224
  scrollContentToTop(ctx2) {
1220
1225
  if (ctx2.scrollToIndexFn) {
@@ -1311,6 +1316,7 @@ function machine(userContext) {
1311
1316
  },
1312
1317
  syncSelectedItems(ctx2) {
1313
1318
  sync.valueChange(ctx2);
1319
+ set.inputValue(ctx2, getInputValue(ctx2));
1314
1320
  },
1315
1321
  syncHighlightedItem(ctx2) {
1316
1322
  sync.highlightChange(ctx2);
@@ -1322,6 +1328,13 @@ function machine(userContext) {
1322
1328
  }
1323
1329
  );
1324
1330
  }
1331
+ function getInputValue(ctx) {
1332
+ return match(ctx.selectionBehavior, {
1333
+ preserve: ctx.inputValue,
1334
+ replace: ctx.valueAsString,
1335
+ clear: ""
1336
+ });
1337
+ }
1325
1338
  var sync = {
1326
1339
  valueChange: (ctx) => {
1327
1340
  const prevSelectedItems = ctx.selectedItems;
@@ -1330,23 +1343,7 @@ var sync = {
1330
1343
  if (foundItem) return foundItem;
1331
1344
  return ctx.collection.find(v);
1332
1345
  });
1333
- const valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1334
- ctx.valueAsString = valueAsString;
1335
- let inputValue;
1336
- if (ctx.getSelectionValue) {
1337
- inputValue = ctx.getSelectionValue({
1338
- inputValue: ctx.inputValue,
1339
- selectedItems: Array.from(ctx.selectedItems),
1340
- valueAsString
1341
- });
1342
- } else {
1343
- inputValue = match(ctx.selectionBehavior, {
1344
- replace: ctx.valueAsString,
1345
- preserve: ctx.inputValue,
1346
- clear: ""
1347
- });
1348
- }
1349
- set.inputValue(ctx, inputValue);
1346
+ ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1350
1347
  },
1351
1348
  highlightChange: (ctx) => {
1352
1349
  ctx.highlightedItem = ctx.collection.find(ctx.highlightedValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/combobox",
3
- "version": "0.75.0",
3
+ "version": "0.77.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": "0.75.0",
30
- "@zag-js/aria-hidden": "0.75.0",
31
- "@zag-js/collection": "0.75.0",
32
- "@zag-js/core": "0.75.0",
33
- "@zag-js/dismissable": "0.75.0",
34
- "@zag-js/dom-query": "0.75.0",
35
- "@zag-js/dom-event": "0.75.0",
36
- "@zag-js/utils": "0.75.0",
37
- "@zag-js/popper": "0.75.0",
38
- "@zag-js/types": "0.75.0"
29
+ "@zag-js/anatomy": "0.77.0",
30
+ "@zag-js/aria-hidden": "0.77.0",
31
+ "@zag-js/collection": "0.77.0",
32
+ "@zag-js/core": "0.77.0",
33
+ "@zag-js/dismissable": "0.77.0",
34
+ "@zag-js/dom-query": "0.77.0",
35
+ "@zag-js/dom-event": "0.77.0",
36
+ "@zag-js/utils": "0.77.0",
37
+ "@zag-js/popper": "0.77.0",
38
+ "@zag-js/types": "0.77.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "clean-package": "2.2.0"