@yamada-ui/autocomplete 1.6.2-dev-20241026110242 → 1.6.2-dev-20241026234458

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/dist/autocomplete-create.d.mts +2 -2
  2. package/dist/autocomplete-create.d.ts +2 -2
  3. package/dist/autocomplete-create.js +3 -1
  4. package/dist/autocomplete-create.js.map +1 -1
  5. package/dist/autocomplete-create.mjs +2 -2
  6. package/dist/autocomplete-empty.d.mts +2 -2
  7. package/dist/autocomplete-empty.d.ts +2 -2
  8. package/dist/autocomplete-empty.js +5 -2
  9. package/dist/autocomplete-empty.js.map +1 -1
  10. package/dist/autocomplete-empty.mjs +2 -2
  11. package/dist/autocomplete-list.d.mts +2 -2
  12. package/dist/autocomplete-list.d.ts +2 -2
  13. package/dist/autocomplete-list.js +16 -19
  14. package/dist/autocomplete-list.js.map +1 -1
  15. package/dist/autocomplete-list.mjs +2 -2
  16. package/dist/autocomplete-option-group.d.mts +3 -3
  17. package/dist/autocomplete-option-group.d.ts +3 -3
  18. package/dist/autocomplete-option-group.js +27 -13
  19. package/dist/autocomplete-option-group.js.map +1 -1
  20. package/dist/autocomplete-option-group.mjs +2 -2
  21. package/dist/autocomplete-option.d.mts +1 -1
  22. package/dist/autocomplete-option.d.ts +1 -1
  23. package/dist/autocomplete-option.js +18 -12
  24. package/dist/autocomplete-option.js.map +1 -1
  25. package/dist/autocomplete-option.mjs +2 -2
  26. package/dist/autocomplete.js +78 -56
  27. package/dist/autocomplete.js.map +1 -1
  28. package/dist/autocomplete.mjs +10 -10
  29. package/dist/{chunk-KWIJUSLC.mjs → chunk-2UKLSSUA.mjs} +3 -3
  30. package/dist/chunk-2UKLSSUA.mjs.map +1 -0
  31. package/dist/{chunk-ZXALWDKQ.mjs → chunk-3A2HEULI.mjs} +24 -13
  32. package/dist/chunk-3A2HEULI.mjs.map +1 -0
  33. package/dist/{chunk-PKRO525W.mjs → chunk-6II6KCIJ.mjs} +3 -3
  34. package/dist/chunk-6II6KCIJ.mjs.map +1 -0
  35. package/dist/{chunk-OY5JVCQQ.mjs → chunk-6WQMVK6S.mjs} +5 -5
  36. package/dist/{chunk-HUY7Q3WA.mjs → chunk-6ZFQNL3O.mjs} +5 -7
  37. package/dist/{chunk-HUY7Q3WA.mjs.map → chunk-6ZFQNL3O.mjs.map} +1 -1
  38. package/dist/{chunk-7QON6ZHO.mjs → chunk-CMFJUJJW.mjs} +25 -11
  39. package/dist/chunk-CMFJUJJW.mjs.map +1 -0
  40. package/dist/{chunk-352YZTOO.mjs → chunk-EVGBK5C5.mjs} +12 -12
  41. package/dist/{chunk-352YZTOO.mjs.map → chunk-EVGBK5C5.mjs.map} +1 -1
  42. package/dist/{chunk-J6UKIKNL.mjs → chunk-G6SC44LI.mjs} +3 -3
  43. package/dist/chunk-G6SC44LI.mjs.map +1 -0
  44. package/dist/{chunk-X2PFHBZY.mjs → chunk-PTPJFYGI.mjs} +15 -17
  45. package/dist/chunk-PTPJFYGI.mjs.map +1 -0
  46. package/dist/{chunk-WNN655FX.mjs → chunk-PU6HFINM.mjs} +7 -7
  47. package/dist/chunk-PU6HFINM.mjs.map +1 -0
  48. package/dist/{chunk-WJ4P4B2E.mjs → chunk-REPBXBG3.mjs} +5 -6
  49. package/dist/chunk-REPBXBG3.mjs.map +1 -0
  50. package/dist/index.js +78 -58
  51. package/dist/index.js.map +1 -1
  52. package/dist/index.mjs +11 -11
  53. package/dist/multi-autocomplete.js +78 -58
  54. package/dist/multi-autocomplete.js.map +1 -1
  55. package/dist/multi-autocomplete.mjs +10 -10
  56. package/dist/use-autocomplete-list.d.mts +1 -1
  57. package/dist/use-autocomplete-list.d.ts +1 -1
  58. package/dist/use-autocomplete-list.js +13 -15
  59. package/dist/use-autocomplete-list.js.map +1 -1
  60. package/dist/use-autocomplete-list.mjs +1 -1
  61. package/dist/use-autocomplete-option-group.d.mts +3 -2
  62. package/dist/use-autocomplete-option-group.d.ts +3 -2
  63. package/dist/use-autocomplete-option-group.js +22 -8
  64. package/dist/use-autocomplete-option-group.js.map +1 -1
  65. package/dist/use-autocomplete-option-group.mjs +1 -1
  66. package/dist/use-autocomplete-option.d.mts +6 -4
  67. package/dist/use-autocomplete-option.d.ts +6 -4
  68. package/dist/use-autocomplete-option.js +23 -12
  69. package/dist/use-autocomplete-option.js.map +1 -1
  70. package/dist/use-autocomplete-option.mjs +1 -1
  71. package/dist/use-autocomplete.js +54 -34
  72. package/dist/use-autocomplete.js.map +1 -1
  73. package/dist/use-autocomplete.mjs +5 -5
  74. package/package.json +2 -2
  75. package/dist/chunk-7QON6ZHO.mjs.map +0 -1
  76. package/dist/chunk-J6UKIKNL.mjs.map +0 -1
  77. package/dist/chunk-KWIJUSLC.mjs.map +0 -1
  78. package/dist/chunk-PKRO525W.mjs.map +0 -1
  79. package/dist/chunk-WJ4P4B2E.mjs.map +0 -1
  80. package/dist/chunk-WNN655FX.mjs.map +0 -1
  81. package/dist/chunk-X2PFHBZY.mjs.map +0 -1
  82. package/dist/chunk-ZXALWDKQ.mjs.map +0 -1
  83. /package/dist/{chunk-OY5JVCQQ.mjs.map → chunk-6WQMVK6S.mjs.map} +0 -0
