@yamada-ui/autocomplete 0.1.9 → 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-UJYX53L6.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-UJYX53L6.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-UJYX53L6.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-UJYX53L6.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-2e4e8207.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-UJYX53L6.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-2e4e8207.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-UJYX53L6.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-2e4e8207.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;
@@ -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("");
@@ -1000,6 +1000,8 @@ var useAutocompleteList = () => {
1000
1000
  (0, import_react.useEffect)(() => {
1001
1001
  if (!listRef.current || !selectedValue)
1002
1002
  return;
1003
+ if (beforeFocusedIndex.current === selectedValue.index)
1004
+ return;
1003
1005
  const parent = listRef.current;
1004
1006
  const child = selectedValue.node;
1005
1007
  const parentHeight = parent.clientHeight;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Autocomplete
3
- } from "./chunk-UJYX53L6.mjs";
3
+ } from "./chunk-YQULJUTP.mjs";
4
4
  export {
5
5
  Autocomplete
6
6
  };
@@ -692,20 +692,20 @@ var defaultFormat = (value) => {
692
692
  value = value.toUpperCase();
693
693
  return value;
694
694
  };
695
- var flattenData = (data) => {
696
- const filterData = (data2) => data2.map((data3) => {
697
- const { value, isDisabled, isFocusable } = data3;
695
+ var flattenOptions = (options) => {
696
+ const filterOptions = (options2) => options2.map((options3) => {
697
+ const { value, isDisabled, isFocusable } = options3;
698
698
  const trulyDisabled = !!isDisabled && !isFocusable;
699
699
  const isMulti = isArray(value);
700
700
  if (trulyDisabled)
701
701
  return;
702
702
  if (!isMulti) {
703
- return data3;
703
+ return options3;
704
704
  } else {
705
- return filterData(value);
705
+ return filterOptions(value);
706
706
  }
707
707
  }).filter(Boolean);
708
- return filterData(data).flat(Infinity);
708
+ return filterOptions(options).flat(Infinity);
709
709
  };
710
710
  var isTargetOption = (target) => {
711
711
  var _a;
@@ -753,7 +753,7 @@ var useAutocomplete = ({
753
753
  const inputRef = useRef2(null);
754
754
  const timeoutIds = useRef2(/* @__PURE__ */ new Set([]));
755
755
  const isComposition = useRef2(false);
756
- const [data, setData] = useState(rest.data);
756
+ const [options, setOptions] = useState(rest.options);
757
757
  const [value, setValue] = useControllableState({
758
758
  value: rest.value,
759
759
  defaultValue: rest.defaultValue,
@@ -771,7 +771,7 @@ var useAutocomplete = ({
771
771
  const isEmptyValue = !isMulti ? !value : !value.length;
772
772
  if (createOption && !isUndefined(children)) {
773
773
  console.warn(
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 '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.`
775
775
  );
776
776
  }
777
777
  const selectedValues = descendants.enabledValues(
@@ -785,7 +785,7 @@ var useAutocomplete = ({
785
785
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
786
786
  );
787
787
  const validChildren = getValidChildren2(children);
788
- 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) => {
789
789
  if (!isArray(value2)) {
790
790
  return /* @__PURE__ */ jsx8(AutocompleteOption, { value: value2, ...props, children: label }, i);
791
791
  } else {
@@ -1049,20 +1049,20 @@ var useAutocomplete = ({
1049
1049
  if (!listRef.current)
1050
1050
  return;
1051
1051
  const newOption = { label: inputValue, value: inputValue };
1052
- let newData = [];
1053
- if (data)
1054
- newData = data;
1052
+ let newOptions = [];
1053
+ if (options)
1054
+ newOptions = options;
1055
1055
  if (createOrder === "first") {
1056
- newData = [newOption, ...newData];
1056
+ newOptions = [newOption, ...newOptions];
1057
1057
  } else if (createOrder === "last") {
1058
- newData = [...newData, newOption];
1058
+ newOptions = [...newOptions, newOption];
1059
1059
  } else {
1060
- const i = newData.findIndex(({ label }) => label === createOrder);
1061
- if (i !== -1 && isArray(newData[i].value)) {
1060
+ const i = newOptions.findIndex(({ label }) => label === createOrder);
1061
+ if (i !== -1 && isArray(newOptions[i].value)) {
1062
1062
  if (createSecondOrder === "first") {
1063
- newData[i].value = [newOption, ...newData[i].value];
1063
+ newOptions[i].value = [newOption, ...newOptions[i].value];
1064
1064
  } else {
1065
- newData[i].value = [...newData[i].value, newOption];
1065
+ newOptions[i].value = [...newOptions[i].value, newOption];
1066
1066
  }
1067
1067
  } else {
1068
1068
  console.warn(
@@ -1070,13 +1070,13 @@ var useAutocomplete = ({
1070
1070
  );
1071
1071
  }
1072
1072
  }
1073
- setData(newData);
1073
+ setOptions(newOptions);
1074
1074
  onChange(inputValue);
1075
1075
  rebirthOptions(false);
1076
- const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
1076
+ const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
1077
1077
  setFocusedIndex(index);
1078
- (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
1079
- }, [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]);
1080
1080
  const onDelete = useCallback(() => {
1081
1081
  if (!isMulti) {
1082
1082
  onChange("");
@@ -1349,6 +1349,8 @@ var useAutocompleteList = () => {
1349
1349
  useEffect(() => {
1350
1350
  if (!listRef.current || !selectedValue)
1351
1351
  return;
1352
+ if (beforeFocusedIndex.current === selectedValue.index)
1353
+ return;
1352
1354
  const parent = listRef.current;
1353
1355
  const child = selectedValue.node;
1354
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-2e4e8207.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;
@@ -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("");
@@ -805,6 +805,8 @@ var useAutocompleteList = () => {
805
805
  (0, import_react.useEffect)(() => {
806
806
  if (!listRef.current || !selectedValue)
807
807
  return;
808
+ if (beforeFocusedIndex.current === selectedValue.index)
809
+ return;
808
810
  const parent = listRef.current;
809
811
  const child = selectedValue.node;
810
812
  const parentHeight = parent.clientHeight;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  AutocompleteOption,
6
6
  AutocompleteOptionGroup,
7
7
  MultiAutocomplete
8
- } from "./chunk-UJYX53L6.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-2e4e8207.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;
@@ -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("");
@@ -1001,6 +1001,8 @@ var useAutocompleteList = () => {
1001
1001
  (0, import_react.useEffect)(() => {
1002
1002
  if (!listRef.current || !selectedValue)
1003
1003
  return;
1004
+ if (beforeFocusedIndex.current === selectedValue.index)
1005
+ return;
1004
1006
  const parent = listRef.current;
1005
1007
  const child = selectedValue.node;
1006
1008
  const parentHeight = parent.clientHeight;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MultiAutocomplete
3
- } from "./chunk-UJYX53L6.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>) => {
@@ -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-2e4e8207.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;
@@ -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("");
@@ -945,6 +945,8 @@ var useAutocompleteList = () => {
945
945
  (0, import_react2.useEffect)(() => {
946
946
  if (!listRef.current || !selectedValue)
947
947
  return;
948
+ if (beforeFocusedIndex.current === selectedValue.index)
949
+ return;
948
950
  const parent = listRef.current;
949
951
  const child = selectedValue.node;
950
952
  const parentHeight = parent.clientHeight;
@@ -12,7 +12,7 @@ import {
12
12
  useAutocompleteList,
13
13
  useAutocompleteOption,
14
14
  useAutocompleteOptionGroup
15
- } from "./chunk-UJYX53L6.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.9",
3
+ "version": "0.1.10",
4
4
  "description": "Yamada UI autocomplete component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -39,7 +39,7 @@
39
39
  "@yamada-ui/core": "0.2.2",
40
40
  "@yamada-ui/utils": "0.1.1",
41
41
  "@yamada-ui/icon": "0.1.9",
42
- "@yamada-ui/select": "0.1.9",
42
+ "@yamada-ui/select": "0.1.10",
43
43
  "@yamada-ui/form-control": "0.1.9",
44
44
  "@yamada-ui/popover": "0.1.9",
45
45
  "@yamada-ui/use-descendant": "0.1.1",