@zag-js/combobox 0.75.0 → 0.76.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.
Files changed (3) hide show
  1. package/dist/index.js +21 -17
  2. package/dist/index.mjs +21 -17
  3. package/package.json +11 -11
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, true));
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, true));
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,20 @@ function machine(userContext) {
1324
1330
  }
1325
1331
  );
1326
1332
  }
1333
+ function getInputValue(ctx, selection) {
1334
+ if (ctx.getSelectionValue && selection) {
1335
+ return ctx.getSelectionValue({
1336
+ inputValue: ctx.inputValue,
1337
+ selectedItems: Array.from(ctx.selectedItems),
1338
+ valueAsString: ctx.valueAsString
1339
+ });
1340
+ }
1341
+ return utils.match(ctx.selectionBehavior, {
1342
+ preserve: ctx.inputValue,
1343
+ replace: ctx.valueAsString,
1344
+ clear: ""
1345
+ });
1346
+ }
1327
1347
  var sync = {
1328
1348
  valueChange: (ctx) => {
1329
1349
  const prevSelectedItems = ctx.selectedItems;
@@ -1332,23 +1352,7 @@ var sync = {
1332
1352
  if (foundItem) return foundItem;
1333
1353
  return ctx.collection.find(v);
1334
1354
  });
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);
1355
+ ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1352
1356
  },
1353
1357
  highlightChange: (ctx) => {
1354
1358
  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, true));
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, true));
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,20 @@ function machine(userContext) {
1322
1328
  }
1323
1329
  );
1324
1330
  }
1331
+ function getInputValue(ctx, selection) {
1332
+ if (ctx.getSelectionValue && selection) {
1333
+ return ctx.getSelectionValue({
1334
+ inputValue: ctx.inputValue,
1335
+ selectedItems: Array.from(ctx.selectedItems),
1336
+ valueAsString: ctx.valueAsString
1337
+ });
1338
+ }
1339
+ return match(ctx.selectionBehavior, {
1340
+ preserve: ctx.inputValue,
1341
+ replace: ctx.valueAsString,
1342
+ clear: ""
1343
+ });
1344
+ }
1325
1345
  var sync = {
1326
1346
  valueChange: (ctx) => {
1327
1347
  const prevSelectedItems = ctx.selectedItems;
@@ -1330,23 +1350,7 @@ var sync = {
1330
1350
  if (foundItem) return foundItem;
1331
1351
  return ctx.collection.find(v);
1332
1352
  });
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);
1353
+ ctx.valueAsString = ctx.collection.stringifyItems(ctx.selectedItems);
1350
1354
  },
1351
1355
  highlightChange: (ctx) => {
1352
1356
  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.76.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.76.0",
30
+ "@zag-js/aria-hidden": "0.76.0",
31
+ "@zag-js/collection": "0.76.0",
32
+ "@zag-js/core": "0.76.0",
33
+ "@zag-js/dismissable": "0.76.0",
34
+ "@zag-js/dom-query": "0.76.0",
35
+ "@zag-js/dom-event": "0.76.0",
36
+ "@zag-js/utils": "0.76.0",
37
+ "@zag-js/popper": "0.76.0",
38
+ "@zag-js/types": "0.76.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "clean-package": "2.2.0"