@yamada-ui/autocomplete 1.6.0-dev-20241011153139 → 1.6.0-dev-20241011162716

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/dist/autocomplete-context.d.mts +2 -4
  2. package/dist/autocomplete-context.d.ts +2 -4
  3. package/dist/autocomplete-context.js.map +1 -1
  4. package/dist/autocomplete-context.mjs +1 -1
  5. package/dist/autocomplete-create.js.map +1 -1
  6. package/dist/autocomplete-create.mjs +4 -4
  7. package/dist/autocomplete-empty.js.map +1 -1
  8. package/dist/autocomplete-empty.mjs +4 -4
  9. package/dist/autocomplete-icon.js.map +1 -1
  10. package/dist/autocomplete-icon.mjs +2 -2
  11. package/dist/autocomplete-list.js.map +1 -1
  12. package/dist/autocomplete-list.mjs +3 -3
  13. package/dist/autocomplete-option-group.js.map +1 -1
  14. package/dist/autocomplete-option-group.mjs +3 -3
  15. package/dist/autocomplete-option.js +11 -14
  16. package/dist/autocomplete-option.js.map +1 -1
  17. package/dist/autocomplete-option.mjs +4 -4
  18. package/dist/autocomplete.d.mts +0 -1
  19. package/dist/autocomplete.d.ts +0 -1
  20. package/dist/autocomplete.js +51 -88
  21. package/dist/autocomplete.js.map +1 -1
  22. package/dist/autocomplete.mjs +12 -12
  23. package/dist/{chunk-WERCEZNJ.mjs → chunk-352YZTOO.mjs} +39 -62
  24. package/dist/chunk-352YZTOO.mjs.map +1 -0
  25. package/dist/{chunk-V6YCG642.mjs → chunk-6OTUOEYS.mjs} +2 -2
  26. package/dist/{chunk-67X7JKWL.mjs → chunk-7QON6ZHO.mjs} +2 -2
  27. package/dist/{chunk-7LZUXESV.mjs → chunk-HUY7Q3WA.mjs} +14 -25
  28. package/dist/chunk-HUY7Q3WA.mjs.map +1 -0
  29. package/dist/{chunk-K5HCHHCJ.mjs → chunk-J6UKIKNL.mjs} +4 -4
  30. package/dist/{chunk-AIBJWPRA.mjs → chunk-KWIJUSLC.mjs} +4 -4
  31. package/dist/{chunk-Q33EMTO2.mjs → chunk-OY5JVCQQ.mjs} +14 -24
  32. package/dist/chunk-OY5JVCQQ.mjs.map +1 -0
  33. package/dist/{chunk-2HJUFFCU.mjs → chunk-PKRO525W.mjs} +4 -4
  34. package/dist/{chunk-VTBUO5SK.mjs → chunk-WJ4P4B2E.mjs} +3 -3
  35. package/dist/{chunk-4SBNPEK7.mjs → chunk-WNN655FX.mjs} +3 -3
  36. package/dist/{chunk-TR4X4EEG.mjs → chunk-X2PFHBZY.mjs} +2 -2
  37. package/dist/{chunk-WDQYM4FP.mjs → chunk-ZNO5RUVT.mjs} +1 -1
  38. package/dist/chunk-ZNO5RUVT.mjs.map +1 -0
  39. package/dist/{chunk-6OLHNK7O.mjs → chunk-ZXALWDKQ.mjs} +14 -18
  40. package/dist/chunk-ZXALWDKQ.mjs.map +1 -0
  41. package/dist/index.d.mts +0 -1
  42. package/dist/index.d.ts +0 -1
  43. package/dist/index.js +57 -105
  44. package/dist/index.js.map +1 -1
  45. package/dist/index.mjs +13 -13
  46. package/dist/multi-autocomplete.d.mts +0 -1
  47. package/dist/multi-autocomplete.d.ts +0 -1
  48. package/dist/multi-autocomplete.js +51 -89
  49. package/dist/multi-autocomplete.js.map +1 -1
  50. package/dist/multi-autocomplete.mjs +12 -12
  51. package/dist/use-autocomplete-list.js.map +1 -1
  52. package/dist/use-autocomplete-list.mjs +2 -2
  53. package/dist/use-autocomplete-option-group.js.map +1 -1
  54. package/dist/use-autocomplete-option-group.mjs +2 -2
  55. package/dist/use-autocomplete-option.js +11 -14
  56. package/dist/use-autocomplete-option.js.map +1 -1
  57. package/dist/use-autocomplete-option.mjs +2 -2
  58. package/dist/use-autocomplete.d.mts +11 -16
  59. package/dist/use-autocomplete.d.ts +11 -16
  60. package/dist/use-autocomplete.js +45 -72
  61. package/dist/use-autocomplete.js.map +1 -1
  62. package/dist/use-autocomplete.mjs +7 -7
  63. package/package.json +13 -13
  64. package/dist/chunk-6OLHNK7O.mjs.map +0 -1
  65. package/dist/chunk-7LZUXESV.mjs.map +0 -1
  66. package/dist/chunk-Q33EMTO2.mjs.map +0 -1
  67. package/dist/chunk-WDQYM4FP.mjs.map +0 -1
  68. package/dist/chunk-WERCEZNJ.mjs.map +0 -1
  69. /package/dist/{chunk-V6YCG642.mjs.map → chunk-6OTUOEYS.mjs.map} +0 -0
  70. /package/dist/{chunk-67X7JKWL.mjs.map → chunk-7QON6ZHO.mjs.map} +0 -0
  71. /package/dist/{chunk-K5HCHHCJ.mjs.map → chunk-J6UKIKNL.mjs.map} +0 -0
  72. /package/dist/{chunk-AIBJWPRA.mjs.map → chunk-KWIJUSLC.mjs.map} +0 -0
  73. /package/dist/{chunk-2HJUFFCU.mjs.map → chunk-PKRO525W.mjs.map} +0 -0
  74. /package/dist/{chunk-VTBUO5SK.mjs.map → chunk-WJ4P4B2E.mjs.map} +0 -0
  75. /package/dist/{chunk-4SBNPEK7.mjs.map → chunk-WNN655FX.mjs.map} +0 -0
  76. /package/dist/{chunk-TR4X4EEG.mjs.map → chunk-X2PFHBZY.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/autocomplete.tsx"],"sourcesContent":["import type { CSSUIObject, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { MotionProps } from \"@yamada-ui/motion\"\nimport type { PortalProps } from \"@yamada-ui/portal\"\nimport type { FC, ReactNode } from \"react\"\nimport type { AutocompleteCreateProps } from \"./autocomplete-create\"\nimport type { AutocompleteEmptyProps } from \"./autocomplete-empty\"\nimport type { AutocompleteIconProps } from \"./autocomplete-icon\"\nimport type { AutocompleteListProps } from \"./autocomplete-list\"\nimport type { UseAutocompleteProps } from \"./use-autocomplete\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { Popover, PopoverTrigger } from \"@yamada-ui/popover\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { cx, runIfFunc } from \"@yamada-ui/utils\"\nimport {\n AutocompleteDescendantsContextProvider,\n AutocompleteProvider,\n useAutocompleteContext,\n} from \"./autocomplete-context\"\nimport { AutocompleteCreate } from \"./autocomplete-create\"\nimport { AutocompleteEmpty } from \"./autocomplete-empty\"\nimport { AutocompleteIcon } from \"./autocomplete-icon\"\nimport { AutocompleteList } from \"./autocomplete-list\"\nimport { useAutocomplete, useAutocompleteInput } from \"./use-autocomplete\"\n\ninterface AutocompleteOptions {\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: string\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: string\n /**\n * The footer of the autocomplete content element.\n */\n footer?: FC<{ value: string | undefined; onClose: () => void }> | ReactNode\n /**\n * The header of the autocomplete content element.\n */\n header?: FC<{ value: string | undefined; onClose: () => void }> | ReactNode\n /**\n * Props for autocomplete container element.\n */\n containerProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for autocomplete content element.\n */\n contentProps?: Omit<MotionProps, \"children\">\n /**\n * Props for autocomplete create element.\n */\n createProps?: Omit<AutocompleteCreateProps, \"children\">\n /**\n * Props for autocomplete empty element.\n */\n emptyProps?: Omit<AutocompleteEmptyProps, \"children\">\n /**\n * Props for autocomplete field element.\n */\n fieldProps?: Omit<AutocompleteFieldProps, \"children\" | \"inputProps\">\n /**\n * Props for autocomplete icon element.\n */\n iconProps?: AutocompleteIconProps\n /**\n * Props for autocomplete input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for autocomplete list element.\n */\n listProps?: Omit<AutocompleteListProps, \"children\">\n /**\n * Props to be forwarded to the portal component.\n *\n * @default '{ isDisabled: true }'\n */\n portalProps?: Omit<PortalProps, \"children\">\n}\n\nexport interface AutocompleteProps\n extends ThemeProps<\"Autocomplete\">,\n Omit<UseAutocompleteProps, \"maxSelectValues\" | \"omitSelectedValues\">,\n AutocompleteOptions {}\n\n/**\n * `Autocomplete` is a component used to display suggestions in response to user text input.\n *\n * @see Docs https://yamada-ui.com/components/forms/autocomplete\n */\nexport const Autocomplete = forwardRef<AutocompleteProps, \"input\">(\n (props, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Autocomplete\", props)\n let {\n className,\n color,\n defaultValue = \"\",\n footer,\n h,\n header,\n height,\n minH,\n minHeight,\n containerProps,\n contentProps,\n createProps,\n emptyProps,\n fieldProps,\n iconProps,\n inputProps,\n listProps,\n portalProps = { isDisabled: true },\n ...computedProps\n } = omitThemeProps(mergedProps)\n\n const {\n allowCreate,\n children,\n descendants,\n inputValue,\n isEmpty,\n value,\n formControlProps,\n getContainerProps,\n getFieldProps,\n getPopoverProps,\n onClose,\n ...rest\n } = useAutocomplete({ ...computedProps, defaultValue })\n\n h ??= height\n minH ??= minHeight\n\n const css: CSSUIObject = {\n color,\n h: \"fit-content\",\n w: \"100%\",\n ...styles.container,\n }\n\n return (\n <AutocompleteDescendantsContextProvider value={descendants}>\n <AutocompleteProvider\n value={{\n ...rest,\n allowCreate,\n inputValue,\n isEmpty,\n styles,\n value,\n formControlProps,\n onClose,\n }}\n >\n <Popover {...getPopoverProps()}>\n <ui.div\n className={cx(\"ui-autocomplete\", className)}\n __css={css}\n {...getContainerProps(containerProps)}\n >\n <ui.div\n className=\"ui-autocomplete__inner\"\n __css={{ position: \"relative\", ...styles.inner }}\n >\n <AutocompleteField\n h={h}\n minH={minH}\n inputProps={inputProps}\n {...getFieldProps(fieldProps, ref)}\n />\n\n <AutocompleteIcon {...iconProps} {...formControlProps} />\n </ui.div>\n\n <Portal {...portalProps}>\n <AutocompleteList\n footer={runIfFunc(footer, { value, onClose })}\n header={runIfFunc(header, { value, onClose })}\n contentProps={contentProps}\n {...listProps}\n >\n {!isEmpty ? (\n <>\n {allowCreate ? (\n <AutocompleteCreate {...createProps} />\n ) : (\n <AutocompleteEmpty {...emptyProps} />\n )}\n\n {children}\n </>\n ) : allowCreate && inputValue ? (\n <AutocompleteCreate {...createProps} />\n ) : (\n <AutocompleteEmpty {...emptyProps} />\n )}\n </AutocompleteList>\n </Portal>\n </ui.div>\n </Popover>\n </AutocompleteProvider>\n </AutocompleteDescendantsContextProvider>\n )\n },\n)\n\nAutocomplete.displayName = \"Autocomplete\"\nAutocomplete.__ui__ = \"Autocomplete\"\n\ninterface AutocompleteFieldProps\n extends HTMLUIProps,\n Pick<AutocompleteProps, \"inputProps\"> {}\n\nconst AutocompleteField = forwardRef<AutocompleteFieldProps, \"input\">(\n ({ className, h, minH, placeholder, inputProps, ...rest }, ref) => {\n const { inputValue, label, styles } = useAutocompleteContext()\n const { getInputProps } = useAutocompleteInput()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"flex\",\n h,\n minH,\n pe: \"2rem\",\n ...styles.field,\n cursor: \"text\",\n }\n\n return (\n <PopoverTrigger>\n <ui.div\n className={cx(\"ui-autocomplete__field\", className)}\n __css={css}\n {...rest}\n >\n <ui.input\n className=\"ui-autocomplete__field__input\"\n display=\"inline-block\"\n placeholder={placeholder}\n w=\"100%\"\n {...getInputProps(\n { ...inputProps, value: inputValue || label || \"\" },\n ref,\n )}\n />\n </ui.div>\n </PopoverTrigger>\n )\n },\n)\n\nAutocompleteField.displayName = \"AutocompleteField\"\nAutocompleteField.__ui__ = \"AutocompleteField\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,sBAAsB;AACxC,SAAS,cAAc;AACvB,SAAS,IAAI,iBAAiB;AAqJhB,SAsBM,UAlBJ,KAJF;AAtEP,IAAM,eAAe;AAAA,EAC1B,CAAC,OAAO,QAAQ;AACd,UAAM,CAAC,QAAQ,WAAW,IAAI,uBAAuB,gBAAgB,KAAK;AAC1E,QAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,EAAE,YA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mjs";
4
+ } from "./chunk-ZXALWDKQ.mjs";
5
5
  import {
6
6
  AutocompleteItemIcon
7
- } from "./chunk-V6YCG642.mjs";
7
+ } from "./chunk-6OTUOEYS.mjs";
8
8
  import {
9
9
  useAutocompleteContext
10
- } from "./chunk-WDQYM4FP.mjs";
10
+ } from "./chunk-ZNO5RUVT.mjs";
11
11
 
