@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
|
@@ -360,8 +360,7 @@ var flattenItems = (items) => {
|
|
|
360
360
|
var _a;
|
|
361
361
|
const { isDisabled, isFocusable } = item;
|
|
362
362
|
const trulyDisabled = !!isDisabled && !isFocusable;
|
|
363
|
-
if (trulyDisabled)
|
|
364
|
-
return;
|
|
363
|
+
if (trulyDisabled) return;
|
|
365
364
|
if ("items" in item) {
|
|
366
365
|
return filterItems((_a = item.items) != null ? _a : []);
|
|
367
366
|
} else {
|
|
@@ -496,23 +495,18 @@ var useAutocomplete = ({
|
|
|
496
495
|
});
|
|
497
496
|
const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
|
|
498
497
|
const onOpen = (0, import_react.useCallback)(() => {
|
|
499
|
-
if (formControlProps.disabled || formControlProps.readOnly)
|
|
500
|
-
|
|
501
|
-
if (!allowCreate && (isEmpty || isAllSelected))
|
|
502
|
-
return;
|
|
498
|
+
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
499
|
+
if (!allowCreate && (isEmpty || isAllSelected)) return;
|
|
503
500
|
onInternalOpen();
|
|
504
|
-
if (inputRef.current)
|
|
505
|
-
inputRef.current.focus();
|
|
501
|
+
if (inputRef.current) inputRef.current.focus();
|
|
506
502
|
}, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
|
|
507
503
|
const onFocusFirst = (0, import_react.useCallback)(() => {
|
|
508
504
|
const id2 = setTimeout(() => {
|
|
509
|
-
if (isEmpty || isAllSelected)
|
|
510
|
-
return;
|
|
505
|
+
if (isEmpty || isAllSelected) return;
|
|
511
506
|
const first = descendants.enabledFirstValue(
|
|
512
507
|
({ node }) => "target" in node.dataset
|
|
513
508
|
);
|
|
514
|
-
if (!first)
|
|
515
|
-
return;
|
|
509
|
+
if (!first) return;
|
|
516
510
|
if (!isMulti || !omitSelectedValues) {
|
|
517
511
|
setFocusedIndex(first.index);
|
|
518
512
|
} else {
|
|
@@ -536,13 +530,11 @@ var useAutocomplete = ({
|
|
|
536
530
|
]);
|
|
537
531
|
const onFocusLast = (0, import_react.useCallback)(() => {
|
|
538
532
|
const id2 = setTimeout(() => {
|
|
539
|
-
if (isEmpty || isAllSelected)
|
|
540
|
-
return;
|
|
533
|
+
if (isEmpty || isAllSelected) return;
|
|
541
534
|
const last = descendants.enabledLastValue(
|
|
542
535
|
({ node }) => "target" in node.dataset
|
|
543
536
|
);
|
|
544
|
-
if (!last)
|
|
545
|
-
return;
|
|
537
|
+
if (!last) return;
|
|
546
538
|
if (!isMulti || !omitSelectedValues) {
|
|
547
539
|
setFocusedIndex(last.index);
|
|
548
540
|
} else {
|
|
@@ -573,8 +565,7 @@ var useAutocomplete = ({
|
|
|
573
565
|
return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
|
|
574
566
|
}
|
|
575
567
|
);
|
|
576
|
-
if (selected)
|
|
577
|
-
setFocusedIndex(selected.index);
|
|
568
|
+
if (selected) setFocusedIndex(selected.index);
|
|
578
569
|
});
|
|
579
570
|
timeoutIds.current.add(id2);
|
|
580
571
|
}, [descendants, isMulti, value]);
|
|
@@ -586,8 +577,7 @@ var useAutocomplete = ({
|
|
|
586
577
|
index,
|
|
587
578
|
({ node }) => "target" in node.dataset
|
|
588
579
|
);
|
|
589
|
-
if (!next)
|
|
590
|
-
return;
|
|
580
|
+
if (!next) return;
|
|
591
581
|
if (!isMulti || !omitSelectedValues) {
|
|
592
582
|
setFocusedIndex(next.index);
|
|
593
583
|
} else {
|
|
@@ -618,8 +608,7 @@ var useAutocomplete = ({
|
|
|
618
608
|
index,
|
|
619
609
|
({ node }) => "target" in node.dataset
|
|
620
610
|
);
|
|
621
|
-
if (!prev)
|
|
622
|
-
return;
|
|
611
|
+
if (!prev) return;
|
|
623
612
|
if (!isMulti || !omitSelectedValues) {
|
|
624
613
|
setFocusedIndex(prev.index);
|
|
625
614
|
} else {
|
|
@@ -673,8 +662,7 @@ var useAutocomplete = ({
|
|
|
673
662
|
values.forEach(({ node }) => {
|
|
674
663
|
node.dataset.target = "";
|
|
675
664
|
});
|
|
676
|
-
if (runFocus)
|
|
677
|
-
onFocusFirst();
|
|
665
|
+
if (runFocus) onFocusFirst();
|
|
678
666
|
setIsHit(true);
|
|
679
667
|
},
|
|
680
668
|
[descendants, onFocusFirst]
|
|
@@ -744,10 +732,8 @@ var useAutocomplete = ({
|
|
|
744
732
|
}
|
|
745
733
|
).length > 0;
|
|
746
734
|
onChangeLabel(newValue);
|
|
747
|
-
if (allowFree || isHit2)
|
|
748
|
-
|
|
749
|
-
if (isMulti && runRebirth)
|
|
750
|
-
rebirthOptions(false);
|
|
735
|
+
if (allowFree || isHit2) setInputValue("");
|
|
736
|
+
if (isMulti && runRebirth) rebirthOptions(false);
|
|
751
737
|
},
|
|
752
738
|
[
|
|
753
739
|
allowFree,
|
|
@@ -764,14 +750,11 @@ var useAutocomplete = ({
|
|
|
764
750
|
let enabledValue = descendants.value(focusedIndex);
|
|
765
751
|
if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
|
|
766
752
|
enabledValue = void 0;
|
|
767
|
-
if (!enabledValue)
|
|
768
|
-
return;
|
|
753
|
+
if (!enabledValue) return;
|
|
769
754
|
const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
|
|
770
755
|
onChange(value2);
|
|
771
|
-
if (closeOnSelect)
|
|
772
|
-
|
|
773
|
-
if (omitSelectedValues)
|
|
774
|
-
onFocusNext();
|
|
756
|
+
if (closeOnSelect) onClose();
|
|
757
|
+
if (omitSelectedValues) onFocusNext();
|
|
775
758
|
}, [
|
|
776
759
|
closeOnSelect,
|
|
777
760
|
descendants,
|
|
@@ -783,8 +766,7 @@ var useAutocomplete = ({
|
|
|
783
766
|
]);
|
|
784
767
|
const onSearch = (0, import_react.useCallback)(
|
|
785
768
|
(ev) => {
|
|
786
|
-
if (!isOpen)
|
|
787
|
-
onOpen();
|
|
769
|
+
if (!isOpen) onOpen();
|
|
788
770
|
onSearchProp == null ? void 0 : onSearchProp(ev);
|
|
789
771
|
const value2 = ev.target.value;
|
|
790
772
|
const computedValue = format(value2);
|
|
@@ -805,12 +787,10 @@ var useAutocomplete = ({
|
|
|
805
787
|
}, []);
|
|
806
788
|
const onCreate = (0, import_react.useCallback)(() => {
|
|
807
789
|
var _a, _b;
|
|
808
|
-
if (!listRef.current)
|
|
809
|
-
return;
|
|
790
|
+
if (!listRef.current) return;
|
|
810
791
|
const newItem = { label: inputValue, value: inputValue };
|
|
811
792
|
let newItems = [];
|
|
812
|
-
if (resolvedItems)
|
|
813
|
-
newItems = resolvedItems;
|
|
793
|
+
if (resolvedItems) newItems = resolvedItems;
|
|
814
794
|
if (firstInsertPositionItem === "first") {
|
|
815
795
|
newItems = [newItem, ...newItems];
|
|
816
796
|
} else if (firstInsertPositionItem === "last") {
|
|
@@ -853,31 +833,25 @@ var useAutocomplete = ({
|
|
|
853
833
|
]);
|
|
854
834
|
const onClick = (0, import_react.useCallback)(() => {
|
|
855
835
|
if (isOpen) {
|
|
856
|
-
if (inputRef.current)
|
|
857
|
-
inputRef.current.focus();
|
|
836
|
+
if (inputRef.current) inputRef.current.focus();
|
|
858
837
|
} else {
|
|
859
838
|
onOpen();
|
|
860
839
|
onFocusFirstOrSelected();
|
|
861
840
|
}
|
|
862
841
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
863
842
|
const onFocus = (0, import_react.useCallback)(() => {
|
|
864
|
-
if (isOpen)
|
|
865
|
-
return;
|
|
843
|
+
if (isOpen) return;
|
|
866
844
|
onOpen();
|
|
867
845
|
onFocusFirstOrSelected();
|
|
868
846
|
}, [isOpen, onFocusFirstOrSelected, onOpen]);
|
|
869
847
|
const onBlur = (0, import_react.useCallback)(
|
|
870
848
|
(ev) => {
|
|
871
849
|
const relatedTarget = (0, import_utils6.getEventRelatedTarget)(ev);
|
|
872
|
-
if ((0, import_utils6.isContains)(containerRef.current, relatedTarget))
|
|
873
|
-
|
|
874
|
-
if (
|
|
875
|
-
return;
|
|
876
|
-
if (allowFree && !!inputValue)
|
|
877
|
-
onChange(inputValue, false);
|
|
850
|
+
if ((0, import_utils6.isContains)(containerRef.current, relatedTarget)) return;
|
|
851
|
+
if (!closeOnBlur && isHit) return;
|
|
852
|
+
if (allowFree && !!inputValue) onChange(inputValue, false);
|
|
878
853
|
setInputValue("");
|
|
879
|
-
if (isOpen)
|
|
880
|
-
onClose();
|
|
854
|
+
if (isOpen) onClose();
|
|
881
855
|
},
|
|
882
856
|
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
883
857
|
);
|
|
@@ -887,8 +861,7 @@ var useAutocomplete = ({
|
|
|
887
861
|
} else {
|
|
888
862
|
onChange(value[value.length - 1]);
|
|
889
863
|
}
|
|
890
|
-
if (!isOpen)
|
|
891
|
-
onFocus();
|
|
864
|
+
if (!isOpen) onFocus();
|
|
892
865
|
}, [isMulti, isOpen, onChange, onFocus, value]);
|
|
893
866
|
const onClear = (0, import_react.useCallback)(
|
|
894
867
|
(ev) => {
|
|
@@ -898,27 +871,22 @@ var useAutocomplete = ({
|
|
|
898
871
|
setLabel(void 0);
|
|
899
872
|
setInputValue("");
|
|
900
873
|
rebirthOptions();
|
|
901
|
-
if (isOpen && inputRef.current)
|
|
902
|
-
inputRef.current.focus();
|
|
874
|
+
if (isOpen && inputRef.current) inputRef.current.focus();
|
|
903
875
|
},
|
|
904
876
|
[isOpen, setLabel, setInputValue, setValue, rebirthOptions]
|
|
905
877
|
);
|
|
906
878
|
const onKeyDown = (0, import_react.useCallback)(
|
|
907
879
|
(ev) => {
|
|
908
|
-
if (ev.key === " ")
|
|
909
|
-
|
|
910
|
-
if (
|
|
911
|
-
return;
|
|
912
|
-
if (isComposition.current)
|
|
913
|
-
return;
|
|
880
|
+
if (ev.key === " ") ev.key = ev.code;
|
|
881
|
+
if (formControlProps.disabled || formControlProps.readOnly) return;
|
|
882
|
+
if (isComposition.current) return;
|
|
914
883
|
const enabledDelete = label === inputValue || !inputValue.length;
|
|
915
884
|
const actions = {
|
|
916
885
|
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
917
886
|
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
|
|
918
887
|
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
919
888
|
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
920
|
-
if (inputValue)
|
|
921
|
-
onChange(inputValue);
|
|
889
|
+
if (inputValue) onChange(inputValue);
|
|
922
890
|
setFocusedIndex(0);
|
|
923
891
|
} : void 0,
|
|
924
892
|
Home: isOpen ? onFocusFirst : void 0,
|
|
@@ -927,8 +895,7 @@ var useAutocomplete = ({
|
|
|
927
895
|
Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
|
|
928
896
|
};
|
|
929
897
|
const action = actions[ev.key];
|
|
930
|
-
if (!action)
|
|
931
|
-
return;
|
|
898
|
+
if (!action) return;
|
|
932
899
|
ev.preventDefault();
|
|
933
900
|
ev.stopPropagation();
|
|
934
901
|
action(ev);
|
|
@@ -959,10 +926,8 @@ var useAutocomplete = ({
|
|
|
959
926
|
]
|
|
960
927
|
);
|
|
961
928
|
(0, import_react.useEffect)(() => {
|
|
962
|
-
if (!isMulti)
|
|
963
|
-
|
|
964
|
-
if (!omitSelectedValues && (0, import_utils6.isUndefined)(maxSelectValues))
|
|
965
|
-
return;
|
|
929
|
+
if (!isMulti) return;
|
|
930
|
+
if (!omitSelectedValues && (0, import_utils6.isUndefined)(maxSelectValues)) return;
|
|
966
931
|
const isAll = value.length > 0 && value.length === descendants.count();
|
|
967
932
|
const isMax = value.length === maxSelectValues;
|
|
968
933
|
if (isAll || isMax) {
|
|
@@ -987,20 +952,17 @@ var useAutocomplete = ({
|
|
|
987
952
|
const label2 = getSelectedValues(value);
|
|
988
953
|
setLabel(label2);
|
|
989
954
|
} else {
|
|
990
|
-
if (prevValue.current === value)
|
|
991
|
-
return;
|
|
955
|
+
if (prevValue.current === value) return;
|
|
992
956
|
onChangeLabel(value, false);
|
|
993
957
|
}
|
|
994
958
|
}, [isMulti, value, onChangeLabel, getSelectedValues]);
|
|
995
959
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
996
|
-
if (isOpen || allowFree)
|
|
997
|
-
return;
|
|
960
|
+
if (isOpen || allowFree) return;
|
|
998
961
|
setFocusedIndex(-1);
|
|
999
962
|
setInputValue("");
|
|
1000
963
|
}, [isOpen]);
|
|
1001
964
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
1002
|
-
if (!isHit)
|
|
1003
|
-
setFocusedIndex(-2);
|
|
965
|
+
if (!isHit) setFocusedIndex(-2);
|
|
1004
966
|
}, [isHit]);
|
|
1005
967
|
(0, import_utils6.useUnmountEffect)(() => {
|
|
1006
968
|
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
|
@@ -1109,8 +1071,7 @@ var useAutocompleteInput = () => {
|
|
|
1109
1071
|
isOpen
|
|
1110
1072
|
} = useAutocompleteContext();
|
|
1111
1073
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
1112
|
-
if (isAllSelected && inputRef.current)
|
|
1113
|
-
inputRef.current.blur();
|
|
1074
|
+
if (isAllSelected && inputRef.current) inputRef.current.blur();
|
|
1114
1075
|
}, [isAllSelected]);
|
|
1115
1076
|
const getInputProps = (0, import_react.useCallback)(
|
|
1116
1077
|
(props = {}, ref = null) => ({
|
|
@@ -1163,14 +1124,11 @@ var useAutocompleteList = () => {
|
|
|
1163
1124
|
const beforeFocusedIndex = (0, import_react.useRef)(-1);
|
|
1164
1125
|
const selectedValue = descendants.value(focusedIndex);
|
|
1165
1126
|
const onAnimationComplete = (0, import_react.useCallback)(() => {
|
|
1166
|
-
if (!isOpen)
|
|
1167
|
-
rebirthOptions(false);
|
|
1127
|
+
if (!isOpen) rebirthOptions(false);
|
|
1168
1128
|
}, [isOpen, rebirthOptions]);
|
|
1169
1129
|
(0, import_react.useEffect)(() => {
|
|
1170
|
-
if (!listRef.current || !selectedValue)
|
|
1171
|
-
|
|
1172
|
-
if (beforeFocusedIndex.current === selectedValue.index)
|
|
1173
|
-
return;
|
|
1130
|
+
if (!listRef.current || !selectedValue) return;
|
|
1131
|
+
if (beforeFocusedIndex.current === selectedValue.index) return;
|
|
1174
1132
|
const parent = listRef.current;
|
|
1175
1133
|
const child = selectedValue.node;
|
|
1176
1134
|
const parentHeight = parent.clientHeight;
|
|
@@ -1195,8 +1153,7 @@ var useAutocompleteList = () => {
|
|
|
1195
1153
|
beforeFocusedIndex.current = selectedValue.index;
|
|
1196
1154
|
}, [listRef, selectedValue]);
|
|
1197
1155
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
1198
|
-
if (!isOpen)
|
|
1199
|
-
beforeFocusedIndex.current = -1;
|
|
1156
|
+
if (!isOpen) beforeFocusedIndex.current = -1;
|
|
1200
1157
|
}, [isOpen]);
|
|
1201
1158
|
const getListProps = (0, import_react.useCallback)(
|
|
1202
1159
|
(props = {}, ref = null) => ({
|
|
@@ -1319,23 +1276,18 @@ var useAutocompleteOption = (props) => {
|
|
|
1319
1276
|
(ev) => {
|
|
1320
1277
|
ev.stopPropagation();
|
|
1321
1278
|
if (isDisabled) {
|
|
1322
|
-
if (inputRef.current)
|
|
1323
|
-
inputRef.current.focus();
|
|
1279
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1324
1280
|
return;
|
|
1325
1281
|
}
|
|
1326
1282
|
if (!isTargetOption(ev.currentTarget)) {
|
|
1327
|
-
if (inputRef.current)
|
|
1328
|
-
inputRef.current.focus();
|
|
1283
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1329
1284
|
return;
|
|
1330
1285
|
}
|
|
1331
1286
|
setFocusedIndex(index);
|
|
1332
1287
|
onChange(optionValue != null ? optionValue : "");
|
|
1333
|
-
if (inputRef.current)
|
|
1334
|
-
|
|
1335
|
-
if (
|
|
1336
|
-
onClose();
|
|
1337
|
-
if (omitSelectedValues)
|
|
1338
|
-
onFocusNext(index);
|
|
1288
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1289
|
+
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
|
|
1290
|
+
if (omitSelectedValues) onFocusNext(index);
|
|
1339
1291
|
},
|
|
1340
1292
|
[
|
|
1341
1293
|
onFocusNext,
|
|
@@ -1352,8 +1304,7 @@ var useAutocompleteOption = (props) => {
|
|
|
1352
1304
|
]
|
|
1353
1305
|
);
|
|
1354
1306
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
1355
|
-
if (isSelected)
|
|
1356
|
-
onChangeLabel(optionValue != null ? optionValue : "", false);
|
|
1307
|
+
if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", false);
|
|
1357
1308
|
}, [optionValue]);
|
|
1358
1309
|
const getOptionProps = (0, import_react.useCallback)(
|
|
1359
1310
|
(props2 = {}, ref = null) => {
|
|
@@ -1676,15 +1627,13 @@ var MultiAutocompleteField = (0, import_core8.forwardRef)(
|
|
|
1676
1627
|
const { value, label, inputValue, onChange, isOpen, inputRef, styles } = useAutocompleteContext();
|
|
1677
1628
|
const { getInputProps } = useAutocompleteInput();
|
|
1678
1629
|
const cloneChildren = (0, import_react3.useMemo)(() => {
|
|
1679
|
-
if (!(label == null ? void 0 : label.length))
|
|
1680
|
-
return null;
|
|
1630
|
+
if (!(label == null ? void 0 : label.length)) return null;
|
|
1681
1631
|
if (component) {
|
|
1682
1632
|
return label.map((label2, index) => {
|
|
1683
1633
|
const onRemove = (ev) => {
|
|
1684
1634
|
ev.stopPropagation();
|
|
1685
1635
|
onChange(value[index]);
|
|
1686
|
-
if (inputRef.current)
|
|
1687
|
-
inputRef.current.focus();
|
|
1636
|
+
if (inputRef.current) inputRef.current.focus();
|
|
1688
1637
|
};
|
|
1689
1638
|
const el = component({
|
|
1690
1639
|
value: value[index],
|