@yamada-ui/autocomplete 0.1.8 → 0.1.10

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AutocompleteCreate
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  AutocompleteCreate
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AutocompleteEmpty
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  AutocompleteEmpty
6
6
  };
@@ -2,7 +2,7 @@ import {
2
2
  AutocompleteClearIcon,
3
3
  AutocompleteIcon,
4
4
  AutocompleteItemIcon
5
- } from "./chunk-MG2KF34Q.mjs";
5
+ } from "./chunk-YQULJUTP.mjs";
6
6
  export {
7
7
  AutocompleteClearIcon,
8
8
  AutocompleteIcon,
@@ -58,6 +58,8 @@ var useAutocompleteList = () => {
58
58
  (0, import_react.useEffect)(() => {
59
59
  if (!listRef.current || !selectedValue)
60
60
  return;
61
+ if (beforeFocusedIndex.current === selectedValue.index)
62
+ return;
61
63
  const parent = listRef.current;
62
64
  const child = selectedValue.node;
63
65
  const parentHeight = parent.clientHeight;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AutocompleteList
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  AutocompleteList
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import * as _yamada_ui_core from '@yamada-ui/core';
2
2
  import { HTMLUIProps } from '@yamada-ui/core';
3
- import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-42515ffb.js';
3
+ import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-4995431c.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
6
  import '@yamada-ui/form-control';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AutocompleteOptionGroup
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  AutocompleteOptionGroup
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import '@yamada-ui/core';
2
2
  import 'react';
3
- export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-42515ffb.js';
3
+ export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-4995431c.js';
4
4
  import 'react/jsx-runtime';
5
5
  import '@yamada-ui/form-control';
6
6
  import '@yamada-ui/popover';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AutocompleteOption
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  AutocompleteOption
6
6
  };
@@ -2,7 +2,7 @@ import * as _yamada_ui_core from '@yamada-ui/core';
2
2
  import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
3
3
  import { AutocompleteIconProps } from './autocomplete-icon.js';
4
4
  import { AutocompleteListProps } from './autocomplete-list.js';
5
- import { b as UseAutocompleteProps } from './use-autocomplete-42515ffb.js';
5
+ import { b as UseAutocompleteProps } from './use-autocomplete-4995431c.js';
6
6
  import 'react';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
@@ -343,20 +343,20 @@ var defaultFormat = (value) => {
343
343
  value = value.toUpperCase();
344
344
  return value;
345
345
  };
346
- var flattenData = (data) => {
347
- const filterData = (data2) => data2.map((data3) => {
348
- const { value, isDisabled, isFocusable } = data3;
346
+ var flattenOptions = (options) => {
347
+ const filterOptions = (options2) => options2.map((options3) => {
348
+ const { value, isDisabled, isFocusable } = options3;
349
349
  const trulyDisabled = !!isDisabled && !isFocusable;
350
350
  const isMulti = (0, import_utils6.isArray)(value);
351
351
  if (trulyDisabled)
352
352
  return;
353
353
  if (!isMulti) {
354
- return data3;
354
+ return options3;
355
355
  } else {
356
- return filterData(value);
356
+ return filterOptions(value);
357
357
  }
358
358
  }).filter(Boolean);
359
- return filterData(data).flat(Infinity);
359
+ return filterOptions(options).flat(Infinity);
360
360
  };
361
361
  var isTargetOption = (target) => {
362
362
  var _a;
@@ -395,7 +395,7 @@ var useAutocomplete = ({
395
395
  const { id } = rest;
396
396
  const formControlProps = (0, import_utils6.pickObject)(rest, import_form_control.formControlProperties);
397
397
  const [containerProps, inputProps] = (0, import_utils6.splitObject)(
398
- (0, import_utils6.omitObject)(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
398
+ (0, import_utils6.omitObject)(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
399
399
  import_core6.layoutStylesProperties
400
400
  );
401
401
  const descendants = useAutocompleteDescendants();
@@ -404,7 +404,7 @@ var useAutocomplete = ({
404
404
  const inputRef = (0, import_react.useRef)(null);
405
405
  const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
406
406
  const isComposition = (0, import_react.useRef)(false);
407
- const [data, setData] = (0, import_react.useState)(rest.data);
407
+ const [options, setOptions] = (0, import_react.useState)(rest.options);
408
408
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
409
409
  value: rest.value,
410
410
  defaultValue: rest.defaultValue,
@@ -422,7 +422,7 @@ var useAutocomplete = ({
422
422
  const isEmptyValue = !isMulti ? !value : !value.length;
423
423
  if (createOption && !(0, import_utils6.isUndefined)(children)) {
424
424
  console.warn(
425
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
425
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
426
426
  );
427
427
  }
428
428
  const selectedValues = descendants.enabledValues(
@@ -436,7 +436,7 @@ var useAutocomplete = ({
436
436
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
437
437
  );
438
438
  const validChildren = (0, import_utils6.getValidChildren)(children);
439
- const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
439
+ const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
440
440
  if (!(0, import_utils6.isArray)(value2)) {
441
441
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
442
442
  } else {
@@ -700,20 +700,20 @@ var useAutocomplete = ({
700
700
  if (!listRef.current)
701
701
  return;
702
702
  const newOption = { label: inputValue, value: inputValue };
703
- let newData = [];
704
- if (data)
705
- newData = data;
703
+ let newOptions = [];
704
+ if (options)
705
+ newOptions = options;
706
706
  if (createOrder === "first") {
707
- newData = [newOption, ...newData];
707
+ newOptions = [newOption, ...newOptions];
708
708
  } else if (createOrder === "last") {
709
- newData = [...newData, newOption];
709
+ newOptions = [...newOptions, newOption];
710
710
  } else {
711
- const i = newData.findIndex(({ label }) => label === createOrder);
712
- if (i !== -1 && (0, import_utils6.isArray)(newData[i].value)) {
711
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
712
+ if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
713
713
  if (createSecondOrder === "first") {
714
- newData[i].value = [newOption, ...newData[i].value];
714
+ newOptions[i].value = [newOption, ...newOptions[i].value];
715
715
  } else {
716
- newData[i].value = [...newData[i].value, newOption];
716
+ newOptions[i].value = [...newOptions[i].value, newOption];
717
717
  }
718
718
  } else {
719
719
  console.warn(
@@ -721,13 +721,13 @@ var useAutocomplete = ({
721
721
  );
722
722
  }
723
723
  }
724
- setData(newData);
724
+ setOptions(newOptions);
725
725
  onChange(inputValue);
726
726
  rebirthOptions(false);
727
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
727
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
728
728
  setFocusedIndex(index);
729
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
730
- }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
729
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
730
+ }, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
731
731
  const onDelete = (0, import_react.useCallback)(() => {
732
732
  if (!isMulti) {
733
733
  onChange("");
@@ -742,10 +742,8 @@ var useAutocomplete = ({
742
742
  setDisplayValue(void 0);
743
743
  setInputValue("");
744
744
  rebirthOptions();
745
- if (inputRef.current)
746
- inputRef.current.focus();
747
745
  },
748
- [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
746
+ [setDisplayValue, setInputValue, setValue, rebirthOptions]
749
747
  );
750
748
  const onClick = (0, import_react.useCallback)(() => {
751
749
  if (isOpen) {
@@ -877,10 +875,9 @@ var useAutocomplete = ({
877
875
  ...props,
878
876
  ...formControlProps,
879
877
  onClick: (0, import_utils6.handlerAll)(props.onClick, rest.onClick, onClick),
880
- onFocus: (0, import_utils6.handlerAll)(props.onFocus, rest.onFocus, onFocus),
881
878
  onBlur: (0, import_utils6.handlerAll)(props.onBlur, rest.onBlur, onBlur)
882
879
  }),
883
- [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
880
+ [containerProps, formControlProps, onBlur, onClick, rest]
884
881
  );
885
882
  const getFieldProps = (0, import_react.useCallback)(
886
883
  (props = {}, ref = null) => ({
@@ -891,9 +888,10 @@ var useAutocomplete = ({
891
888
  placeholder,
892
889
  "data-active": (0, import_utils6.dataAttr)(isOpen),
893
890
  "aria-expanded": (0, import_utils6.dataAttr)(isOpen),
891
+ onFocus: (0, import_utils6.handlerAll)(props.onFocus, rest.onFocus, onFocus),
894
892
  onKeyDown: (0, import_utils6.handlerAll)(props.onKeyDown, rest.onKeyDown, onKeyDown)
895
893
  }),
896
- [formControlProps, placeholder, isOpen, rest, onKeyDown]
894
+ [formControlProps, placeholder, isOpen, rest, onFocus, onKeyDown]
897
895
  );
898
896
  return {
899
897
  id,
@@ -1002,6 +1000,8 @@ var useAutocompleteList = () => {
1002
1000
  (0, import_react.useEffect)(() => {
1003
1001
  if (!listRef.current || !selectedValue)
1004
1002
  return;
1003
+ if (beforeFocusedIndex.current === selectedValue.index)
1004
+ return;
1005
1005
  const parent = listRef.current;
1006
1006
  const child = selectedValue.node;
1007
1007
  const parentHeight = parent.clientHeight;
@@ -1430,8 +1430,7 @@ var AutocompleteField = (0, import_core8.forwardRef)(
1430
1430
  display: "inline-block",
1431
1431
  w: "full",
1432
1432
  placeholder,
1433
- ...getInputProps(inputProps, ref),
1434
- value: inputValue || displayValue || ""
1433
+ ...getInputProps({ ...inputProps, value: inputValue || displayValue || "" }, ref)
1435
1434
  }
1436
1435
  ) }) });
1437
1436
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Autocomplete
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  Autocomplete
6
6
  };
@@ -222,8 +222,7 @@ var AutocompleteField = forwardRef2(
222
222
  display: "inline-block",
223
223
  w: "full",
224
224
  placeholder,
225
- ...getInputProps(inputProps, ref),
226
- value: inputValue || displayValue || ""
225
+ ...getInputProps({ ...inputProps, value: inputValue || displayValue || "" }, ref)
227
226
  }
228
227
  ) }) });
229
228
  }
@@ -584,8 +583,7 @@ var MultiAutocompleteField = forwardRef7(
584
583
  marginBlockStart: "0.125rem",
585
584
  marginBlockEnd: "0.125rem",
586
585
  placeholder: !displayValue || keepPlaceholder && isOpen ? placeholder : void 0,
587
- ...getInputProps(inputProps, ref),
588
- value: inputValue
586
+ ...getInputProps({ ...inputProps, value: inputValue != null ? inputValue : "" }, ref)
589
587
  }
590
588
  )
591
589
  ]
@@ -694,20 +692,20 @@ var defaultFormat = (value) => {
694
692
  value = value.toUpperCase();
695
693
  return value;
696
694
  };
697
- var flattenData = (data) => {
698
- const filterData = (data2) => data2.map((data3) => {
699
- const { value, isDisabled, isFocusable } = data3;
695
+ var flattenOptions = (options) => {
696
+ const filterOptions = (options2) => options2.map((options3) => {
697
+ const { value, isDisabled, isFocusable } = options3;
700
698
  const trulyDisabled = !!isDisabled && !isFocusable;
701
699
  const isMulti = isArray(value);
702
700
  if (trulyDisabled)
703
701
  return;
704
702
  if (!isMulti) {
705
- return data3;
703
+ return options3;
706
704
  } else {
707
- return filterData(value);
705
+ return filterOptions(value);
708
706
  }
709
707
  }).filter(Boolean);
710
- return filterData(data).flat(Infinity);
708
+ return filterOptions(options).flat(Infinity);
711
709
  };
712
710
  var isTargetOption = (target) => {
713
711
  var _a;
@@ -746,7 +744,7 @@ var useAutocomplete = ({
746
744
  const { id } = rest;
747
745
  const formControlProps = pickObject(rest, formControlProperties);
748
746
  const [containerProps, inputProps] = splitObject(
749
- omitObject(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
747
+ omitObject(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
750
748
  layoutStylesProperties
751
749
  );
752
750
  const descendants = useAutocompleteDescendants();
@@ -755,7 +753,7 @@ var useAutocomplete = ({
755
753
  const inputRef = useRef2(null);
756
754
  const timeoutIds = useRef2(/* @__PURE__ */ new Set([]));
757
755
  const isComposition = useRef2(false);
758
- const [data, setData] = useState(rest.data);
756
+ const [options, setOptions] = useState(rest.options);
759
757
  const [value, setValue] = useControllableState({
760
758
  value: rest.value,
761
759
  defaultValue: rest.defaultValue,
@@ -773,7 +771,7 @@ var useAutocomplete = ({
773
771
  const isEmptyValue = !isMulti ? !value : !value.length;
774
772
  if (createOption && !isUndefined(children)) {
775
773
  console.warn(
776
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
774
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
777
775
  );
778
776
  }
779
777
  const selectedValues = descendants.enabledValues(
@@ -787,7 +785,7 @@ var useAutocomplete = ({
787
785
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
788
786
  );
789
787
  const validChildren = getValidChildren2(children);
790
- const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
788
+ const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
791
789
  if (!isArray(value2)) {
792
790
  return /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props, children: label }, i);
793
791
  } else {
@@ -1051,20 +1049,20 @@ var useAutocomplete = ({
1051
1049
  if (!listRef.current)
1052
1050
  return;
1053
1051
  const newOption = { label: inputValue, value: inputValue };
1054
- let newData = [];
1055
- if (data)
1056
- newData = data;
1052
+ let newOptions = [];
1053
+ if (options)
1054
+ newOptions = options;
1057
1055
  if (createOrder === "first") {
1058
- newData = [newOption, ...newData];
1056
+ newOptions = [newOption, ...newOptions];
1059
1057
  } else if (createOrder === "last") {
1060
- newData = [...newData, newOption];
1058
+ newOptions = [...newOptions, newOption];
1061
1059
  } else {
1062
- const i = newData.findIndex(({ label }) => label === createOrder);
1063
- if (i !== -1 && isArray(newData[i].value)) {
1060
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
1061
+ if (i !== -1 && isArray(newOptions[i].value)) {
1064
1062
  if (createSecondOrder === "first") {
1065
- newData[i].value = [newOption, ...newData[i].value];
1063
+ newOptions[i].value = [newOption, ...newOptions[i].value];
1066
1064
  } else {
1067
- newData[i].value = [...newData[i].value, newOption];
1065
+ newOptions[i].value = [...newOptions[i].value, newOption];
1068
1066
  }
1069
1067
  } else {
1070
1068
  console.warn(
@@ -1072,13 +1070,13 @@ var useAutocomplete = ({
1072
1070
  );
1073
1071
  }
1074
1072
  }
1075
- setData(newData);
1073
+ setOptions(newOptions);
1076
1074
  onChange(inputValue);
1077
1075
  rebirthOptions(false);
1078
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
1076
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
1079
1077
  setFocusedIndex(index);
1080
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
1081
- }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
1078
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
1079
+ }, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
1082
1080
  const onDelete = useCallback(() => {
1083
1081
  if (!isMulti) {
1084
1082
  onChange("");
@@ -1093,10 +1091,8 @@ var useAutocomplete = ({
1093
1091
  setDisplayValue(void 0);
1094
1092
  setInputValue("");
1095
1093
  rebirthOptions();
1096
- if (inputRef.current)
1097
- inputRef.current.focus();
1098
1094
  },
1099
- [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
1095
+ [setDisplayValue, setInputValue, setValue, rebirthOptions]
1100
1096
  );
1101
1097
  const onClick = useCallback(() => {
1102
1098
  if (isOpen) {
@@ -1228,10 +1224,9 @@ var useAutocomplete = ({
1228
1224
  ...props,
1229
1225
  ...formControlProps,
1230
1226
  onClick: handlerAll2(props.onClick, rest.onClick, onClick),
1231
- onFocus: handlerAll2(props.onFocus, rest.onFocus, onFocus),
1232
1227
  onBlur: handlerAll2(props.onBlur, rest.onBlur, onBlur)
1233
1228
  }),
1234
- [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
1229
+ [containerProps, formControlProps, onBlur, onClick, rest]
1235
1230
  );
1236
1231
  const getFieldProps = useCallback(
1237
1232
  (props = {}, ref = null) => ({
@@ -1242,9 +1237,10 @@ var useAutocomplete = ({
1242
1237
  placeholder,
1243
1238
  "data-active": dataAttr(isOpen),
1244
1239
  "aria-expanded": dataAttr(isOpen),
1240
+ onFocus: handlerAll2(props.onFocus, rest.onFocus, onFocus),
1245
1241
  onKeyDown: handlerAll2(props.onKeyDown, rest.onKeyDown, onKeyDown)
1246
1242
  }),
1247
- [formControlProps, placeholder, isOpen, rest, onKeyDown]
1243
+ [formControlProps, placeholder, isOpen, rest, onFocus, onKeyDown]
1248
1244
  );
1249
1245
  return {
1250
1246
  id,
@@ -1353,6 +1349,8 @@ var useAutocompleteList = () => {
1353
1349
  useEffect(() => {
1354
1350
  if (!listRef.current || !selectedValue)
1355
1351
  return;
1352
+ if (beforeFocusedIndex.current === selectedValue.index)
1353
+ return;
1356
1354
  const parent = listRef.current;
1357
1355
  const child = selectedValue.node;
1358
1356
  const parentHeight = parent.clientHeight;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Autocomplete, AutocompleteProps } from './autocomplete.js';
2
2
  export { AutocompleteOptionGroup, AutocompleteOptionGroupProps } from './autocomplete-option-group.js';
3
- export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-42515ffb.js';
3
+ export { a as AutocompleteOption, A as AutocompleteOptionProps } from './use-autocomplete-4995431c.js';
4
4
  export { AutocompleteCreate, AutocompleteCreateProps } from './autocomplete-create.js';
5
5
  export { AutocompleteEmpty, AutocompleteEmptyProps } from './autocomplete-empty.js';
6
6
  export { MultiAutocomplete, MultiAutocompleteProps } from './multi-autocomplete.js';
package/dist/index.js CHANGED
@@ -148,20 +148,20 @@ var defaultFormat = (value) => {
148
148
  value = value.toUpperCase();
149
149
  return value;
150
150
  };
151
- var flattenData = (data) => {
152
- const filterData = (data2) => data2.map((data3) => {
153
- const { value, isDisabled, isFocusable } = data3;
151
+ var flattenOptions = (options) => {
152
+ const filterOptions = (options2) => options2.map((options3) => {
153
+ const { value, isDisabled, isFocusable } = options3;
154
154
  const trulyDisabled = !!isDisabled && !isFocusable;
155
155
  const isMulti = (0, import_utils.isArray)(value);
156
156
  if (trulyDisabled)
157
157
  return;
158
158
  if (!isMulti) {
159
- return data3;
159
+ return options3;
160
160
  } else {
161
- return filterData(value);
161
+ return filterOptions(value);
162
162
  }
163
163
  }).filter(Boolean);
164
- return filterData(data).flat(Infinity);
164
+ return filterOptions(options).flat(Infinity);
165
165
  };
166
166
  var isTargetOption = (target) => {
167
167
  var _a;
@@ -200,7 +200,7 @@ var useAutocomplete = ({
200
200
  const { id } = rest;
201
201
  const formControlProps = (0, import_utils.pickObject)(rest, import_form_control.formControlProperties);
202
202
  const [containerProps, inputProps] = (0, import_utils.splitObject)(
203
- (0, import_utils.omitObject)(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
203
+ (0, import_utils.omitObject)(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
204
204
  import_core.layoutStylesProperties
205
205
  );
206
206
  const descendants = useAutocompleteDescendants();
@@ -209,7 +209,7 @@ var useAutocomplete = ({
209
209
  const inputRef = (0, import_react.useRef)(null);
210
210
  const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
211
211
  const isComposition = (0, import_react.useRef)(false);
212
- const [data, setData] = (0, import_react.useState)(rest.data);
212
+ const [options, setOptions] = (0, import_react.useState)(rest.options);
213
213
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
214
214
  value: rest.value,
215
215
  defaultValue: rest.defaultValue,
@@ -227,7 +227,7 @@ var useAutocomplete = ({
227
227
  const isEmptyValue = !isMulti ? !value : !value.length;
228
228
  if (createOption && !(0, import_utils.isUndefined)(children)) {
229
229
  console.warn(
230
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
230
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
231
231
  );
232
232
  }
233
233
  const selectedValues = descendants.enabledValues(
@@ -241,7 +241,7 @@ var useAutocomplete = ({
241
241
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
242
242
  );
243
243
  const validChildren = (0, import_utils.getValidChildren)(children);
244
- const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
244
+ const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
245
245
  if (!(0, import_utils.isArray)(value2)) {
246
246
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
247
247
  } else {
@@ -505,20 +505,20 @@ var useAutocomplete = ({
505
505
  if (!listRef.current)
506
506
  return;
507
507
  const newOption = { label: inputValue, value: inputValue };
508
- let newData = [];
509
- if (data)
510
- newData = data;
508
+ let newOptions = [];
509
+ if (options)
510
+ newOptions = options;
511
511
  if (createOrder === "first") {
512
- newData = [newOption, ...newData];
512
+ newOptions = [newOption, ...newOptions];
513
513
  } else if (createOrder === "last") {
514
- newData = [...newData, newOption];
514
+ newOptions = [...newOptions, newOption];
515
515
  } else {
516
- const i = newData.findIndex(({ label }) => label === createOrder);
517
- if (i !== -1 && (0, import_utils.isArray)(newData[i].value)) {
516
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
517
+ if (i !== -1 && (0, import_utils.isArray)(newOptions[i].value)) {
518
518
  if (createSecondOrder === "first") {
519
- newData[i].value = [newOption, ...newData[i].value];
519
+ newOptions[i].value = [newOption, ...newOptions[i].value];
520
520
  } else {
521
- newData[i].value = [...newData[i].value, newOption];
521
+ newOptions[i].value = [...newOptions[i].value, newOption];
522
522
  }
523
523
  } else {
524
524
  console.warn(
@@ -526,13 +526,13 @@ var useAutocomplete = ({
526
526
  );
527
527
  }
528
528
  }
529
- setData(newData);
529
+ setOptions(newOptions);
530
530
  onChange(inputValue);
531
531
  rebirthOptions(false);
532
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
532
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
533
533
  setFocusedIndex(index);
534
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
535
- }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
534
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
535
+ }, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
536
536
  const onDelete = (0, import_react.useCallback)(() => {
537
537
  if (!isMulti) {
538
538
  onChange("");
@@ -547,10 +547,8 @@ var useAutocomplete = ({
547
547
  setDisplayValue(void 0);
548
548
  setInputValue("");
549
549
  rebirthOptions();
550
- if (inputRef.current)
551
- inputRef.current.focus();
552
550
  },
553
- [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
551
+ [setDisplayValue, setInputValue, setValue, rebirthOptions]
554
552
  );
555
553
  const onClick = (0, import_react.useCallback)(() => {
556
554
  if (isOpen) {
@@ -682,10 +680,9 @@ var useAutocomplete = ({
682
680
  ...props,
683
681
  ...formControlProps,
684
682
  onClick: (0, import_utils.handlerAll)(props.onClick, rest.onClick, onClick),
685
- onFocus: (0, import_utils.handlerAll)(props.onFocus, rest.onFocus, onFocus),
686
683
  onBlur: (0, import_utils.handlerAll)(props.onBlur, rest.onBlur, onBlur)
687
684
  }),
688
- [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
685
+ [containerProps, formControlProps, onBlur, onClick, rest]
689
686
  );
690
687
  const getFieldProps = (0, import_react.useCallback)(
691
688
  (props = {}, ref = null) => ({
@@ -696,9 +693,10 @@ var useAutocomplete = ({
696
693
  placeholder,
697
694
  "data-active": (0, import_utils.dataAttr)(isOpen),
698
695
  "aria-expanded": (0, import_utils.dataAttr)(isOpen),
696
+ onFocus: (0, import_utils.handlerAll)(props.onFocus, rest.onFocus, onFocus),
699
697
  onKeyDown: (0, import_utils.handlerAll)(props.onKeyDown, rest.onKeyDown, onKeyDown)
700
698
  }),
701
- [formControlProps, placeholder, isOpen, rest, onKeyDown]
699
+ [formControlProps, placeholder, isOpen, rest, onFocus, onKeyDown]
702
700
  );
703
701
  return {
704
702
  id,
@@ -807,6 +805,8 @@ var useAutocompleteList = () => {
807
805
  (0, import_react.useEffect)(() => {
808
806
  if (!listRef.current || !selectedValue)
809
807
  return;
808
+ if (beforeFocusedIndex.current === selectedValue.index)
809
+ return;
810
810
  const parent = listRef.current;
811
811
  const child = selectedValue.node;
812
812
  const parentHeight = parent.clientHeight;
@@ -1284,8 +1284,7 @@ var AutocompleteField = (0, import_core4.forwardRef)(
1284
1284
  display: "inline-block",
1285
1285
  w: "full",
1286
1286
  placeholder,
1287
- ...getInputProps(inputProps, ref),
1288
- value: inputValue || displayValue || ""
1287
+ ...getInputProps({ ...inputProps, value: inputValue || displayValue || "" }, ref)
1289
1288
  }
1290
1289
  ) }) });
1291
1290
  }
@@ -1641,8 +1640,7 @@ var MultiAutocompleteField = (0, import_core9.forwardRef)(
1641
1640
  marginBlockStart: "0.125rem",
1642
1641
  marginBlockEnd: "0.125rem",
1643
1642
  placeholder: !displayValue || keepPlaceholder && isOpen ? placeholder : void 0,
1644
- ...getInputProps(inputProps, ref),
1645
- value: inputValue
1643
+ ...getInputProps({ ...inputProps, value: inputValue != null ? inputValue : "" }, ref)
1646
1644
  }
1647
1645
  )
1648
1646
  ]
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  AutocompleteOption,
6
6
  AutocompleteOptionGroup,
7
7
  MultiAutocomplete
8
- } from "./chunk-MG2KF34Q.mjs";
8
+ } from "./chunk-YQULJUTP.mjs";
9
9
  export {
10
10
  Autocomplete,
11
11
  AutocompleteCreate,
@@ -3,7 +3,7 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
3
3
  import { FC, MouseEventHandler } from 'react';
4
4
  import { AutocompleteIconProps } from './autocomplete-icon.js';
5
5
  import { AutocompleteListProps } from './autocomplete-list.js';
6
- import { b as UseAutocompleteProps } from './use-autocomplete-42515ffb.js';
6
+ import { b as UseAutocompleteProps } from './use-autocomplete-4995431c.js';
7
7
  import 'react/jsx-runtime';
8
8
  import '@yamada-ui/form-control';
9
9
  import '@yamada-ui/popover';
@@ -344,20 +344,20 @@ var defaultFormat = (value) => {
344
344
  value = value.toUpperCase();
345
345
  return value;
346
346
  };
347
- var flattenData = (data) => {
348
- const filterData = (data2) => data2.map((data3) => {
349
- const { value, isDisabled, isFocusable } = data3;
347
+ var flattenOptions = (options) => {
348
+ const filterOptions = (options2) => options2.map((options3) => {
349
+ const { value, isDisabled, isFocusable } = options3;
350
350
  const trulyDisabled = !!isDisabled && !isFocusable;
351
351
  const isMulti = (0, import_utils6.isArray)(value);
352
352
  if (trulyDisabled)
353
353
  return;
354
354
  if (!isMulti) {
355
- return data3;
355
+ return options3;
356
356
  } else {
357
- return filterData(value);
357
+ return filterOptions(value);
358
358
  }
359
359
  }).filter(Boolean);
360
- return filterData(data).flat(Infinity);
360
+ return filterOptions(options).flat(Infinity);
361
361
  };
362
362
  var isTargetOption = (target) => {
363
363
  var _a;
@@ -396,7 +396,7 @@ var useAutocomplete = ({
396
396
  const { id } = rest;
397
397
  const formControlProps = (0, import_utils6.pickObject)(rest, import_form_control.formControlProperties);
398
398
  const [containerProps, inputProps] = (0, import_utils6.splitObject)(
399
- (0, import_utils6.omitObject)(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
399
+ (0, import_utils6.omitObject)(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
400
400
  import_core6.layoutStylesProperties
401
401
  );
402
402
  const descendants = useAutocompleteDescendants();
@@ -405,7 +405,7 @@ var useAutocomplete = ({
405
405
  const inputRef = (0, import_react.useRef)(null);
406
406
  const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
407
407
  const isComposition = (0, import_react.useRef)(false);
408
- const [data, setData] = (0, import_react.useState)(rest.data);
408
+ const [options, setOptions] = (0, import_react.useState)(rest.options);
409
409
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
410
410
  value: rest.value,
411
411
  defaultValue: rest.defaultValue,
@@ -423,7 +423,7 @@ var useAutocomplete = ({
423
423
  const isEmptyValue = !isMulti ? !value : !value.length;
424
424
  if (createOption && !(0, import_utils6.isUndefined)(children)) {
425
425
  console.warn(
426
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
426
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
427
427
  );
428
428
  }
429
429
  const selectedValues = descendants.enabledValues(
@@ -437,7 +437,7 @@ var useAutocomplete = ({
437
437
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
438
438
  );
439
439
  const validChildren = (0, import_utils6.getValidChildren)(children);
440
- const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
440
+ const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
441
441
  if (!(0, import_utils6.isArray)(value2)) {
442
442
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
443
443
  } else {
@@ -701,20 +701,20 @@ var useAutocomplete = ({
701
701
  if (!listRef.current)
702
702
  return;
703
703
  const newOption = { label: inputValue, value: inputValue };
704
- let newData = [];
705
- if (data)
706
- newData = data;
704
+ let newOptions = [];
705
+ if (options)
706
+ newOptions = options;
707
707
  if (createOrder === "first") {
708
- newData = [newOption, ...newData];
708
+ newOptions = [newOption, ...newOptions];
709
709
  } else if (createOrder === "last") {
710
- newData = [...newData, newOption];
710
+ newOptions = [...newOptions, newOption];
711
711
  } else {
712
- const i = newData.findIndex(({ label }) => label === createOrder);
713
- if (i !== -1 && (0, import_utils6.isArray)(newData[i].value)) {
712
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
713
+ if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
714
714
  if (createSecondOrder === "first") {
715
- newData[i].value = [newOption, ...newData[i].value];
715
+ newOptions[i].value = [newOption, ...newOptions[i].value];
716
716
  } else {
717
- newData[i].value = [...newData[i].value, newOption];
717
+ newOptions[i].value = [...newOptions[i].value, newOption];
718
718
  }
719
719
  } else {
720
720
  console.warn(
@@ -722,13 +722,13 @@ var useAutocomplete = ({
722
722
  );
723
723
  }
724
724
  }
725
- setData(newData);
725
+ setOptions(newOptions);
726
726
  onChange(inputValue);
727
727
  rebirthOptions(false);
728
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
728
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
729
729
  setFocusedIndex(index);
730
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
731
- }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
730
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
731
+ }, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
732
732
  const onDelete = (0, import_react.useCallback)(() => {
733
733
  if (!isMulti) {
734
734
  onChange("");
@@ -743,10 +743,8 @@ var useAutocomplete = ({
743
743
  setDisplayValue(void 0);
744
744
  setInputValue("");
745
745
  rebirthOptions();
746
- if (inputRef.current)
747
- inputRef.current.focus();
748
746
  },
749
- [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
747
+ [setDisplayValue, setInputValue, setValue, rebirthOptions]
750
748
  );
751
749
  const onClick = (0, import_react.useCallback)(() => {
752
750
  if (isOpen) {
@@ -878,10 +876,9 @@ var useAutocomplete = ({
878
876
  ...props,
879
877
  ...formControlProps,
880
878
  onClick: (0, import_utils6.handlerAll)(props.onClick, rest.onClick, onClick),
881
- onFocus: (0, import_utils6.handlerAll)(props.onFocus, rest.onFocus, onFocus),
882
879
  onBlur: (0, import_utils6.handlerAll)(props.onBlur, rest.onBlur, onBlur)
883
880
  }),
884
- [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
881
+ [containerProps, formControlProps, onBlur, onClick, rest]
885
882
  );
886
883
  const getFieldProps = (0, import_react.useCallback)(
887
884
  (props = {}, ref = null) => ({
@@ -892,9 +889,10 @@ var useAutocomplete = ({
892
889
  placeholder,
893
890
  "data-active": (0, import_utils6.dataAttr)(isOpen),
894
891
  "aria-expanded": (0, import_utils6.dataAttr)(isOpen),
892
+ onFocus: (0, import_utils6.handlerAll)(props.onFocus, rest.onFocus, onFocus),
895
893
  onKeyDown: (0, import_utils6.handlerAll)(props.onKeyDown, rest.onKeyDown, onKeyDown)
896
894
  }),
897
- [formControlProps, placeholder, isOpen, rest, onKeyDown]
895
+ [formControlProps, placeholder, isOpen, rest, onFocus, onKeyDown]
898
896
  );
899
897
  return {
900
898
  id,
@@ -1003,6 +1001,8 @@ var useAutocompleteList = () => {
1003
1001
  (0, import_react.useEffect)(() => {
1004
1002
  if (!listRef.current || !selectedValue)
1005
1003
  return;
1004
+ if (beforeFocusedIndex.current === selectedValue.index)
1005
+ return;
1006
1006
  const parent = listRef.current;
1007
1007
  const child = selectedValue.node;
1008
1008
  const parentHeight = parent.clientHeight;
@@ -1535,8 +1535,7 @@ var MultiAutocompleteField = (0, import_core8.forwardRef)(
1535
1535
  marginBlockStart: "0.125rem",
1536
1536
  marginBlockEnd: "0.125rem",
1537
1537
  placeholder: !displayValue || keepPlaceholder && isOpen ? placeholder : void 0,
1538
- ...getInputProps(inputProps, ref),
1539
- value: inputValue
1538
+ ...getInputProps({ ...inputProps, value: inputValue != null ? inputValue : "" }, ref)
1540
1539
  }
1541
1540
  )
1542
1541
  ]
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MultiAutocomplete
3
- } from "./chunk-MG2KF34Q.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  MultiAutocomplete
6
6
  };
@@ -3363,7 +3363,7 @@ type UseAutocompleteBaseProps<T extends MaybeValue = string> = Omit<PopoverProps
3363
3363
  omitSelectedValues?: boolean;
3364
3364
  maxSelectedValues?: number;
3365
3365
  optionProps?: Omit<AutocompleteOptionProps, 'value' | 'children'>;
3366
- data?: UIOption[];
3366
+ options?: UIOption[];
3367
3367
  };
3368
3368
  type UseAutocompleteProps<T extends MaybeValue = string> = Omit<HTMLUIProps<'input'>, keyof UseAutocompleteBaseProps | 'list' | 'disabled' | 'required' | 'readOnly' | 'size'> & UseAutocompleteBaseProps<T>;
3369
3369
  declare const useAutocomplete: <T extends MaybeValue = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, createOption, createOrder, createSecondOrder, emptyMessage, format, placement, duration, optionProps, placeholder, children, ...rest }: UseAutocompleteProps<T>) => {
@@ -4004,7 +4004,7 @@ declare const useAutocomplete: <T extends MaybeValue = string>({ defaultIsOpen,
4004
4004
  getPopoverProps: (props?: PopoverProps) => PopoverProps;
4005
4005
  getContainerProps: PropGetter;
4006
4006
  getFieldProps: PropGetter;
4007
- inputProps: Omit<Omit<Dict, "value" | "id" | "onChange" | "month" | "onChangeMonth">, any>;
4007
+ inputProps: Omit<Omit<Dict, "value" | "defaultValue" | "id" | "onChange" | "month" | "onChangeMonth">, any>;
4008
4008
  };
4009
4009
  type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>;
4010
4010
  declare const useAutocompleteInput: () => {
@@ -5,4 +5,4 @@ import '@yamada-ui/form-control';
5
5
  import '@yamada-ui/popover';
6
6
  import '@yamada-ui/select';
7
7
  import '@yamada-ui/utils';
8
- export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider, M as MaybeValue, s as UseAutocompleteCreateReturn, v as UseAutocompleteEmptyReturn, k as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, n as UseAutocompleteOptionGroupReturn, o as UseAutocompleteOptionProps, q as UseAutocompleteOptionReturn, b as UseAutocompleteProps, i as UseAutocompleteReturn, h as useAutocomplete, g as useAutocompleteContext, r as useAutocompleteCreate, e as useAutocompleteDescendant, d as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, t as useAutocompleteEmpty, j as useAutocompleteInput, l as useAutocompleteList, p as useAutocompleteOption, m as useAutocompleteOptionGroup } from './use-autocomplete-42515ffb.js';
8
+ export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider, M as MaybeValue, s as UseAutocompleteCreateReturn, v as UseAutocompleteEmptyReturn, k as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, n as UseAutocompleteOptionGroupReturn, o as UseAutocompleteOptionProps, q as UseAutocompleteOptionReturn, b as UseAutocompleteProps, i as UseAutocompleteReturn, h as useAutocomplete, g as useAutocompleteContext, r as useAutocompleteCreate, e as useAutocompleteDescendant, d as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, t as useAutocompleteEmpty, j as useAutocompleteInput, l as useAutocompleteList, p as useAutocompleteOption, m as useAutocompleteOptionGroup } from './use-autocomplete-4995431c.js';
@@ -288,20 +288,20 @@ var defaultFormat = (value) => {
288
288
  value = value.toUpperCase();
289
289
  return value;
290
290
  };
291
- var flattenData = (data) => {
292
- const filterData = (data2) => data2.map((data3) => {
293
- const { value, isDisabled, isFocusable } = data3;
291
+ var flattenOptions = (options) => {
292
+ const filterOptions = (options2) => options2.map((options3) => {
293
+ const { value, isDisabled, isFocusable } = options3;
294
294
  const trulyDisabled = !!isDisabled && !isFocusable;
295
295
  const isMulti = (0, import_utils4.isArray)(value);
296
296
  if (trulyDisabled)
297
297
  return;
298
298
  if (!isMulti) {
299
- return data3;
299
+ return options3;
300
300
  } else {
301
- return filterData(value);
301
+ return filterOptions(value);
302
302
  }
303
303
  }).filter(Boolean);
304
- return filterData(data).flat(Infinity);
304
+ return filterOptions(options).flat(Infinity);
305
305
  };
306
306
  var isTargetOption = (target) => {
307
307
  var _a;
@@ -340,7 +340,7 @@ var useAutocomplete = ({
340
340
  const { id } = rest;
341
341
  const formControlProps = (0, import_utils4.pickObject)(rest, import_form_control.formControlProperties);
342
342
  const [containerProps, inputProps] = (0, import_utils4.splitObject)(
343
- (0, import_utils4.omitObject)(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
343
+ (0, import_utils4.omitObject)(rest, ["id", "value", "defaultValue", "onChange", "month", "onChangeMonth"]),
344
344
  import_core4.layoutStylesProperties
345
345
  );
346
346
  const descendants = useAutocompleteDescendants();
@@ -349,7 +349,7 @@ var useAutocomplete = ({
349
349
  const inputRef = (0, import_react2.useRef)(null);
350
350
  const timeoutIds = (0, import_react2.useRef)(/* @__PURE__ */ new Set([]));
351
351
  const isComposition = (0, import_react2.useRef)(false);
352
- const [data, setData] = (0, import_react2.useState)(rest.data);
352
+ const [options, setOptions] = (0, import_react2.useState)(rest.options);
353
353
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
354
354
  value: rest.value,
355
355
  defaultValue: rest.defaultValue,
@@ -367,7 +367,7 @@ var useAutocomplete = ({
367
367
  const isEmptyValue = !isMulti ? !value : !value.length;
368
368
  if (createOption && !(0, import_utils4.isUndefined)(children)) {
369
369
  console.warn(
370
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
370
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
371
371
  );
372
372
  }
373
373
  const selectedValues = descendants.enabledValues(
@@ -381,7 +381,7 @@ var useAutocomplete = ({
381
381
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
382
382
  );
383
383
  const validChildren = (0, import_utils4.getValidChildren)(children);
384
- const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
384
+ const computedChildren = options == null ? void 0 : options.map(({ label, value: value2, ...props }, i) => {
385
385
  if (!(0, import_utils4.isArray)(value2)) {
386
386
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
387
387
  } else {
@@ -645,20 +645,20 @@ var useAutocomplete = ({
645
645
  if (!listRef.current)
646
646
  return;
647
647
  const newOption = { label: inputValue, value: inputValue };
648
- let newData = [];
649
- if (data)
650
- newData = data;
648
+ let newOptions = [];
649
+ if (options)
650
+ newOptions = options;
651
651
  if (createOrder === "first") {
652
- newData = [newOption, ...newData];
652
+ newOptions = [newOption, ...newOptions];
653
653
  } else if (createOrder === "last") {
654
- newData = [...newData, newOption];
654
+ newOptions = [...newOptions, newOption];
655
655
  } else {
656
- const i = newData.findIndex(({ label }) => label === createOrder);
657
- if (i !== -1 && (0, import_utils4.isArray)(newData[i].value)) {
656
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
657
+ if (i !== -1 && (0, import_utils4.isArray)(newOptions[i].value)) {
658
658
  if (createSecondOrder === "first") {
659
- newData[i].value = [newOption, ...newData[i].value];
659
+ newOptions[i].value = [newOption, ...newOptions[i].value];
660
660
  } else {
661
- newData[i].value = [...newData[i].value, newOption];
661
+ newOptions[i].value = [...newOptions[i].value, newOption];
662
662
  }
663
663
  } else {
664
664
  console.warn(
@@ -666,13 +666,13 @@ var useAutocomplete = ({
666
666
  );
667
667
  }
668
668
  }
669
- setData(newData);
669
+ setOptions(newOptions);
670
670
  onChange(inputValue);
671
671
  rebirthOptions(false);
672
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
672
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
673
673
  setFocusedIndex(index);
674
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
675
- }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
674
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
675
+ }, [inputValue, options, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
676
676
  const onDelete = (0, import_react2.useCallback)(() => {
677
677
  if (!isMulti) {
678
678
  onChange("");
@@ -687,10 +687,8 @@ var useAutocomplete = ({
687
687
  setDisplayValue(void 0);
688
688
  setInputValue("");
689
689
  rebirthOptions();
690
- if (inputRef.current)
691
- inputRef.current.focus();
692
690
  },
693
- [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
691
+ [setDisplayValue, setInputValue, setValue, rebirthOptions]
694
692
  );
695
693
  const onClick = (0, import_react2.useCallback)(() => {
696
694
  if (isOpen) {
@@ -822,10 +820,9 @@ var useAutocomplete = ({
822
820
  ...props,
823
821
  ...formControlProps,
824
822
  onClick: (0, import_utils4.handlerAll)(props.onClick, rest.onClick, onClick),
825
- onFocus: (0, import_utils4.handlerAll)(props.onFocus, rest.onFocus, onFocus),
826
823
  onBlur: (0, import_utils4.handlerAll)(props.onBlur, rest.onBlur, onBlur)
827
824
  }),
828
- [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
825
+ [containerProps, formControlProps, onBlur, onClick, rest]
829
826
  );
830
827
  const getFieldProps = (0, import_react2.useCallback)(
831
828
  (props = {}, ref = null) => ({
@@ -836,9 +833,10 @@ var useAutocomplete = ({
836
833
  placeholder,
837
834
  "data-active": (0, import_utils4.dataAttr)(isOpen),
838
835
  "aria-expanded": (0, import_utils4.dataAttr)(isOpen),
836
+ onFocus: (0, import_utils4.handlerAll)(props.onFocus, rest.onFocus, onFocus),
839
837
  onKeyDown: (0, import_utils4.handlerAll)(props.onKeyDown, rest.onKeyDown, onKeyDown)
840
838
  }),
841
- [formControlProps, placeholder, isOpen, rest, onKeyDown]
839
+ [formControlProps, placeholder, isOpen, rest, onFocus, onKeyDown]
842
840
  );
843
841
  return {
844
842
  id,
@@ -947,6 +945,8 @@ var useAutocompleteList = () => {
947
945
  (0, import_react2.useEffect)(() => {
948
946
  if (!listRef.current || !selectedValue)
949
947
  return;
948
+ if (beforeFocusedIndex.current === selectedValue.index)
949
+ return;
950
950
  const parent = listRef.current;
951
951
  const child = selectedValue.node;
952
952
  const parentHeight = parent.clientHeight;
@@ -12,7 +12,7 @@ import {
12
12
  useAutocompleteList,
13
13
  useAutocompleteOption,
14
14
  useAutocompleteOptionGroup
15
- } from "./chunk-MG2KF34Q.mjs";
15
+ } from "./chunk-YQULJUTP.mjs";
16
16
  export {
17
17
  AutocompleteDescendantsContextProvider,
18
18
  AutocompleteProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/autocomplete",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Yamada UI autocomplete component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -36,16 +36,16 @@
36
36
  "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@yamada-ui/core": "0.2.1",
39
+ "@yamada-ui/core": "0.2.2",
40
40
  "@yamada-ui/utils": "0.1.1",
41
- "@yamada-ui/icon": "0.1.8",
42
- "@yamada-ui/select": "0.1.8",
43
- "@yamada-ui/form-control": "0.1.8",
44
- "@yamada-ui/popover": "0.1.8",
41
+ "@yamada-ui/icon": "0.1.9",
42
+ "@yamada-ui/select": "0.1.10",
43
+ "@yamada-ui/form-control": "0.1.9",
44
+ "@yamada-ui/popover": "0.1.9",
45
45
  "@yamada-ui/use-descendant": "0.1.1",
46
46
  "@yamada-ui/use-clickable": "0.1.1",
47
47
  "@yamada-ui/use-outside-click": "0.1.1",
48
- "@yamada-ui/use-controllable-state": "0.1.1"
48
+ "@yamada-ui/use-controllable-state": "0.1.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "react": "^18.0.0",