12
12
  // src/autocomplete-empty.tsx
13
13
  import { forwardRef, ui } from "@yamada-ui/core";
@@ -61,4 +61,4 @@ AutocompleteMinusIcon.__ui__ = "AutocompleteMinusIcon";
61
61
  export {
62
62
  AutocompleteEmpty
63
63
  };
64
- //# sourceMappingURL=chunk-2HJUFFCU.mjs.map
64
+ //# sourceMappingURL=chunk-PKRO525W.mjs.map
@@ -1,10 +1,10 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteList
4
- } from "./chunk-TR4X4EEG.mjs";
4
+ } from "./chunk-X2PFHBZY.mjs";
5
5
  import {
6
6
  useAutocompleteContext
7
- } from "./chunk-WDQYM4FP.mjs";
7
+ } from "./chunk-ZNO5RUVT.mjs";
8
8
 
9
9
  // src/autocomplete-list.tsx
10
10
  import { forwardRef, ui } from "@yamada-ui/core";
@@ -86,4 +86,4 @@ AutocompleteList.__ui__ = "AutocompleteList";
86
86
  export {
87
87
  AutocompleteList
88
88
  };
89
- //# sourceMappingURL=chunk-VTBUO5SK.mjs.map
89
+ //# sourceMappingURL=chunk-WJ4P4B2E.mjs.map
@@ -1,10 +1,10 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteOptionGroup
4
- } from "./chunk-67X7JKWL.mjs";
4
+ } from "./chunk-7QON6ZHO.mjs";
5
5
  import {
6
6
  useAutocompleteContext
7
- } from "./chunk-WDQYM4FP.mjs";
7
+ } from "./chunk-ZNO5RUVT.mjs";
8
8
 
