@yamada-ui/autocomplete 1.2.2 → 1.2.3-dev-20240614141936
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/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.js +4 -8
- package/dist/autocomplete-list.js.map +1 -1
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.js +6 -12
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.js +49 -98
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-ORNAXQ6Z.mjs → chunk-JRUGH6ID.mjs} +52 -103
- package/dist/{chunk-ORNAXQ6Z.mjs.map → chunk-JRUGH6ID.mjs.map} +1 -1
- package/dist/index.js +51 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.js +51 -102
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/use-autocomplete.js +49 -98
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +6 -6
|
@@ -584,15 +584,13 @@ var MultiAutocompleteField = forwardRef7(
|
|
|
584
584
|
const { value, label, inputValue, onChange, isOpen, inputRef, styles } = useAutocompleteContext();
|
|
585
585
|
const { getInputProps } = useAutocompleteInput();
|
|
586
586
|
const cloneChildren = useMemo(() => {
|
|
587
|
-
if (!(label == null ? void 0 : label.length))
|
|
588
|
-
return null;
|
|
587
|
+
if (!(label == null ? void 0 : label.length)) return null;
|
|
589
588
|
if (component) {
|
|
590
589
|
return label.map((label2, index) => {
|
|
591
590
|
const onRemove = (ev) => {
|
|
592
591
|
ev.stopPropagation();
|
|
593
592
|
onChange(value[index]);
|
|
594
|
-
if (inputRef.current)
|
|
595
|
-
inputRef.current.focus();
|
|
593
|
+
if (inputRef.current) inputRef.current.focus();
|
|
596
594
|
};
|
|
597
595
|
const el = component({
|
|
598
596
|
value: value[index],
|
|
@@ -764,8 +762,7 @@ var flattenItems = (items) => {
|
|
|
764
762
|
var _a;
|
|
765
763
|
const { isDisabled, isFocusable } = item;
|
|
766
764
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
767
|
-
if (trulyDisabled)
|
|
768
|
-
return;
|
|
765
|
+
if (trulyDisabled) return;
|
|
769
766
|
if ("items" in item) {
|
|
770
767
|
return filterItems((_a = item.items) != null ? _a : []);
|
|
771
768
|
} else {
|
|
@@ -900,23 +897,18 @@ var useAutocomplete = ({
|
|
|
900
897
|
});
|
|
901
898
|
const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
|
|
902
899
|
const onOpen = useCallback(() => {
|
|
903
|
-
if (formControlProps.disabled || formControlProps.readOnly)
|
|
904
|
-
|
|
905
|
-
if (!allowCreate && (isEmpty || isAllSelected))
|
|
906
|
-
return;
|
|
900
|
+
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
901
|
+
if (!allowCreate && (isEmpty || isAllSelected)) return;
|
|
907
902
|
onInternalOpen();
|
|
908
|
-
if (inputRef.current)
|
|
909
|
-
inputRef.current.focus();
|
|
903
|
+
if (inputRef.current) inputRef.current.focus();
|
|
910
904
|
}, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
|
|
911
905
|
const onFocusFirst = useCallback(() => {
|
|
912
906
|
const id2 = setTimeout(() => {
|
|
913
|
-
if (isEmpty || isAllSelected)
|
|
914
|
-
return;
|
|
907
|
+
if (isEmpty || isAllSelected) return;
|
|
915
908
|
const first = descendants.enabledFirstValue(
|
|
916
909
|
({ node }) => "target" in node.dataset
|
|
917
910
|
);
|
|
918
|
-
if (!first)
|
|
919
|
-
return;
|
|
911
|
+
if (!first) return;
|
|
920
912
|
if (!isMulti || !omitSelectedValues) {
|
|
921
913
|
setFocusedIndex(first.index);
|
|
922
914
|
} else {
|
|
@@ -940,13 +932,11 @@ var useAutocomplete = ({
|
|
|
940
932
|
]);
|
|
941
933
|
const onFocusLast = useCallback(() => {
|
|
942
934
|
const id2 = setTimeout(() => {
|
|
943
|
-
if (isEmpty || isAllSelected)
|
|
944
|
-
return;
|
|
935
|
+
if (isEmpty || isAllSelected) return;
|
|
945
936
|
const last = descendants.enabledLastValue(
|
|
946
937
|
({ node }) => "target" in node.dataset
|
|
947
938
|
);
|
|
948
|
-
if (!last)
|
|
949
|
-
return;
|
|
939
|
+
if (!last) return;
|
|
950
940
|
if (!isMulti || !omitSelectedValues) {
|
|
951
941
|
setFocusedIndex(last.index);
|
|
952
942
|
} else {
|
|
@@ -977,8 +967,7 @@ var useAutocomplete = ({
|
|
|
977
967
|
return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
978
968
|
}
|
|
979
969
|
);
|
|
980
|
-
if (selected)
|
|
981
|
-
setFocusedIndex(selected.index);
|
|
970
|
+
if (selected) setFocusedIndex(selected.index);
|
|
982
971
|
});
|
|
983
972
|
timeoutIds.current.add(id2);
|
|
984
973
|
}, [descendants, isMulti, value]);
|
|
@@ -990,8 +979,7 @@ var useAutocomplete = ({
|
|
|
990
979
|
index,
|
|
991
980
|
({ node }) => "target" in node.dataset
|
|
992
981
|
);
|
|
993
|
-
if (!next)
|
|
994
|
-
return;
|
|
982
|
+
if (!next) return;
|
|
995
983
|
if (!isMulti || !omitSelectedValues) {
|
|
996
984
|
setFocusedIndex(next.index);
|
|
997
985
|
} else {
|
|
@@ -1022,8 +1010,7 @@ var useAutocomplete = ({
|
|
|
1022
1010
|
index,
|
|
1023
1011
|
({ node }) => "target" in node.dataset
|
|
1024
1012
|
);
|
|
1025
|
-
if (!prev)
|
|
1026
|
-
return;
|
|
1013
|
+
if (!prev) return;
|
|
1027
1014
|
if (!isMulti || !omitSelectedValues) {
|
|
1028
1015
|
setFocusedIndex(prev.index);
|
|
1029
1016
|
} else {
|
|
@@ -1077,8 +1064,7 @@ var useAutocomplete = ({
|
|
|
1077
1064
|
values.forEach(({ node }) => {
|
|
1078
1065
|
node.dataset.target = "";
|
|
1079
1066
|
});
|
|
1080
|
-
if (runFocus)
|
|
1081
|
-
onFocusFirst();
|
|
1067
|
+
if (runFocus) onFocusFirst();
|
|
1082
1068
|
setIsHit(true);
|
|
1083
1069
|
},
|
|
1084
1070
|
[descendants, onFocusFirst]
|
|
@@ -1148,10 +1134,8 @@ var useAutocomplete = ({
|
|
|
1148
1134
|
}
|
|
1149
1135
|
).length > 0;
|
|
1150
1136
|
onChangeLabel(newValue);
|
|
1151
|
-
if (allowFree || isHit2)
|
|
1152
|
-
|
|
1153
|
-
if (isMulti && runRebirth)
|
|
1154
|
-
rebirthOptions(false);
|
|
1137
|
+
if (allowFree || isHit2) setInputValue("");
|
|
1138
|
+
if (isMulti && runRebirth) rebirthOptions(false);
|
|
1155
1139
|
},
|
|
1156
1140
|
[
|
|
1157
1141
|
allowFree,
|
|
@@ -1168,14 +1152,11 @@ var useAutocomplete = ({
|
|
|
1168
1152
|
let enabledValue = descendants.value(focusedIndex);
|
|
1169
1153
|
if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
|
|
1170
1154
|
enabledValue = void 0;
|
|
1171
|
-
if (!enabledValue)
|
|
1172
|
-
return;
|
|
1155
|
+
if (!enabledValue) return;
|
|
1173
1156
|
const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
|
|
1174
1157
|
onChange(value2);
|
|
1175
|
-
if (closeOnSelect)
|
|
1176
|
-
|
|
1177
|
-
if (omitSelectedValues)
|
|
1178
|
-
onFocusNext();
|
|
1158
|
+
if (closeOnSelect) onClose();
|
|
1159
|
+
if (omitSelectedValues) onFocusNext();
|
|
1179
1160
|
}, [
|
|
1180
1161
|
closeOnSelect,
|
|
1181
1162
|
descendants,
|
|
@@ -1187,8 +1168,7 @@ var useAutocomplete = ({
|
|
|
1187
1168
|
]);
|
|
1188
1169
|
const onSearch = useCallback(
|
|
1189
1170
|
(ev) => {
|
|
1190
|
-
if (!isOpen)
|
|
1191
|
-
onOpen();
|
|
1171
|
+
if (!isOpen) onOpen();
|
|
1192
1172
|
onSearchProp == null ? void 0 : onSearchProp(ev);
|
|
1193
1173
|
const value2 = ev.target.value;
|
|
1194
1174
|
const computedValue = format(value2);
|
|
@@ -1209,12 +1189,10 @@ var useAutocomplete = ({
|
|
|
1209
1189
|
}, []);
|
|
1210
1190
|
const onCreate = useCallback(() => {
|
|
1211
1191
|
var _a, _b;
|
|
1212
|
-
if (!listRef.current)
|
|
1213
|
-
return;
|
|
1192
|
+
if (!listRef.current) return;
|
|
1214
1193
|
const newItem = { label: inputValue, value: inputValue };
|
|
1215
1194
|
let newItems = [];
|
|
1216
|
-
if (resolvedItems)
|
|
1217
|
-
newItems = resolvedItems;
|
|
1195
|
+
if (resolvedItems) newItems = resolvedItems;
|
|
1218
1196
|
if (firstInsertPositionItem === "first") {
|
|
1219
1197
|
newItems = [newItem, ...newItems];
|
|
1220
1198
|
} else if (firstInsertPositionItem === "last") {
|
|
@@ -1257,31 +1235,25 @@ var useAutocomplete = ({
|
|
|
1257
1235
|
]);
|
|
1258
1236
|
const onClick = useCallback(() => {
|
|
1259
1237
|
if (isOpen) {
|
|
1260
|
-
if (inputRef.current)
|
|
1261
|
-
inputRef.current.focus();
|
|
1238
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1262
1239
|
} else {
|
|
1263
1240
|
onOpen();
|
|
1264
1241
|
onFocusFirstOrSelected();
|
|
1265
1242
|
}
|
|
1266
1243
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
1267
1244
|
const onFocus = useCallback(() => {
|
|
1268
|
-
if (isOpen)
|
|
1269
|
-
return;
|
|
1245
|
+
if (isOpen) return;
|
|
1270
1246
|
onOpen();
|
|
1271
1247
|
onFocusFirstOrSelected();
|
|
1272
1248
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
1273
1249
|
const onBlur = useCallback(
|
|
1274
1250
|
(ev) => {
|
|
1275
1251
|
const relatedTarget = getEventRelatedTarget(ev);
|
|
1276
|
-
if (isContains(containerRef.current, relatedTarget))
|
|
1277
|
-
|
|
1278
|
-
if (
|
|
1279
|
-
return;
|
|
1280
|
-
if (allowFree && !!inputValue)
|
|
1281
|
-
onChange(inputValue, false);
|
|
1252
|
+
if (isContains(containerRef.current, relatedTarget)) return;
|
|
1253
|
+
if (!closeOnBlur && isHit) return;
|
|
1254
|
+
if (allowFree && !!inputValue) onChange(inputValue, false);
|
|
1282
1255
|
setInputValue("");
|
|
1283
|
-
if (isOpen)
|
|
1284
|
-
onClose();
|
|
1256
|
+
if (isOpen) onClose();
|
|
1285
1257
|
},
|
|
1286
1258
|
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
1287
1259
|
);
|
|
@@ -1291,8 +1263,7 @@ var useAutocomplete = ({
|
|
|
1291
1263
|
} else {
|
|
1292
1264
|
onChange(value[value.length - 1]);
|
|
1293
1265
|
}
|
|
1294
|
-
if (!isOpen)
|
|
1295
|
-
onFocus();
|
|
1266
|
+
if (!isOpen) onFocus();
|
|
1296
1267
|
}, [isMulti, isOpen, onChange, onFocus, value]);
|
|
1297
1268
|
const onClear = useCallback(
|
|
1298
1269
|
(ev) => {
|
|
@@ -1302,27 +1273,22 @@ var useAutocomplete = ({
|
|
|
1302
1273
|
setLabel(void 0);
|
|
1303
1274
|
setInputValue("");
|
|
1304
1275
|
rebirthOptions();
|
|
1305
|
-
if (isOpen && inputRef.current)
|
|
1306
|
-
inputRef.current.focus();
|
|
1276
|
+
if (isOpen && inputRef.current) inputRef.current.focus();
|
|
1307
1277
|
},
|
|
1308
1278
|
[isOpen, setLabel, setInputValue, setValue, rebirthOptions]
|
|
1309
1279
|
);
|
|
1310
1280
|
const onKeyDown = useCallback(
|
|
1311
1281
|
(ev) => {
|
|
1312
|
-
if (ev.key === " ")
|
|
1313
|
-
|
|
1314
|
-
if (
|
|
1315
|
-
return;
|
|
1316
|
-
if (isComposition.current)
|
|
1317
|
-
return;
|
|
1282
|
+
if (ev.key === " ") ev.key = ev.code;
|
|
1283
|
+
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
1284
|
+
if (isComposition.current) return;
|
|
1318
1285
|
const enabledDelete = label === inputValue || !inputValue.length;
|
|
1319
1286
|
const actions = {
|
|
1320
1287
|
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1321
1288
|
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? funcAll(onOpen, onFocusLastOrSelected) : void 0,
|
|
1322
1289
|
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : void 0,
|
|
1323
1290
|
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? funcAll(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
1324
|
-
if (inputValue)
|
|
1325
|
-
onChange(inputValue);
|
|
1291
|
+
if (inputValue) onChange(inputValue);
|
|
1326
1292
|
setFocusedIndex(0);
|
|
1327
1293
|
} : void 0,
|
|
1328
1294
|
Home: isOpen ? onFocusFirst : void 0,
|
|
@@ -1331,8 +1297,7 @@ var useAutocomplete = ({
|
|
|
1331
1297
|
Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
|
|
1332
1298
|
};
|
|
1333
1299
|
const action = actions[ev.key];
|
|
1334
|
-
if (!action)
|
|
1335
|
-
return;
|
|
1300
|
+
if (!action) return;
|
|
1336
1301
|
ev.preventDefault();
|
|
1337
1302
|
ev.stopPropagation();
|
|
1338
1303
|
action(ev);
|
|
@@ -1363,10 +1328,8 @@ var useAutocomplete = ({
|
|
|
1363
1328
|
]
|
|
1364
1329
|
);
|
|
1365
1330
|
useEffect(() => {
|
|
1366
|
-
if (!isMulti)
|
|
1367
|
-
|
|
1368
|
-
if (!omitSelectedValues && isUndefined(maxSelectValues))
|
|
1369
|
-
return;
|
|
1331
|
+
if (!isMulti) return;
|
|
1332
|
+
if (!omitSelectedValues && isUndefined(maxSelectValues)) return;
|
|
1370
1333
|
const isAll = value.length > 0 && value.length === descendants.count();
|
|
1371
1334
|
const isMax = value.length === maxSelectValues;
|
|
1372
1335
|
if (isAll || isMax) {
|
|
@@ -1391,20 +1354,17 @@ var useAutocomplete = ({
|
|
|
1391
1354
|
const label2 = getSelectedValues(value);
|
|
1392
1355
|
setLabel(label2);
|
|
1393
1356
|
} else {
|
|
1394
|
-
if (prevValue.current === value)
|
|
1395
|
-
return;
|
|
1357
|
+
if (prevValue.current === value) return;
|
|
1396
1358
|
onChangeLabel(value, false);
|
|
1397
1359
|
}
|
|
1398
1360
|
}, [isMulti, value, onChangeLabel, getSelectedValues]);
|
|
1399
1361
|
useUpdateEffect(() => {
|
|
1400
|
-
if (isOpen || allowFree)
|
|
1401
|
-
return;
|
|
1362
|
+
if (isOpen || allowFree) return;
|
|
1402
1363
|
setFocusedIndex(-1);
|
|
1403
1364
|
setInputValue("");
|
|
1404
1365
|
}, [isOpen]);
|
|
1405
1366
|
useUpdateEffect(() => {
|
|
1406
|
-
if (!isHit)
|
|
1407
|
-
setFocusedIndex(-2);
|
|
1367
|
+
if (!isHit) setFocusedIndex(-2);
|
|
1408
1368
|
}, [isHit]);
|
|
1409
1369
|
useUnmountEffect(() => {
|
|
1410
1370
|
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
|
@@ -1513,8 +1473,7 @@ var useAutocompleteInput = () => {
|
|
|
1513
1473
|
isOpen
|
|
1514
1474
|
} = useAutocompleteContext();
|
|
1515
1475
|
useUpdateEffect(() => {
|
|
1516
|
-
if (isAllSelected && inputRef.current)
|
|
1517
|
-
inputRef.current.blur();
|
|
1476
|
+
if (isAllSelected && inputRef.current) inputRef.current.blur();
|
|
1518
1477
|
}, [isAllSelected]);
|
|
1519
1478
|
const getInputProps = useCallback(
|
|
1520
1479
|
(props = {}, ref = null) => ({
|
|
@@ -1567,14 +1526,11 @@ var useAutocompleteList = () => {
|
|
|
1567
1526
|
const beforeFocusedIndex = useRef2(-1);
|
|
1568
1527
|
const selectedValue = descendants.value(focusedIndex);
|
|
1569
1528
|
const onAnimationComplete = useCallback(() => {
|
|
1570
|
-
if (!isOpen)
|
|
1571
|
-
rebirthOptions(false);
|
|
1529
|
+
if (!isOpen) rebirthOptions(false);
|
|
1572
1530
|
}, [isOpen, rebirthOptions]);
|
|
1573
1531
|
useEffect(() => {
|
|
1574
|
-
if (!listRef.current || !selectedValue)
|
|
1575
|
-
|
|
1576
|
-
if (beforeFocusedIndex.current === selectedValue.index)
|
|
1577
|
-
return;
|
|
1532
|
+
if (!listRef.current || !selectedValue) return;
|
|
1533
|
+
if (beforeFocusedIndex.current === selectedValue.index) return;
|
|
1578
1534
|
const parent = listRef.current;
|
|
1579
1535
|
const child = selectedValue.node;
|
|
1580
1536
|
const parentHeight = parent.clientHeight;
|
|
@@ -1599,8 +1555,7 @@ var useAutocompleteList = () => {
|
|
|
1599
1555
|
beforeFocusedIndex.current = selectedValue.index;
|
|
1600
1556
|
}, [listRef, selectedValue]);
|
|
1601
1557
|
useUpdateEffect(() => {
|
|
1602
|
-
if (!isOpen)
|
|
1603
|
-
beforeFocusedIndex.current = -1;
|
|
1558
|
+
if (!isOpen) beforeFocusedIndex.current = -1;
|
|
1604
1559
|
}, [isOpen]);
|
|
1605
1560
|
const getListProps = useCallback(
|
|
1606
1561
|
(props = {}, ref = null) => ({
|
|
@@ -1723,23 +1678,18 @@ var useAutocompleteOption = (props) => {
|
|
|
1723
1678
|
(ev) => {
|
|
1724
1679
|
ev.stopPropagation();
|
|
1725
1680
|
if (isDisabled) {
|
|
1726
|
-
if (inputRef.current)
|
|
1727
|
-
inputRef.current.focus();
|
|
1681
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1728
1682
|
return;
|
|
1729
1683
|
}
|
|
1730
1684
|
if (!isTargetOption(ev.currentTarget)) {
|
|
1731
|
-
if (inputRef.current)
|
|
1732
|
-
inputRef.current.focus();
|
|
1685
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1733
1686
|
return;
|
|
1734
1687
|
}
|
|
1735
1688
|
setFocusedIndex(index);
|
|
1736
1689
|
onChange(optionValue != null ? optionValue : "");
|
|
1737
|
-
if (inputRef.current)
|
|
1738
|
-
|
|
1739
|
-
if (
|
|
1740
|
-
onClose();
|
|
1741
|
-
if (omitSelectedValues)
|
|
1742
|
-
onFocusNext(index);
|
|
1690
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1691
|
+
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
|
|
1692
|
+
if (omitSelectedValues) onFocusNext(index);
|
|
1743
1693
|
},
|
|
1744
1694
|
[
|
|
1745
1695
|
onFocusNext,
|
|
@@ -1756,8 +1706,7 @@ var useAutocompleteOption = (props) => {
|
|
|
1756
1706
|
]
|
|
1757
1707
|
);
|
|
1758
1708
|
useUpdateEffect(() => {
|
|
1759
|
-
if (isSelected)
|
|
1760
|
-
onChangeLabel(optionValue != null ? optionValue : "", false);
|
|
1709
|
+
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", false);
|
|
1761
1710
|
}, [optionValue]);
|
|
1762
1711
|
const getOptionProps = useCallback(
|
|
1763
1712
|
(props2 = {}, ref = null) => {
|
|
@@ -1911,4 +1860,4 @@ export {
|
|
|
1911
1860
|
AutocompleteItemIcon,
|
|
1912
1861
|
AutocompleteCreate
|
|
1913
1862
|
};
|
|
1914
|
-
//# sourceMappingURL=chunk-
|
|
1863
|
+
//# sourceMappingURL=chunk-JRUGH6ID.mjs.map
|