@@ -43,11 +43,12 @@ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createCont
43
43
 
44
44
  // src/use-autocomplete-list.ts
45
45
  var useAutocompleteList = () => {
46
- const uuid = (0, import_react.useId)();
47
- const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
46
+ const { focusedIndex, isOpen, listRef, rebirthOptions, value } = useAutocompleteContext();
48
47
  const descendants = useAutocompleteDescendantsContext();
48
+ const uuid = (0, import_react.useId)();
49
49
  const beforeFocusedIndex = (0, import_react.useRef)(-1);
50
50
  const selectedValue = descendants.value(focusedIndex);
51
+ const isMulti = (0, import_utils2.isArray)(value);
51
52
  const onAnimationComplete = (0, import_react.useCallback)(() => {
52
53
  if (!isOpen) rebirthOptions(false);
53
54
  }, [isOpen, rebirthOptions]);
@@ -81,19 +82,16 @@ var useAutocompleteList = () => {
81
82
  if (!isOpen) beforeFocusedIndex.current = -1;
82
83
  }, [isOpen]);
83
84
  const getListProps = (0, import_react.useCallback)(
84
- (props = {}, ref = null) => {
85
- var _a;
86
- return {
87
- id: (_a = props.id) != null ? _a : uuid,
88
- ref: (0, import_utils2.mergeRefs)(listRef, ref),
89
- as: "ul",
90
- position: "relative",
91
- role: "listbox",
92
- tabIndex: -1,
93
- ...props
94
- };
95
- },
96
- [listRef, uuid]
85
+ ({ id, ...props } = {}, ref = null) => ({
86
+ id: id != null ? id : uuid,
87
+ ref: (0, import_utils2.mergeRefs)(listRef, ref),
88
+ "aria-multiselectable": (0, import_utils2.ariaAttr)(isMulti),
89
+ position: "relative",
90
+ role: "listbox",
91
+ tabIndex: -1,
92
+ ...props
93
+ }),
94
+ [listRef, uuid, isMulti]
97
95
  );