9
9
  // src/autocomplete-option-group.tsx
10
10
  import { forwardRef, ui } from "@yamada-ui/core";
@@ -67,4 +67,4 @@ AutocompleteOptionGroup.__ui__ = "AutocompleteOptionGroup";
67
67
  export {
68
68
  AutocompleteOptionGroup
69
69
  };
70
- //# sourceMappingURL=chunk-4SBNPEK7.mjs.map
70
+ //# sourceMappingURL=chunk-WNN655FX.mjs.map
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  useAutocompleteContext,
4
4
  useAutocompleteDescendantsContext
5
- } from "./chunk-WDQYM4FP.mjs";
5
+ } from "./chunk-ZNO5RUVT.mjs";
6
6
 
7
7
  // src/use-autocomplete-list.ts
8
8
  import { mergeRefs, useUpdateEffect } from "@yamada-ui/utils";
@@ -69,4 +69,4 @@ var useAutocompleteList = () => {
69
69
  export {
70
70
  useAutocompleteList
71
71
  };
72
- //# sourceMappingURL=chunk-TR4X4EEG.mjs.map
72
+ //# sourceMappingURL=chunk-X2PFHBZY.mjs.map
@@ -22,4 +22,4 @@ export {
22
22
  AutocompleteProvider,
23
23
  useAutocompleteContext
24
24
  };
25
- //# sourceMappingURL=chunk-WDQYM4FP.mjs.map
25
+ //# sourceMappingURL=chunk-ZNO5RUVT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/autocomplete-context.ts"],"sourcesContent":["import type { CSSUIObject } from \"@yamada-ui/core\"\nimport type { Dispatch, DOMAttributes, RefObject, SetStateAction } from \"react\"\nimport type { UseAutocompleteProps } from \"./use-autocomplete\"\nimport { createDescendant } from \"@yamada-ui/use-descendant\"\nimport { createContext } from \"@yamada-ui/utils\"\n\nexport const {\n DescendantsContextProvider: AutocompleteDescendantsContextProvider,\n useDescendant: useAutocompleteDescendant,\n useDescendants: useAutocompleteDescendants,\n useDescendantsContext: useAutocompleteDescendantsContext,\n} = createDescendant()\n\ninterface AutocompleteContext\n extends Omit<\n UseAutocompleteProps,\n \"defaultValue\" | \"onChange\" | \"onCreate\" | \"value\"\n > {\n focusedIndex: number\n inputRef: RefObject<HTMLInputElement>\n inputValue: string\n isAllSelected: boolean\n isEmpty: boolean\n isHit: boolean\n isOpen: boolean\n label: string | string[] | undefined\n listRef: RefObject<HTMLUListElement>\n pickOptions: (value: string) => void\n rebirthOptions: (runFocus?: boolean) => void\n setFocusedIndex: Dispatch<SetStateAction<number>>\n styles: { [key: string]: CSSUIObject | undefined }\n value: string | string[]\n formControlProps: { [key: string]: any }\n inputProps: DOMAttributes<HTMLInputElement>\n onChange: (newValue: string, runRebirth?: boolean) => void\n onClose: () => void\n onCreate: () => void\n onFocusFirst: () => void\n onFocusLast: () => void\n onFocusNext: (index?: number) => void\n onFocusPrev: (index?: number) => void\n onOpen: () => void\n}\n\nexport const [AutocompleteProvider, useAutocompleteContext] =\n createContext<AutocompleteContext>({\n name: \"AutocompleteContext\",\n errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Autocomplete />\" or \"<MultiAutocomplete />\"`,\n })\n"],"mappings":";;;AAGA,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,IAAI,iBAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,IACxD,cAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;","names":[]}
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  useAutocompleteContext,
4
4
  useAutocompleteDescendant
5
- } from "./chunk-WDQYM4FP.mjs";
5
+ } from "./chunk-ZNO5RUVT.mjs";
6
6
 