98
96
  return {
99
97
  getListProps,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-autocomplete-list.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { PropGetter } from \"@yamada-ui/core\"\nimport { mergeRefs, useUpdateEffect } from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport const useAutocompleteList = () => {\n const uuid = useId()\n const { focusedIndex, isOpen, listRef, rebirthOptions } =\n useAutocompleteContext()\n\n const descendants = useAutocompleteDescendantsContext()\n\n const beforeFocusedIndex = useRef<number>(-1)\n const selectedValue = descendants.value(focusedIndex)\n\n const onAnimationComplete = useCallback(() => {\n if (!isOpen) rebirthOptions(false)\n }, [isOpen, rebirthOptions])\n\n useEffect(() => {\n if (!listRef.current || !selectedValue) return\n\n if (beforeFocusedIndex.current === selectedValue.index) return\n\n const parent = listRef.current\n const child = selectedValue.node\n\n const parentHeight = parent.clientHeight\n const viewTop = parent.scrollTop\n const viewBottom = viewTop + parentHeight\n\n const childHeight = child.clientHeight\n const childTop = child.offsetTop\n const childBottom = childTop + childHeight\n\n const isInView = viewTop <= childTop && childBottom <= viewBottom\n\n const isScrollBottom = beforeFocusedIndex.current < selectedValue.index\n\n if (!isInView) {\n if (childBottom <= parentHeight) {\n listRef.current.scrollTo({ top: 0 })\n } else {\n if (!isScrollBottom) {\n listRef.current.scrollTo({ top: childTop + 1 })\n } else {\n listRef.current.scrollTo({ top: childBottom - parentHeight })\n }\n }\n }\n\n beforeFocusedIndex.current = selectedValue.index\n }, [listRef, selectedValue])\n\n useUpdateEffect(() => {\n if (!isOpen) beforeFocusedIndex.current = -1\n }, [isOpen])\n\n const getListProps: PropGetter<\"ul\"> = useCallback(\n (props = {}, ref = null) => ({\n id: props.id ?? uuid,\n ref: mergeRefs(listRef, ref),\n as: \"ul\",\n position: \"relative\",\n role: \"listbox\",\n tabIndex: -1,\n ...props,\n }),\n [listRef, uuid],\n )\n\n return {\n getListProps,\n onAnimationComplete,\n }\n}\n","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAA2C;AAC3C,mBAAsD;;;ACCtD,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,QAAI,wCAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;ADxCI,IAAM,sBAAsB,MAAM;AACvC,QAAM,WAAO,oBAAM;AACnB,QAAM,EAAE,cAAc,QAAQ,SAAS,eAAe,IACpD,uBAAuB;AAEzB,QAAM,cAAc,kCAAkC;AAEtD,QAAM,yBAAqB,qBAAe,EAAE;AAC5C,QAAM,gBAAgB,YAAY,MAAM,YAAY;AAEpD,QAAM,0BAAsB,0BAAY,MAAM;AAC5C,QAAI,CAAC,OAAQ,gBAAe,KAAK;AAAA,EACnC,GAAG,CAAC,QAAQ,cAAc,CAAC;AAE3B,8BAAU,MAAM;AACd,QAAI,CAAC,QAAQ,WAAW,CAAC,cAAe;AAExC,QAAI,mBAAmB,YAAY,cAAc,MAAO;AAExD,UAAM,SAAS,QAAQ;AACvB,UAAM,QAAQ,cAAc;AAE5B,UAAM,eAAe,OAAO;AAC5B,UAAM,UAAU,OAAO;AACvB,UAAM,aAAa,UAAU;AAE7B,UAAM,cAAc,MAAM;AAC1B,UAAM,WAAW,MAAM;AACvB,UAAM,cAAc,WAAW;AAE/B,UAAM,WAAW,WAAW,YAAY,eAAe;AAEvD,UAAM,iBAAiB,mBAAmB,UAAU,cAAc;AAElE,QAAI,CAAC,UAAU;AACb,UAAI,eAAe,cAAc;AAC/B,gBAAQ,QAAQ,SAAS,EAAE,KAAK,EAAE,CAAC;AAAA,MACrC,OAAO;AACL,YAAI,CAAC,gBAAgB;AACnB,kBAAQ,QAAQ,SAAS,EAAE,KAAK,WAAW,EAAE,CAAC;AAAA,QAChD,OAAO;AACL,kBAAQ,QAAQ,SAAS,EAAE,KAAK,cAAc,aAAa,CAAC;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAEA,uBAAmB,UAAU,cAAc;AAAA,EAC7C,GAAG,CAAC,SAAS,aAAa,CAAC;AAE3B,qCAAgB,MAAM;AACpB,QAAI,CAAC,OAAQ,oBAAmB,UAAU;AAAA,EAC5C,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,mBAAiC;AAAA,IACrC,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAM;AA9D7B;AA8DiC;AAAA,QAC3B,KAAI,WAAM,OAAN,YAAY;AAAA,QAChB,SAAK,yBAAU,SAAS,GAAG;AAAA,QAC3B,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,MAAM;AAAA,QACN,UAAU;AAAA,QACV,GAAG;AAAA,MACL;AAAA;AAAA,IACA,CAAC,SAAS,IAAI;AAAA,EAChB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
1
+ {"version":3,"sources":["../src/use-autocomplete-list.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { PropGetter } from \"@yamada-ui/core\"\nimport { ariaAttr, isArray, mergeRefs, useUpdateEffect } from \"@yamada-ui/utils\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport const useAutocompleteList = () => {\n const { focusedIndex, isOpen, listRef, rebirthOptions, value } =\n useAutocompleteContext()\n const descendants = useAutocompleteDescendantsContext()\n const uuid = useId()\n const beforeFocusedIndex = useRef<number>(-1)\n const selectedValue = descendants.value(focusedIndex)\n const isMulti = isArray(value)\n\n const onAnimationComplete = useCallback(() => {\n if (!isOpen) rebirthOptions(false)\n }, [isOpen, rebirthOptions])\n\n useEffect(() => {\n if (!listRef.current || !selectedValue) return\n\n if (beforeFocusedIndex.current === selectedValue.index) return\n\n const parent = listRef.current\n const child = selectedValue.node\n\n const parentHeight = parent.clientHeight\n const viewTop = parent.scrollTop\n const viewBottom = viewTop + parentHeight\n\n const childHeight = child.clientHeight\n const childTop = child.offsetTop\n const childBottom = childTop + childHeight\n\n const isInView = viewTop <= childTop && childBottom <= viewBottom\n\n const isScrollBottom = beforeFocusedIndex.current < selectedValue.index\n\n if (!isInView) {\n if (childBottom <= parentHeight) {\n listRef.current.scrollTo({ top: 0 })\n } else {\n if (!isScrollBottom) {\n listRef.current.scrollTo({ top: childTop + 1 })\n } else {\n listRef.current.scrollTo({ top: childBottom - parentHeight })\n }\n }\n }\n\n beforeFocusedIndex.current = selectedValue.index\n }, [listRef, selectedValue])\n\n useUpdateEffect(() => {\n if (!isOpen) beforeFocusedIndex.current = -1\n }, [isOpen])\n\n const getListProps: PropGetter = useCallback(\n ({ id, ...props } = {}, ref = null) => ({\n id: id ?? uuid,\n ref: mergeRefs(listRef, ref),\n \"aria-multiselectable\": ariaAttr(isMulti),\n position: \"relative\",\n role: \"listbox\",\n tabIndex: -1,\n ...props,\n }),\n [listRef, uuid, isMulti],\n )\n\n return {\n getListProps,\n onAnimationComplete,\n }\n}\n","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAA8D;AAC9D,mBAAsD;;;ACCtD,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,QAAI,wCAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;ADxCI,IAAM,sB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B;AAAA,IAC/B,CAAC,EAAE,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,MAAM,UAAU;AAAA,MACtC,IAAI,kBAAM;AAAA,MACV,SAAK,yBAAU,SAAS,GAAG;AAAA,MAC3B,4BAAwB,wBAAS,OAAO;AAAA,MACxC,UAAU;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,GAAG;AAAA,IACL;AAAA,IACA,CAAC,SAAS,MAAM,OAAO;AAAA,EACzB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteList
4
- } from "./chunk-X2PFHBZY.mjs";
4
+ } from "./chunk-PTPJFYGI.mjs";
5
5
  import "./chunk-ZNO5RUVT.mjs";
6
6
  export {
7
7
  useAutocompleteList
@@ -1,6 +1,6 @@
1
1
  import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
2
2
 
3
- interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
3
+ interface UseAutocompleteOptionGroupProps extends HTMLUIProps {
4
4
  /**
5
5
  * The label of the autocomplete option group.
6
6
  */
@@ -9,7 +9,8 @@ interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
9
9
  declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOptionGroupProps) => {
10
10
  label: string;
11
11
  getContainerProps: PropGetter<"li", undefined>;
12
- getGroupProps: PropGetter<"ul", undefined>;
12
+ getGroupProps: PropGetter<"div", undefined>;
13
+ getLabelProps: PropGetter<"div", undefined>;
13
14
  };
14
15
  type UseAutocompleteOptionGroupReturn = ReturnType<typeof useAutocompleteOptionGroup>;
15
16
 
@@ -1,6 +1,6 @@
1
1
  import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
2
2
 
3
- interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
3
+ interface UseAutocompleteOptionGroupProps extends HTMLUIProps {
4
4
  /**
5
5
  * The label of the autocomplete option group.
6
6
  */
@@ -9,7 +9,8 @@ interface UseAutocompleteOptionGroupProps extends HTMLUIProps<"ul"> {
9
9
  declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOptionGroupProps) => {
10
10
  label: string;
11
11
  getContainerProps: PropGetter<"li", undefined>;
12
- getGroupProps: PropGetter<"ul", undefined>;
12
+ getGroupProps: PropGetter<"div", undefined>;
13
+ getLabelProps: PropGetter<"div", undefined>;
13
14
  };
14
15
  type UseAutocompleteOptionGroupReturn = ReturnType<typeof useAutocompleteOptionGroup>;
15
16
 
@@ -48,9 +48,11 @@ var useAutocompleteOptionGroup = ({
48
48
  ...rest
49
49
  }) => {
50
50
  const { omitSelectedValues, value } = useAutocompleteContext();
51
- const isMulti = (0, import_utils2.isArray)(value);
52
51
  const descendants = useAutocompleteDescendantsContext();
52
+ const labelRef = (0, import_react.useRef)(null);
53
+ const labelId = (0, import_react.useId)();
53
54
  const values = descendants.values();
55
+ const isMulti = (0, import_utils2.isArray)(value);
54
56
  const selectedValues = isMulti && omitSelectedValues ? descendants.values(
55
57
  ({ node }) => {
56
58
  var _a;
@@ -68,6 +70,7 @@ var useAutocompleteOptionGroup = ({
68
70
  const [containerProps, groupProps] = (0, import_utils2.splitObject)(rest, import_core.layoutStyleProperties);
69
71
  const getContainerProps = (0, import_react.useCallback)(
70
72
  (props = {}, ref = null) => {
73
+ var _a;
71
74
  const style = {
72
75
  border: "0px",
73
76
  clip: "rect(0px, 0px, 0px, 0px)",
@@ -81,29 +84,40 @@ var useAutocompleteOptionGroup = ({
81
84
  };
82
85
  return {
83
86
  ref,
87
+ "aria-labelledby": (_a = labelRef.current) == null ? void 0 : _a.id,
88
+ role: "group",
84
89
  ...props,
85
90
  ...containerProps,
86
- style: isEmpty ? style : void 0,
87
- "data-label": label,
88
- role: "autocomplete-group-container"
91
+ style: isEmpty ? style : void 0
92
+ };
93
+ },
94
+ [containerProps, isEmpty]
95
+ );
96
+ const getLabelProps = (0, import_react.useCallback)(
97
+ ({ id, ...props } = {}, ref = null) => {
98
+ return {
99
+ id: id != null ? id : labelId,
100
+ ref: (0, import_utils2.mergeRefs)(ref, labelRef),
101
+ role: "presentation",
102
+ ...props
89
103
  };
90
104
  },
91
- [containerProps, isEmpty, label]
105
+ [labelId]
92
106
  );
93
107
  const getGroupProps = (0, import_react.useCallback)(
94
108
  (props = {}, ref = null) => ({
95
109
  ref,
96
110
  ...props,
97
111
  ...groupProps,
98
- "data-label": label,
99
- role: "autocomplete-group"
112
+ "data-label": label
100
113
  }),
101
114
  [groupProps, label]
102
115
  );
103
116
  return {
104
117
  label,
105
118
  getContainerProps,
106
- getGroupProps
119
+ getGroupProps,
120
+ getLabelProps
107
121
  };
108
122
  };
109
123
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-autocomplete-option-group.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties } from \"react\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { isArray, splitObject } from \"@yamada-ui/utils\"\nimport { useCallback } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport interface UseAutocompleteOptionGroupProps extends HTMLUIProps<\"ul\"> {\n /**\n * The label of the autocomplete option group.\n */\n label: string\n}\n\nexport const useAutocompleteOptionGroup = ({\n label,\n ...rest\n}: UseAutocompleteOptionGroupProps) => {\n const { omitSelectedValues, value } = useAutocompleteContext()\n\n const isMulti = isArray(value)\n\n const descendants = useAutocompleteDescendantsContext()\n\n const values = descendants.values()\n const selectedValues =\n isMulti && omitSelectedValues\n ? descendants.values(({ node }) =>\n value.includes(node.dataset.value ?? \"\"),\n )\n : []\n const selectedIndexes = selectedValues.map(({ index }) => index)\n const childValues = values.filter(\n ({ index, node }) =>\n node.parentElement?.dataset.label === label &&\n !selectedIndexes.includes(index) &&\n \"target\" in node.dataset,\n )\n\n const isEmpty = !childValues.length\n\n const [containerProps, groupProps] = splitObject(rest, layoutStyleProperties)\n\n const getContainerProps: 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 ...containerProps,\n style: isEmpty ? style : undefined,\n \"data-label\": label,\n role: \"autocomplete-group-container\",\n }\n },\n [containerProps, isEmpty, label],\n )\n\n const getGroupProps: PropGetter<\"ul\"> = useCallback(\n (props = {}, ref = null) => ({\n ref,\n ...props,\n ...groupProps,\n \"data-label\": label,\n role: \"autocomplete-group\",\n }),\n [groupProps, label],\n )\n\n return {\n label,\n getContainerProps,\n getGroupProps,\n }\n}\n\nexport type UseAutocompleteOptionGroupReturn = ReturnType<\n typeof useAutocompleteOptionGroup\n>\n","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAsC;AACtC,IAAAA,gBAAqC;AACrC,mBAA4B;;;ACD5B,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,QAAI,wCAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;AD/BI,IAAM,6BAA6B,CAAC;AAAA,EACzC;AAAA,EACA,GAAG;AACL,MAAuC;AACrC,QAAM,EAAE,oBAAoB,MAAM,IAAI,uBAAuB;AAE7D,QAAM,cAAU,uBAAQ,KAAK;AAE7B,QAAM,cAAc,kCAAkC;AAEtD,QAAM,SAAS,YAAY,OAAO;AAClC,QAAM,iBACJ,WAAW,qBACP,YAAY;AAAA,IAAO,CAAC,EAAE,KAAK,MAAG;AA9BtC;AA+BU,mBAAM,UAAS,UAAK,QAAQ,UAAb,YAAsB,EAAE;AAAA;AAAA,EACzC,IACA,CAAC;AACP,QAAM,kBAAkB,eAAe,IAAI,CAAC,EAAE,MAAM,MAAM,KAAK;AAC/D,QAAM,cAAc,OAAO;AAAA,IACzB,CAAC,EAAE,OAAO,KAAK,MAAG;AApCtB;AAqCM,yBAAK,kBAAL,mBAAoB,QAAQ,WAAU,SACtC,CAAC,gBAAgB,SAAS,KAAK,KAC/B,YAAY,KAAK;AAAA;AAAA,EACrB;AAEA,QAAM,UAAU,CAAC,YAAY;AAE7B,QAAM,CAAC,gBAAgB,UAAU,QAAI,2BAAY,MAAM,iCAAqB;AAE5E,QAAM,wBAAsC;AAAA,IAC1C,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,GAAG;AAAA,QACH,OAAO,UAAU,QAAQ;AAAA,QACzB,cAAc;AAAA,QACd,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,SAAS,KAAK;AAAA,EACjC;AAEA,QAAM,oBAAkC;AAAA,IACtC,CAAC,QAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B;AAAA,MACA,GAAG;AAAA,MACH,GAAG;AAAA,MACH,cAAc;AAAA,MACd,MAAM;AAAA,IACR;AAAA,IACA,CAAC,YAAY,KAAK;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
1
+ {"version":3,"sources":["../src/use-autocomplete-option-group.ts","../src/autocomplete-context.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties } from \"react\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { isArray, mergeRefs, splitObject } from \"@yamada-ui/utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendantsContext,\n} from \"./autocomplete-context\"\n\nexport interface UseAutocompleteOptionGroupProps extends HTMLUIProps {\n /**\n * The label of the autocomplete option group.\n */\n label: string\n}\n\nexport const useAutocompleteOptionGroup = ({\n label,\n ...rest\n}: UseAutocompleteOptionGroupProps) => {\n const { omitSelectedValues, value } = useAutocompleteContext()\n const descendants = useAutocompleteDescendantsContext()\n const labelRef = useRef<HTMLDivElement>(null)\n const labelId = useId()\n const values = descendants.values()\n const isMulti = isArray(value)\n const selectedValues =\n isMulti && omitSelectedValues\n ? descendants.values(({ node }) =>\n value.includes(node.dataset.value ?? \"\"),\n )\n : []\n const selectedIndexes = selectedValues.map(({ index }) => index)\n const childValues = values.filter(\n ({ index, node }) =>\n node.parentElement?.dataset.label === label &&\n !selectedIndexes.includes(index) &&\n \"target\" in node.dataset,\n )\n const isEmpty = !childValues.length\n\n const [containerProps, groupProps] = splitObject(rest, layoutStyleProperties)\n\n const getContainerProps: 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 \"aria-labelledby\": labelRef.current?.id,\n role: \"group\",\n ...props,\n ...containerProps,\n style: isEmpty ? style : undefined,\n }\n },\n [containerProps, isEmpty],\n )\n\n const getLabelProps: PropGetter = useCallback(\n ({ id, ...props } = {}, ref = null) => {\n return {\n id: id ?? labelId,\n ref: mergeRefs(ref, labelRef),\n role: \"presentation\",\n ...props,\n }\n },\n [labelId],\n )\n\n const getGroupProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref,\n ...props,\n ...groupProps,\n \"data-label\": label,\n }),\n [groupProps, label],\n )\n\n return {\n label,\n getContainerProps,\n getGroupProps,\n getLabelProps,\n }\n}\n\nexport type UseAutocompleteOptionGroupReturn = ReturnType<\n typeof useAutocompleteOptionGroup\n>\n","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAsC;AACtC,IAAAA,gBAAgD;AAChD,mBAA2C;;;ACD3C,4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A,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL;AAAA,QACA,oBAAmB,cAAS,YAAT,mBAAkB;AAAA,QACrC,MAAM;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,QACH,OAAO,UAAU,QAAQ;AAAA,MAC3B;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,QAAM,oBAA4B;AAAA,IAChC,CAAC,EAAE,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,MAAM,SAAS;AACrC,aAAO;AAAA,QACL,IAAI,kBAAM;AAAA,QACV,SAAK,yBAAU,KAAK,QAAQ;AAAA,QAC5B,MAAM;AAAA,QACN,GAAG;AAAA,MACL;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,oBAA4B;AAAA,IAChC,CAAC,QAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B;AAAA,MACA,GAAG;AAAA,MACH,GAAG;AAAA,MACH,cAAc;AAAA,IAChB;AAAA,IACA,CAAC,YAAY,KAAK;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_utils"]}
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteOptionGroup
4
- } from "./chunk-7QON6ZHO.mjs";
4
+ } from "./chunk-CMFJUJJW.mjs";
5
5
  import "./chunk-ZNO5RUVT.mjs";
6
6
  export {
7
7
  useAutocompleteOptionGroup
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
3
3
 
4
- interface UseAutocompleteOptionProps extends Omit<HTMLUIProps<"li">, "children" | "value"> {
4
+ interface UseAutocompleteOptionProps extends Omit<HTMLUIProps, "children" | "value"> {
5
5
  /**
6
6
  * The label of the autocomplete option.
7
7
  */
@@ -34,15 +34,17 @@ declare const useAutocompleteOption: (props: UseAutocompleteOptionProps) => {
34
34
  customIcon: react.ReactElement<any, string | react.JSXElementConstructor<any>> | null | undefined;
35
35
  isFocused: boolean;
36
36
  isSelected: boolean;
37
- getOptionProps: PropGetter<"li", undefined>;
37
+ isTarget: boolean;
38
+ omitSelectedValues: boolean | undefined;
39
+ getOptionProps: PropGetter<"div", undefined>;
38
40
  };
39
41
  type UseAutocompleteOptionReturn = ReturnType<typeof useAutocompleteOption>;
40
42
  declare const useAutocompleteCreate: () => {
41
- getCreateProps: PropGetter<"li", undefined>;
43
+ getCreateProps: PropGetter<"div", undefined>;
42
44
  };
43
45
  type UseAutocompleteCreateReturn = ReturnType<typeof useAutocompleteCreate>;
44
46
  declare const useAutocompleteEmpty: () => {
45
- getEmptyProps: PropGetter<"li", undefined>;
47
+ getEmptyProps: PropGetter<"div", undefined>;
46
48
  };
47
49
  type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>;
48
50
 
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { HTMLUIProps, PropGetter } from '@yamada-ui/core';
3
3
 
4
- interface UseAutocompleteOptionProps extends Omit<HTMLUIProps<"li">, "children" | "value"> {
4
+ interface UseAutocompleteOptionProps extends Omit<HTMLUIProps, "children" | "value"> {
5
5
  /**
6
6
  * The label of the autocomplete option.
7
7
  */
@@ -34,15 +34,17 @@ declare const useAutocompleteOption: (props: UseAutocompleteOptionProps) => {
34
34
  customIcon: react.ReactElement<any, string | react.JSXElementConstructor<any>> | null | undefined;
35
35
  isFocused: boolean;
36
36
  isSelected: boolean;
37
- getOptionProps: PropGetter<"li", undefined>;
37
+ isTarget: boolean;
38
+ omitSelectedValues: boolean | undefined;
39
+ getOptionProps: PropGetter<"div", undefined>;
38
40
  };
39
41
  type UseAutocompleteOptionReturn = ReturnType<typeof useAutocompleteOption>;
40
42
  declare const useAutocompleteCreate: () => {
41
- getCreateProps: PropGetter<"li", undefined>;
43
+ getCreateProps: PropGetter<"div", undefined>;
42
44
  };
43
45
  type UseAutocompleteCreateReturn = ReturnType<typeof useAutocompleteCreate>;
44
46
  declare const useAutocompleteEmpty: () => {
45
- getEmptyProps: PropGetter<"li", undefined>;
47
+ getEmptyProps: PropGetter<"div", undefined>;
46
48
  };
47
49
  type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>;
48
50
 
@@ -62,8 +62,10 @@ var useAutocompleteOption = (props) => {
62
62
  onClose,
63
63
  onFocusNext
64
64
  } = useAutocompleteContext();
65
- const id = (0, import_react.useId)();
65
+ const uuid = (0, import_react.useId)();
66
+ const itemRef = (0, import_react.useRef)(null);
66
67
  let {
68
+ id,
67
69
  children,
68
70
  closeOnSelect: customCloseOnSelect,
69
71
  icon: customIcon,
@@ -73,13 +75,19 @@ var useAutocompleteOption = (props) => {
73
75
  ...computedProps
74
76
  } = { ...optionProps, ...props };
75
77
  const trulyDisabled = !!isDisabled && !isFocusable;
76
- const itemRef = (0, import_react.useRef)(null);
77
78
  const { descendants, index, register } = useAutocompleteDescendant({
78
79
  disabled: trulyDisabled
79
80
  });
80
81
  const values = descendants.values();
81
82
  const frontValues = values.slice(0, index);
82
83
  const isMulti = (0, import_utils2.isArray)(value);
84
+ const isDuplicated = frontValues.some(
85
+ ({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")
86
+ );
87
+ const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
88
+ const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
89
+ const isFocused = index === focusedIndex;
90
+ id != null ? id : id = uuid;
83
91
  if ((0, import_utils2.isUndefined)(optionValue)) {
84
92
  if ((0, import_utils2.isString)(children) || (0, import_utils2.isNumber)(children)) {
85
93
  optionValue = children.toString();
@@ -89,12 +97,6 @@ var useAutocompleteOption = (props) => {
89
97
  );
90
98
  }
91
99
  }
92
- const isDuplicated = frontValues.some(
93
- ({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")
94
- );
95
- const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
96
- const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
97
- const isFocused = index === focusedIndex;
98
100
  const onClick = (0, import_react.useCallback)(
99
101
  (ev) => {
100
102
  ev.stopPropagation();
@@ -125,6 +127,7 @@ var useAutocompleteOption = (props) => {
125
127
  );
126
128
  const getOptionProps = (0, import_react.useCallback)(
127
129
  (props2 = {}, ref = null) => {
130
+ const isHidden = !isTarget || omitSelectedValues && isSelected;
128
131
  const style = {
129
132
  border: "0px",
130
133
  clip: "rect(0px, 0px, 0px, 0px)",
@@ -137,14 +140,15 @@ var useAutocompleteOption = (props) => {
137
140
  width: "1px"
138
141
  };
139
142
  return {
140
- id,
141
143
  ref: (0, import_utils2.mergeRefs)(itemRef, ref, register),
142
144
  role: "option",
143
145
  ...computedProps,
144
146
  ...props2,
145
- style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
146
- "aria-checked": isSelected,
147
+ id,
148
+ style: isHidden ? style : void 0,
147
149
  "aria-disabled": (0, import_utils2.ariaAttr)(isDisabled),
150
+ "aria-hidden": (0, import_utils2.ariaAttr)(isHidden),
151
+ "aria-selected": isSelected,
148
152
  "data-disabled": (0, import_utils2.dataAttr)(isDisabled),
149
153
  "data-duplicated": (0, import_utils2.dataAttr)(isDuplicated),
150
154
  "data-focus": (0, import_utils2.dataAttr)(isFocused),
@@ -173,6 +177,8 @@ var useAutocompleteOption = (props) => {
173
177
  customIcon,
174
178
  isFocused,
175
179
  isSelected,
180
+ isTarget,
181
+ omitSelectedValues,
176
182
  getOptionProps
177
183
  };
178
184
  };
@@ -193,8 +199,10 @@ var useAutocompleteCreate = () => {
193
199
  };
194
200
  return {
195
201
  ref,
202
+ role: "option",
196
203
  ...props,
197
204
  style: isHit ? style : void 0,
205
+ "aria-hidden": (0, import_utils2.ariaAttr)(isHit),
198
206
  "data-focus": (0, import_utils2.dataAttr)(!isHit),
199
207
  tabIndex: -1,
200
208
  onClick: (0, import_utils2.handlerAll)(props.onClick, onCreate)
@@ -208,6 +216,7 @@ var useAutocompleteEmpty = () => {
208
216
  const { isEmpty, isHit } = useAutocompleteContext();
209
217
  const getEmptyProps = (0, import_react.useCallback)(
210
218
  (props = {}, ref = null) => {
219
+ const isHidden = isHit && !isEmpty;
211
220
  const style = {
212
221
  border: "0px",
213
222
  clip: "rect(0px, 0px, 0px, 0px)",
@@ -221,8 +230,10 @@ var useAutocompleteEmpty = () => {
221
230
  };
222
231
  return {
223
232
  ref,
233
+ role: "presentation",
224
234
  ...props,
225
- style: isHit && !isEmpty ? style : void 0,
235
+ style: isHidden ? style : void 0,
236
+ "aria-hidden": (0, import_utils2.ariaAttr)(isHidden),
226
237
  tabIndex: -1
227
238
  };
228
239
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-autocomplete-option.ts","../src/autocomplete-context.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","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAUO;AACP,mBAA2C;;;ACV3C,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,QAAI,wCAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;AD7BH,IAAM,iBAAiB,CAAC,WAAqC;AAnB7D;AAoBE,0CAAc,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,SAAK,oBAAM;AAEjB,MAAI;AAAA,IACF;AAAA,IACA,eAAe;AAAA,IACf,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,GAAG;AAAA,EACL,IAAI,EAAE,GAAG,aAAa,GAAG,MAAM;AAE/B,QAAM,gBAAgB,CAAC,CAAC,cAAc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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,kBAAc,wBAAS,CAAC,KAAK;AAAA,QAC7B,UAAU;AAAA,QACV,aAAS,0BAAW,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,oBAAkC;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":["import_utils","props"]}
1
+ {"version":3,"sources":["../src/use-autocomplete-option.ts","../src/autocomplete-context.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, \"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 uuid = useId()\n const itemRef = useRef<HTMLLIElement>(null)\n let {\n id,\n children,\n closeOnSelect: customCloseOnSelect,\n icon: customIcon,\n isDisabled,\n isFocusable,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n const trulyDisabled = !!isDisabled && !isFocusable\n const { descendants, index, register } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n const isMulti = isArray(value)\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 id ??= uuid\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 onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\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 = useCallback(\n (props = {}, ref = null) => {\n const isHidden = !isTarget || (omitSelectedValues && isSelected)\n\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: mergeRefs(itemRef, ref, register),\n role: \"option\",\n ...computedProps,\n ...props,\n id,\n style: isHidden ? style : undefined,\n \"aria-disabled\": ariaAttr(isDisabled),\n \"aria-hidden\": ariaAttr(isHidden),\n \"aria-selected\": isSelected,\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 isTarget,\n omitSelectedValues,\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 = 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 role: \"option\",\n ...props,\n style: isHit ? style : undefined,\n \"aria-hidden\": ariaAttr(isHit),\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 = useCallback(\n (props = {}, ref = null) => {\n const isHidden = isHit && !isEmpty\n\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 role: \"presentation\",\n ...props,\n style: isHidden ? style : undefined,\n \"aria-hidden\": ariaAttr(isHidden),\n tabIndex: -1,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAUO;AACP,mBAA2C;;;ACV3C,4BAAiC;AACjC,mBAA8B;AAEvB,IAAM;AAAA,EACX,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,uBAAuB;AACzB,QAAI,wCAAiB;AAiCd,IAAM,CAAC,sBAAsB,sBAAsB,QACxD,4BAAmC;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;AD7BH,IAAM,iBAAiB,CAAC,WAAqC;AAnB7D;AAoBE,0CAAc,MAAM,KAAK,CAAC,GA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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,MAAM;AAAA,QACN,GAAG;AAAA,QACH,OAAO,WAAW,QAAQ;AAAA,QAC1B,mBAAe,wBAAS,QAAQ;AAAA,QAChC,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,CAAC,OAAO,OAAO;AAAA,EACjB;AAEA,SAAO,EAAE,cAAc;AACzB;","names":["import_utils","props"]}
@@ -3,7 +3,7 @@ import {
3
3
  useAutocompleteCreate,
4
4
  useAutocompleteEmpty,
5
5
  useAutocompleteOption
6
- } from "./chunk-ZXALWDKQ.mjs";
6
+ } from "./chunk-3A2HEULI.mjs";
7
7
  import "./chunk-ZNO5RUVT.mjs";
8
8
  export {
9
9
  useAutocompleteCreate,