7
7
  // src/use-autocomplete-option.ts
8
8
  import {
@@ -14,8 +14,7 @@ import {
14
14
  isNumber,
15
15
  isString,
16
16
  isUndefined,
17
- mergeRefs,
18
- useUpdateEffect
17
+ mergeRefs
19
18
  } from "@yamada-ui/utils";
20
19
  import { useCallback, useId, useRef } from "react";
21
20
  var isTargetOption = (target) => {
@@ -25,7 +24,7 @@ var isTargetOption = (target) => {
25
24
  var useAutocompleteOption = (props) => {
26
25
  var _a, _b;
27
26
  const {
28
- closeOnSelect: generalCloseOnSelect,
27
+ closeOnSelect,
29
28
  focusedIndex,
30
29
  inputRef,
31
30
  omitSelectedValues,
@@ -33,7 +32,6 @@ var useAutocompleteOption = (props) => {
33
32
  value,
34
33
  optionProps,
35
34
  onChange,
36
- onChangeLabel,
37
35
  onClose,
38
36
  onFocusNext
39
37
  } = useAutocompleteContext();
@@ -64,28 +62,27 @@ var useAutocompleteOption = (props) => {
64
62
  );
65
63
  }
66
64
  }
67
- const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
65
+ const isDuplicated = frontValues.some(
66
+ ({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")
67
+ );
68
68
  const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
69
69
  const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
70
70
  const isFocused = index === focusedIndex;
71
71
  const onClick = useCallback(
72
72
  (ev) => {
73
73
  ev.stopPropagation();
74
- if (isDisabled) {
75
- if (inputRef.current) inputRef.current.focus();
76
- return;
77
- }
78
- if (!isTargetOption(ev.currentTarget)) {
74
+ if (isDisabled || !isTargetOption(ev.currentTarget)) {
79
75
  if (inputRef.current) inputRef.current.focus();
80
76
  return;
81
77
  }
82
- setFocusedIndex(index);
78
+ if (!isDuplicated) setFocusedIndex(index);
83
79
  onChange(optionValue != null ? optionValue : "");
84
80
  if (inputRef.current) inputRef.current.focus();
85
- if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
81
+ if (customCloseOnSelect != null ? customCloseOnSelect : closeOnSelect) onClose();
86
82
  if (omitSelectedValues) onFocusNext(index);
87
83
  },
88
84
  [
85
+ isDuplicated,
89
86
  onFocusNext,
90
87
  omitSelectedValues,
91
88
  isDisabled,
@@ -94,14 +91,11 @@ var useAutocompleteOption = (props) => {
94
91
  index,
95
92
  onChange,
96
93
  customCloseOnSelect,
97
- generalCloseOnSelect,
94
+ closeOnSelect,
98
95
  onClose,
99
96
  inputRef
100
97
  ]
101
98
  );
102
- useUpdateEffect(() => {
103
- if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
104
- }, [optionValue]);
105
99
  const getOptionProps = useCallback(
106
100
  (props2 = {}, ref = null) => {
107
101
  const style = {
@@ -125,6 +119,7 @@ var useAutocompleteOption = (props) => {
125
119
  "aria-checked": isSelected,
126
120
  "aria-disabled": ariaAttr(isDisabled),
127
121
  "data-disabled": dataAttr(isDisabled),
122
+ "data-duplicated": dataAttr(isDuplicated),
128
123
  "data-focus": dataAttr(isFocused),
129
124
  "data-target": dataAttr(true),
130
125
  "data-value": optionValue != null ? optionValue : "",
@@ -134,6 +129,7 @@ var useAutocompleteOption = (props) => {
134
129
  },
135
130
  [
136
131
  id,
132
+ isDuplicated,
137
133
  optionValue,
138
134
  computedProps,
139
135
  isDisabled,
@@ -213,4 +209,4 @@ export {
213
209
  useAutocompleteCreate,
214
210
  useAutocompleteEmpty
215
211
  };
216
- //# sourceMappingURL=chunk-6OLHNK7O.mjs.map
212
+ //# sourceMappingURL=chunk-ZXALWDKQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-autocomplete-option.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties, MouseEvent } from \"react\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendant,\n} from \"./autocomplete-context\"\n\nconst isTargetOption = (target: EventTarget | null): boolean =>\n isHTMLElement(target) && !!target.getAttribute(\"role\")?.startsWith(\"option\")\n\nexport interface UseAutocompleteOptionProps\n extends Omit<HTMLUIProps<\"li\">, \"children\" | \"value\"> {\n /**\n * The label of the autocomplete option.\n */\n children?: string\n /**\n * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n */\n isDisabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n */\n isFocusable?: boolean\n /**\n * The value of the autocomplete option.\n */\n value?: string\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n closeOnSelect,\n focusedIndex,\n inputRef,\n omitSelectedValues,\n setFocusedIndex,\n value,\n optionProps,\n onChange,\n onClose,\n onFocusNext,\n } = useAutocompleteContext()\n const id = useId()\n\n let {\n children,\n closeOnSelect: customCloseOnSelect,\n icon: customIcon,\n isDisabled,\n isFocusable,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n\n const trulyDisabled = !!isDisabled && !isFocusable\n\n const itemRef = useRef<HTMLLIElement>(null)\n\n const { descendants, index, register } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n const isMulti = isArray(value)\n\n if (isUndefined(optionValue)) {\n if (isString(children) || isNumber(children)) {\n optionValue = children.toString()\n } else {\n console.warn(\n `${\n !isMulti ? \"Autocomplete\" : \"MultiAutocomplete\"\n }: Cannot infer the option value of complex children. Pass a \\`value\\` prop or use a plain string as children to <Option>.`,\n )\n }\n }\n\n const isDuplicated = frontValues.some(\n ({ node }) => node.dataset.value === (optionValue ?? \"\"),\n )\n const isSelected =\n !isDuplicated &&\n (!isMulti\n ? (optionValue ?? \"\") === value\n : value.includes(optionValue ?? \"\"))\n const isTarget = \"target\" in (itemRef.current?.dataset ?? {})\n const isFocused = index === focusedIndex\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLLIElement>) => {\n ev.stopPropagation()\n\n if (isDisabled || !isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!isDuplicated) setFocusedIndex(index)\n\n onChange(optionValue ?? \"\")\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? closeOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n isDuplicated,\n onFocusNext,\n omitSelectedValues,\n isDisabled,\n optionValue,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n closeOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n const getOptionProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n id,\n ref: mergeRefs(itemRef, ref, register),\n role: \"option\",\n ...computedProps,\n ...props,\n style:\n !isTarget || (omitSelectedValues && isSelected) ? style : undefined,\n \"aria-checked\": isSelected,\n \"aria-disabled\": ariaAttr(isDisabled),\n \"data-disabled\": dataAttr(isDisabled),\n \"data-duplicated\": dataAttr(isDuplicated),\n \"data-focus\": dataAttr(isFocused),\n \"data-target\": dataAttr(true),\n \"data-value\": optionValue ?? \"\",\n tabIndex: -1,\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n id,\n isDuplicated,\n optionValue,\n computedProps,\n isDisabled,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n children,\n customIcon,\n isFocused,\n isSelected,\n getOptionProps,\n }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n\nexport const useAutocompleteCreate = () => {\n const { isHit, onCreate } = useAutocompleteContext()\n\n const getCreateProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n ...props,\n style: isHit ? style : undefined,\n \"data-focus\": dataAttr(!isHit),\n tabIndex: -1,\n onClick: handlerAll(props.onClick, onCreate),\n }\n },\n [isHit, onCreate],\n )\n\n return { getCreateProps }\n}\n\nexport type UseAutocompleteCreateReturn = ReturnType<\n typeof useAutocompleteCreate\n>\n\nexport const useAutocompleteEmpty = () => {\n const { isEmpty, isHit } = useAutocompleteContext()\n\n const getEmptyProps: PropGetter<\"li\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n ...props,\n style: isHit && !isEmpty ? style : undefined,\n tabIndex: -1,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n"],"mappings":";;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,OAAO,cAAc;AAM3C,IAAM,iBAAiB,CAAC,WAAqC;AAnB7D;AAoBE,uBAAc,MAAM,KAAK,CAAC,GAAC,YAAO,aAAa,MAAM,MAA1B,mBAA6B,WAAW;AAAA;AAgC9D,IAAM,wBAAwB,CAAC,UAAsC;AApD5E;AAqDE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,uBAAuB;AAC3B,QAAM,KAAK,MAAM;AAEjB,MAAI;AAAA,IACF;AAAA,IACA,eAAe;A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A,IACvC,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAS;AAC1B,YAAM,QAAuB;AAAA,QAC3B,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,QACH,OAAO,QAAQ,QAAQ;AAAA,QACvB,cAAc,SAAS,CAAC,KAAK;AAAA,QAC7B,UAAU;AAAA,QACV,SAAS,WAAW,MAAM,SAAS,QAAQ;AAAA,MAC7C;AAAA,IACF;AAAA,IACA,CAAC,OAAO,QAAQ;AAAA,EAClB;AAEA,SAAO,EAAE,eAAe;AAC1B;AAMO,IAAM,uBAAuB,MAAM;AACxC,QAAM,EAAE,SAAS,MAAM,IAAI,uBAAuB;AAElD,QAAM,gBAAkC;AAAA,IACtC,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAS;AAC1B,YAAM,QAAuB;AAAA,QAC3B,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,QACH,OAAO,SAAS,CAAC,UAAU,QAAQ;AAAA,QACnC,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,CAAC,OAAO,OAAO;AAAA,EACjB;AAEA,SAAO,EAAE,cAAc;AACzB;","names":["props"]}
package/dist/index.d.mts CHANGED
@@ -14,7 +14,6 @@ import './autocomplete-list.mjs';
14
14
  import './use-autocomplete-option.mjs';
15
15
  import './use-autocomplete-option-group.mjs';
16
16
  import '@yamada-ui/use-descendant';
17
- import 'react/jsx-runtime';
18
17
  import '@yamada-ui/form-control';
19
18
  import '@yamada-ui/popover';
20
19
  import '@yamada-ui/utils';
package/dist/index.d.ts CHANGED
@@ -14,7 +14,6 @@ import './autocomplete-list.js';
14
14
  import './use-autocomplete-option.js';
15
15
  import './use-autocomplete-option-group.js';
16
16
  import '@yamada-ui/use-descendant';
17
- import 'react/jsx-runtime';
18
17
  import '@yamada-ui/form-control';
19
18
  import '@yamada-ui/popover';
20
19
  import '@yamada-ui/utils';
package/dist/index.js CHANGED
@@ -161,7 +161,7 @@ var isTargetOption = (target) => {
161
161
  var useAutocompleteOption = (props) => {
162
162
  var _a, _b;
163
163
  const {
164
- closeOnSelect: generalCloseOnSelect,
164
+ closeOnSelect,
165
165
  focusedIndex,
166
166
  inputRef,
167
167
  omitSelectedValues,
@@ -169,7 +169,6 @@ var useAutocompleteOption = (props) => {
169
169
  value,
170
170
  optionProps,
171
171
  onChange,
172
- onChangeLabel,
173
172
  onClose,
174
173
  onFocusNext
175
174
  } = useAutocompleteContext();
@@ -200,28 +199,27 @@ var useAutocompleteOption = (props) => {
200
199
  );
201
200
  }
202
201
  }
203
- const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
202
+ const isDuplicated = frontValues.some(
203
+ ({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")
204
+ );
204
205
  const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
205
206
  const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
206
207
  const isFocused = index === focusedIndex;
207
208
  const onClick = (0, import_react2.useCallback)(
208
209
  (ev) => {
209
210
  ev.stopPropagation();
210
- if (isDisabled) {
211
+ if (isDisabled || !isTargetOption(ev.currentTarget)) {
211
212
  if (inputRef.current) inputRef.current.focus();
212
213
  return;
213
214
  }
214
- if (!isTargetOption(ev.currentTarget)) {
215
- if (inputRef.current) inputRef.current.focus();
216
- return;
217
- }
218
- setFocusedIndex(index);
215
+ if (!isDuplicated) setFocusedIndex(index);
219
216
  onChange(optionValue != null ? optionValue : "");
220
217
  if (inputRef.current) inputRef.current.focus();
221
- if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
218
+ if (customCloseOnSelect != null ? customCloseOnSelect : closeOnSelect) onClose();
222
219
  if (omitSelectedValues) onFocusNext(index);
223
220
  },
224
221
  [
222
+ isDuplicated,
225
223
  onFocusNext,
226
224
  omitSelectedValues,
227
225
  isDisabled,
@@ -230,14 +228,11 @@ var useAutocompleteOption = (props) => {
230
228
  index,
231
229
  onChange,
232
230
  customCloseOnSelect,
233
- generalCloseOnSelect,
231
+ closeOnSelect,
234
232
  onClose,
235
233
  inputRef
236
234
  ]
237
235
  );
238
- (0, import_utils3.useUpdateEffect)(() => {
239
- if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
240
- }, [optionValue]);
241
236
  const getOptionProps = (0, import_react2.useCallback)(
242
237
  (props2 = {}, ref = null) => {
243
238
  const style = {
@@ -261,6 +256,7 @@ var useAutocompleteOption = (props) => {
261
256
  "aria-checked": isSelected,
262
257
  "aria-disabled": (0, import_utils3.ariaAttr)(isDisabled),
263
258
  "data-disabled": (0, import_utils3.dataAttr)(isDisabled),
259
+ "data-duplicated": (0, import_utils3.dataAttr)(isDuplicated),
264
260
  "data-focus": (0, import_utils3.dataAttr)(isFocused),
265
261
  "data-target": (0, import_utils3.dataAttr)(true),
266
262
  "data-value": optionValue != null ? optionValue : "",
@@ -270,6 +266,7 @@ var useAutocompleteOption = (props) => {
270
266
  },
271
267
  [
272
268
  id,
269
+ isDuplicated,
273
270
  optionValue,
274
271
  computedProps,
275
272
  isDisabled,
@@ -989,15 +986,23 @@ var useAutocomplete = (props) => {
989
986
  );
990
987
  const validChildren = (0, import_utils11.getValidChildren)(children);
991
988
  const computedChildren = (0, import_react5.useMemo)(
992
- () => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
989
+ () => resolvedItems == null ? void 0 : resolvedItems.map((item, index) => {
993
990
  if ("value" in item) {
994
991
  const { label: label2, value: value2, ...props2 } = item;
995
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
992
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, index);
996
993
  } else if ("items" in item) {
997
994
  const { items: items2 = [], label: label2, ...props2 } = item;
998
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOptionGroup, { label: label2, ...props2, children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2)) }, i);
995
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
996
+ AutocompleteOptionGroup,
997
+ {
998
+ label: label2,
999
+ ...props2,
1000
+ children: items2.map(({ label: label3, value: value2, ...props3 }, index2) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, index2))
1001
+ },
1002
+ index
1003
+ );
999
1004
  }
1000
- }),
1005
+ }).filter(Boolean),
1001
1006
  [resolvedItems]
1002
1007
  );
1003
1008
  const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
@@ -1176,50 +1181,29 @@ var useAutocomplete = (props) => {
1176
1181
  },
1177
1182
  [descendants, onFocusFirst]
1178
1183
  );
1179
- const getSelectedValues = (0, import_react5.useCallback)(
1180
- (newValues) => {
1181
- const enabledValues2 = descendants.enabledValues();
1182
- const resolvedValues = (0, import_utils11.isArray)(newValues) ? newValues : [newValues];
1183
- const selectedValues2 = resolvedValues.map((value2) => {
1184
+ const onChangeLabel = (0, import_react5.useCallback)(
1185
+ (newValue) => {
1186
+ const values = descendants.values();
1187
+ if (!values.length) return;
1188
+ const resolvedValues = (0, import_utils11.isArray)(newValue) ? newValue : [newValue];
1189
+ const selectedLabel = resolvedValues.map((value2) => {
1184
1190
  var _a, _b;
1185
- const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
1191
+ const { node } = (_a = values.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
1186
1192
  if (node) {
1187
- const el = Array.from(node.children).find(
1193
+ const { textContent } = (_b = Array.from(node.children).find(
1188
1194
  (child) => child.getAttribute("data-label") !== null
1189
- );
1190
- return (_b = el == null ? void 0 : el.textContent) != null ? _b : void 0;
1195
+ )) != null ? _b : {};
1196
+ return textContent;
1191
1197
  } else {
1192
1198
  return allowFree ? value2 : void 0;
1193
1199
  }
1194
- }).filter(Boolean);
1195
- return selectedValues2;
1200
+ }).filter((label2) => !(0, import_utils11.isUndefined)(label2));
1201
+ setLabel(!isMulti ? selectedLabel[0] : selectedLabel);
1196
1202
  },
1197
- [allowFree, descendants]
1198
- );
1199
- const onChangeLabel = (0, import_react5.useCallback)(
1200
- (newValue, { forceUpdate, runOmit = true } = {}) => {
1201
- const selectedValues2 = getSelectedValues(newValue);
1202
- if (!forceUpdate && !selectedValues2.length) return;
1203
- setLabel((prev) => {
1204
- if (!isMulti) {
1205
- return selectedValues2[0];
1206
- } else {
1207
- selectedValues2.forEach((selectedValue) => {
1208
- const isSelected = (0, import_utils11.isArray)(prev) && prev.includes(selectedValue);
1209
- if (!isSelected) {
1210
- prev = [...(0, import_utils11.isArray)(prev) ? prev : [], selectedValue];
1211
- } else if (runOmit) {
1212
- prev = (0, import_utils11.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
1213
- }
1214
- });
1215
- return prev;
1216
- }
1217
- });
1218
- },
1219
- [getSelectedValues, isMulti]
1203
+ [allowFree, descendants, isMulti]
1220
1204
  );
1221
1205
  const onChange = (0, import_react5.useCallback)(
1222
- (newValue, { forceUpdate, runRebirth = true } = {}) => {
1206
+ (newValue, runRebirth = true) => {
1223
1207
  setValue((prev) => {
1224
1208
  let next;
1225
1209
  if (!(0, import_utils11.isArray)(prev)) {
@@ -1241,14 +1225,13 @@ var useAutocomplete = (props) => {
1241
1225
  return format((_a = node.textContent) != null ? _a : "").includes(newValue);
1242
1226
  }
1243
1227
  ).length > 0;
1244
- onChangeLabel(newValue, { forceUpdate });
1245
- if (allowFree || isHit2) setInputValue("");
1228
+ if (allowCreate || allowFree || isHit2) setInputValue("");
1246
1229
  if (isMulti && runRebirth) rebirthOptions(false);
1247
1230
  },
1248
1231
  [
1249
1232
  allowFree,
1233
+ allowCreate,
1250
1234
  isMulti,
1251
- onChangeLabel,
1252
1235
  rebirthOptions,
1253
1236
  setValue,
1254
1237
  descendants,
@@ -1359,7 +1342,7 @@ var useAutocomplete = (props) => {
1359
1342
  const relatedTarget = (0, import_utils11.getEventRelatedTarget)(ev);
1360
1343
  if ((0, import_utils11.isContains)(containerRef.current, relatedTarget)) return;
1361
1344
  if (!closeOnBlur && isHit) return;
1362
- if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
1345
+ if (allowFree && !!inputValue) onChange(inputValue, false);
1363
1346
  setInputValue("");
1364
1347
  if (isOpen) onClose();
1365
1348
  },
@@ -1367,7 +1350,7 @@ var useAutocomplete = (props) => {
1367
1350
  );
1368
1351
  const onDelete = (0, import_react5.useCallback)(() => {
1369
1352
  if (!isMulti) {
1370
- onChange("", { forceUpdate: true });
1353
+ onChange("");
1371
1354
  } else {
1372
1355
  onChange(value[value.length - 1]);
1373
1356
  }
@@ -1454,18 +1437,9 @@ var useAutocomplete = (props) => {
1454
1437
  onClose,
1455
1438
  maxSelectValues
1456
1439
  ]);
1457
- (0, import_react5.useEffect)(() => {
1458
- var _a;
1459
- if (isMulti) {
1460
- if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value))
1461
- return;
1462
- const label2 = getSelectedValues(value);
1463
- setLabel(label2);
1464
- } else {
1465
- if (prevValue.current === value) return;
1466
- onChangeLabel(value, { runOmit: false });
1467
- }
1468
- }, [isMulti, value, onChangeLabel, getSelectedValues]);
1440
+ (0, import_utils11.useSafeLayoutEffect)(() => {
1441
+ onChangeLabel(value);
1442
+ }, [value]);
1469
1443
  (0, import_utils11.useUpdateEffect)(() => {
1470
1444
  if (isOpen || allowFree) return;
1471
1445
  setFocusedIndex(-1);
@@ -1572,8 +1546,8 @@ var useAutocomplete = (props) => {
1572
1546
  id,
1573
1547
  allowCreate,
1574
1548
  allowFree,
1549
+ children: children != null ? children : computedChildren,
1575
1550
  closeOnSelect,
1576
- computedChildren,
1577
1551
  descendants,
1578
1552
  emptyMessage,
1579
1553
  focusedIndex,
@@ -1597,7 +1571,6 @@ var useAutocomplete = (props) => {
1597
1571
  inputProps,
1598
1572
  optionProps,
1599
1573
  onChange,
1600
- onChangeLabel,
1601
1574
  onClear,
1602
1575
  onClose,
1603
1576
  onCompositionEnd,
@@ -1691,7 +1664,6 @@ var Autocomplete = (0, import_core9.forwardRef)(
1691
1664
  const [styles, mergedProps] = (0, import_core9.useComponentMultiStyle)("Autocomplete", props);
1692
1665
  let {
1693
1666
  className,
1694
- children,
1695
1667
  color,
1696
1668
  defaultValue = "",
1697
1669
  footer,
@@ -1713,7 +1685,7 @@ var Autocomplete = (0, import_core9.forwardRef)(
1713
1685
  } = (0, import_core9.omitThemeProps)(mergedProps);
1714
1686
  const {
1715
1687
  allowCreate,
1716
- computedChildren,
1688
+ children,
1717
1689
  descendants,
1718
1690
  inputValue,
1719
1691
  isEmpty,
@@ -1724,7 +1696,7 @@ var Autocomplete = (0, import_core9.forwardRef)(
1724
1696
  getPopoverProps,
1725
1697
  onClose,
1726
1698
  ...rest
1727
- } = useAutocomplete({ ...computedProps, children, defaultValue });
1699
+ } = useAutocomplete({ ...computedProps, defaultValue });
1728
1700
  h != null ? h : h = height;
1729
1701
  minH != null ? minH : minH = minHeight;
1730
1702
  const css = {
@@ -1772,26 +1744,17 @@ var Autocomplete = (0, import_core9.forwardRef)(
1772
1744
  ]
1773
1745
  }
1774
1746
  ),
1775
- !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1747
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1776
1748
  AutocompleteList,
1777
1749
  {
1778
1750
  footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1779
1751
  header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1780
1752
  contentProps,
1781
1753
  ...listProps,
1782
- children: [
1754
+ children: !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1783
1755
  allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps }),
1784
- children != null ? children : computedChildren
1785
- ]
1786
- }
1787
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1788
- AutocompleteList,
1789
- {
1790
- footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1791
- header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1792
- contentProps,
1793
- ...listProps,
1794
- children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps })
1756
+ children
1757
+ ] }) : allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps })
1795
1758
  }
1796
1759
  ) })
1797
1760
  ]
@@ -1857,7 +1820,6 @@ var MultiAutocomplete = (0, import_core10.forwardRef)(
1857
1820
  );
1858
1821
  let {
1859
1822
  className,
1860
- children,
1861
1823
  closeOnSelect = false,
1862
1824
  color,
1863
1825
  component,
@@ -1885,7 +1847,7 @@ var MultiAutocomplete = (0, import_core10.forwardRef)(
1885
1847
  } = (0, import_core10.omitThemeProps)(mergedProps);
1886
1848
  const {
1887
1849
  allowCreate,
1888
- computedChildren,
1850
+ children,
1889
1851
  descendants,
1890
1852
  inputValue,
1891
1853
  isEmpty,
@@ -1899,7 +1861,6 @@ var MultiAutocomplete = (0, import_core10.forwardRef)(
1899
1861
  ...rest
1900
1862
  } = useAutocomplete({
1901
1863
  ...computedProps,
1902
- children,
1903
1864
  closeOnSelect,
1904
1865
  defaultValue
1905
1866
  });
@@ -1960,26 +1921,17 @@ var MultiAutocomplete = (0, import_core10.forwardRef)(
1960
1921
  ]
1961
1922
  }
1962
1923
  ),
1963
- !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_portal2.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1924
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_portal2.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1964
1925
  AutocompleteList,
1965
1926
  {
1966
1927
  footer: (0, import_utils13.runIfFunc)(footer, { value, onClose }),
1967
1928
  header: (0, import_utils13.runIfFunc)(header, { value, onClose }),
1968
1929
  contentProps,
1969
1930
  ...listProps,
1970
- children: [
1931
+ children: !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1971
1932
  allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, { ...emptyProps }),
1972
- children != null ? children : computedChildren
1973
- ]
1974
- }
1975
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_portal2.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1976
- AutocompleteList,
1977
- {
1978
- footer: (0, import_utils13.runIfFunc)(footer, { value, onClose }),
1979
- header: (0, import_utils13.runIfFunc)(header, { value, onClose }),
1980
- contentProps,
1981
- ...listProps,
1982
- children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, { ...emptyProps })
1933
+ children
1934
+ ] }) : allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, { ...emptyProps })
1983
1935
  }
1984
1936
  ) })
1985
1937
  ]
@@ -2049,11 +2001,11 @@ var MultiAutocompleteField = (0, import_core10.forwardRef)(
2049
2001
  ...styles.field,
2050
2002
  cursor: "text"
2051
2003
  };
2004
+ if ((label == null ? void 0 : label.length) && component) css.py = "0.125rem";
2052
2005
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_popover3.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2053
2006
  import_core10.ui.div,
2054
2007
  {
2055
2008
  className: (0, import_utils13.cx)("ui-multi-autocomplete__field", className),
2056
- py: (label == null ? void 0 : label.length) && component ? "0.125rem" : void 0,
2057
2009
  __css: css,
2058
2010
  ...rest,
2059
2011
  children: [