@yamada-ui/autocomplete 1.5.3-dev-20240927164847 → 1.5.3-dev-20240927172557
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/autocomplete-create.js.map +1 -1
- package/dist/autocomplete-create.mjs +2 -2
- package/dist/autocomplete-empty.js.map +1 -1
- package/dist/autocomplete-empty.mjs +2 -2
- package/dist/autocomplete-list.js +14 -10
- package/dist/autocomplete-list.js.map +1 -1
- package/dist/autocomplete-list.mjs +2 -2
- package/dist/autocomplete-option.js +3 -1
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +2 -2
- package/dist/autocomplete.js +17 -11
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +8 -8
- package/dist/{chunk-OTVG42AD.mjs → chunk-2WVIW6HR.mjs} +2 -2
- package/dist/{chunk-2JAGPELI.mjs → chunk-5LPWFWE6.mjs} +4 -2
- package/dist/chunk-5LPWFWE6.mjs.map +1 -0
- package/dist/{chunk-K42L5QVM.mjs → chunk-7OWUOQZD.mjs} +5 -5
- package/dist/{chunk-ZTDA3B2B.mjs → chunk-CCOWDDFS.mjs} +2 -2
- package/dist/{chunk-2GOTGBRK.mjs → chunk-E3Y2E2TK.mjs} +2 -2
- package/dist/{chunk-YEFQMSJM.mjs → chunk-PCQMCEHL.mjs} +2 -2
- package/dist/{chunk-QGOCVO2C.mjs → chunk-R76HPAN4.mjs} +15 -11
- package/dist/chunk-R76HPAN4.mjs.map +1 -0
- package/dist/{chunk-5MMUZ2XQ.mjs → chunk-S53LMDD7.mjs} +2 -2
- package/dist/{chunk-ZZSGPNV3.mjs → chunk-UNGOVJSY.mjs} +5 -5
- package/dist/index.js +17 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/multi-autocomplete.js +17 -11
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +8 -8
- package/dist/use-autocomplete-list.js +14 -10
- package/dist/use-autocomplete-list.js.map +1 -1
- package/dist/use-autocomplete-list.mjs +1 -1
- package/dist/use-autocomplete-option.js +3 -1
- package/dist/use-autocomplete-option.js.map +1 -1
- package/dist/use-autocomplete-option.mjs +1 -1
- package/dist/use-autocomplete.js +3 -1
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +3 -3
- package/package.json +13 -13
- package/dist/chunk-2JAGPELI.mjs.map +0 -1
- package/dist/chunk-QGOCVO2C.mjs.map +0 -1
- /package/dist/{chunk-OTVG42AD.mjs.map → chunk-2WVIW6HR.mjs.map} +0 -0
- /package/dist/{chunk-K42L5QVM.mjs.map → chunk-7OWUOQZD.mjs.map} +0 -0
- /package/dist/{chunk-ZTDA3B2B.mjs.map → chunk-CCOWDDFS.mjs.map} +0 -0
- /package/dist/{chunk-2GOTGBRK.mjs.map → chunk-E3Y2E2TK.mjs.map} +0 -0
- /package/dist/{chunk-YEFQMSJM.mjs.map → chunk-PCQMCEHL.mjs.map} +0 -0
- /package/dist/{chunk-5MMUZ2XQ.mjs.map → chunk-S53LMDD7.mjs.map} +0 -0
- /package/dist/{chunk-ZZSGPNV3.mjs.map → chunk-UNGOVJSY.mjs.map} +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/use-autocomplete-option.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n mergeRefs,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, MouseEvent } from \"react\"\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\">, \"value\" | \"children\"> {\n /**\n * The value of the autocomplete option.\n */\n value?: string\n /**\n * The label of the autocomplete option.\n */\n children?: string\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 * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n value,\n omitSelectedValues,\n onChange,\n onChangeLabel,\n focusedIndex,\n setFocusedIndex,\n onClose,\n closeOnSelect: generalCloseOnSelect,\n optionProps,\n inputRef,\n onFocusNext,\n } = useAutocompleteContext()\n const id = useId()\n\n let {\n icon: customIcon,\n isDisabled,\n isFocusable,\n closeOnSelect: customCloseOnSelect,\n children,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n\n const trulyDisabled = !!isDisabled && !isFocusable\n\n const itemRef = useRef<HTMLLIElement>(null)\n\n const { index, register, descendants } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n\n const isMulti = isArray(value)\n const isDuplicated = !isMulti\n ? frontValues.some(({ node }) => node.dataset.value === (optionValue ?? \"\"))\n : false\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) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n setFocusedIndex(index)\n\n onChange(optionValue ?? \"\")\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? generalCloseOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n onFocusNext,\n omitSelectedValues,\n isDisabled,\n optionValue,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n generalCloseOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n useUpdateEffect(() => {\n if (isSelected) onChangeLabel(optionValue ?? \"\", { runOmit: false })\n }, [optionValue])\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 width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref: mergeRefs(itemRef, ref, register),\n id,\n role: \"option\",\n ...computedProps,\n ...props,\n tabIndex: -1,\n style:\n !isTarget || (omitSelectedValues && isSelected) ? style : undefined,\n \"data-target\": dataAttr(true),\n \"data-value\": optionValue ?? \"\",\n \"data-focus\": dataAttr(isFocused),\n \"data-disabled\": dataAttr(isDisabled),\n \"aria-checked\": isSelected,\n \"aria-disabled\": ariaAttr(isDisabled),\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n id,\n optionValue,\n computedProps,\n isDisabled,\n isFocused,\n isSelected,\n isTarget,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n isSelected,\n isFocused,\n customIcon,\n children,\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 width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref,\n ...props,\n tabIndex: -1,\n style: isHit ? style : undefined,\n \"data-focus\": dataAttr(!isHit),\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 { isHit, isEmpty } = 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 width: \"1px\",\n margin: \"-1px\",\n padding: \"0px\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n position: \"absolute\",\n }\n\n return {\n ref,\n ...props,\n tabIndex: -1,\n style: isHit && !isEmpty ? style : undefined,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n"],"mappings":";;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,aAAa,OAAO,cAAc;AAM3C,IAAM,iBAAiB,CAAC,WAAqC;AAjB7D;AAkBE,uBAAc,MAAM,KAAK,CAAC,GAAC,sCAAQ,aAAa,YAArB,mBAA8B,WAAW;AAAA;AAgC/D,IAAM,wBAAwB,CAAC,UAAsC;AAlD5E;AAmDE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,uBAAuB;AAC3B,QAAM,KAAK,MAAM;AAEjB,MAAI;AAAA,IACF,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,OAAO;AAAA,IACP,GAAG;AAAA,EACL,IAAI,EAAE,GAAG,aAAa,GA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AAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAEA,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,QACH,UAAU;AAAA,QACV,OAAO,QAAQ,QAAQ;AAAA,QACvB,cAAc,SAAS,CAAC,KAAK;AAAA,QAC7B,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,OAAO,QAAQ,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,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAEA,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,QACH,UAAU;AAAA,QACV,OAAO,SAAS,CAAC,UAAU,QAAQ;AAAA,MACrC;AAAA,IACF;AAAA,IACA,CAAC,OAAO,OAAO;AAAA,EACjB;AAEA,SAAO,EAAE,cAAc;AACzB;","names":["props"]}
|
@@ -2,16 +2,16 @@
|
|
2
2
|
import {
|
3
3
|
useAutocomplete,
|
4
4
|
useAutocompleteInput
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-PCQMCEHL.mjs";
|
6
6
|
import {
|
7
7
|
AutocompleteCreate
|
8
|
-
} from "./chunk-
|
8
|
+
} from "./chunk-E3Y2E2TK.mjs";
|
9
9
|
import {
|
10
10
|
AutocompleteEmpty
|
11
|
-
} from "./chunk-
|
11
|
+
} from "./chunk-CCOWDDFS.mjs";
|
12
12
|
import {
|
13
13
|
AutocompleteList
|
14
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-S53LMDD7.mjs";
|
15
15
|
import {
|
16
16
|
AutocompleteClearIcon,
|
17
17
|
AutocompleteIcon
|
@@ -268,4 +268,4 @@ MultiAutocompleteField.__ui__ = "MultiAutocompleteField";
|
|
268
268
|
export {
|
269
269
|
MultiAutocomplete
|
270
270
|
};
|
271
|
-
//# sourceMappingURL=chunk-
|
271
|
+
//# sourceMappingURL=chunk-7OWUOQZD.mjs.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client"
|
2
2
|
import {
|
3
3
|
useAutocompleteEmpty
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-5LPWFWE6.mjs";
|
5
5
|
import {
|
6
6
|
AutocompleteItemIcon
|
7
7
|
} from "./chunk-7SWSKLSA.mjs";
|
@@ -61,4 +61,4 @@ MinusIcon.__ui__ = "MinusIcon";
|
|
61
61
|
export {
|
62
62
|
AutocompleteEmpty
|
63
63
|
};
|
64
|
-
//# sourceMappingURL=chunk-
|
64
|
+
//# sourceMappingURL=chunk-CCOWDDFS.mjs.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client"
|
2
2
|
import {
|
3
3
|
useAutocompleteCreate
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-5LPWFWE6.mjs";
|
5
5
|
import {
|
6
6
|
AutocompleteItemIcon
|
7
7
|
} from "./chunk-7SWSKLSA.mjs";
|
@@ -60,4 +60,4 @@ PlusIcon.__ui__ = "PlusIcon";
|
|
60
60
|
export {
|
61
61
|
AutocompleteCreate
|
62
62
|
};
|
63
|
-
//# sourceMappingURL=chunk-
|
63
|
+
//# sourceMappingURL=chunk-E3Y2E2TK.mjs.map
|
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
} from "./chunk-6F3LT7J6.mjs";
|
5
5
|
import {
|
6
6
|
AutocompleteOption
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-2WVIW6HR.mjs";
|
8
8
|
import {
|
9
9
|
useAutocompleteContext,
|
10
10
|
useAutocompleteDescendants,
|
@@ -956,4 +956,4 @@ export {
|
|
956
956
|
useAutocomplete,
|
957
957
|
useAutocompleteInput
|
958
958
|
};
|
959
|
-
//# sourceMappingURL=chunk-
|
959
|
+
//# sourceMappingURL=chunk-PCQMCEHL.mjs.map
|
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
import { mergeRefs, useUpdateEffect } from "@yamada-ui/utils";
|
9
9
|
import { useCallback, useEffect, useId, useRef } from "react";
|
10
10
|
var useAutocompleteList = () => {
|
11
|
+
const uuid = useId();
|
11
12
|
const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
|
12
13
|
const descendants = useAutocompleteDescendantsContext();
|
13
14
|
const beforeFocusedIndex = useRef(-1);
|
@@ -45,16 +46,19 @@ var useAutocompleteList = () => {
|
|
45
46
|
if (!isOpen) beforeFocusedIndex.current = -1;
|
46
47
|
}, [isOpen]);
|
47
48
|
const getListProps = useCallback(
|
48
|
-
(props = {}, ref = null) =>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
(props = {}, ref = null) => {
|
50
|
+
var _a;
|
51
|
+
return {
|
52
|
+
as: "ul",
|
53
|
+
ref: mergeRefs(listRef, ref),
|
54
|
+
role: "listbox",
|
55
|
+
tabIndex: -1,
|
56
|
+
position: "relative",
|
57
|
+
id: (_a = props.id) != null ? _a : uuid,
|
58
|
+
...props
|
59
|
+
};
|
60
|
+
},
|
61
|
+
[listRef, uuid]
|
58
62
|
);
|
59
63
|
return {
|
60
64
|
onAnimationComplete,
|
@@ -65,4 +69,4 @@ var useAutocompleteList = () => {
|
|
65
69
|
export {
|
66
70
|
useAutocompleteList
|
67
71
|
};
|
68
|
-
//# sourceMappingURL=chunk-
|
72
|
+
//# sourceMappingURL=chunk-R76HPAN4.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/use-autocomplete-list.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 as: \"ul\",\n ref: mergeRefs(listRef, ref),\n role: \"listbox\",\n tabIndex: -1,\n position: \"relative\",\n id: props.id ?? uuid,\n ...props,\n }),\n [listRef, uuid],\n )\n\n return {\n onAnimationComplete,\n getListProps,\n }\n}\n"],"mappings":";;;;;;;AACA,SAAS,WAAW,uBAAuB;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M,eAAiC;AAAA,IACrC,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAM;AA9D7B;AA8DiC;AAAA,QAC3B,IAAI;AAAA,QACJ,KAAK,UAAU,SAAS,GAAG;AAAA,QAC3B,MAAM;AAAA,QACN,UAAU;AAAA,QACV,UAAU;AAAA,QACV,KAAI,WAAM,OAAN,YAAY;AAAA,QAChB,GAAG;AAAA,MACL;AAAA;AAAA,IACA,CAAC,SAAS,IAAI;AAAA,EAChB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client"
|
2
2
|
import {
|
3
3
|
useAutocompleteList
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-R76HPAN4.mjs";
|
5
5
|
import {
|
6
6
|
useAutocompleteContext
|
7
7
|
} from "./chunk-JPUKYLBW.mjs";
|
@@ -86,4 +86,4 @@ AutocompleteList.__ui__ = "AutocompleteList";
|
|
86
86
|
export {
|
87
87
|
AutocompleteList
|
88
88
|
};
|
89
|
-
//# sourceMappingURL=chunk-
|
89
|
+
//# sourceMappingURL=chunk-S53LMDD7.mjs.map
|
@@ -2,16 +2,16 @@
|
|
2
2
|
import {
|
3
3
|
useAutocomplete,
|
4
4
|
useAutocompleteInput
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-PCQMCEHL.mjs";
|
6
6
|
import {
|
7
7
|
AutocompleteCreate
|
8
|
-
} from "./chunk-
|
8
|
+
} from "./chunk-E3Y2E2TK.mjs";
|
9
9
|
import {
|
10
10
|
AutocompleteEmpty
|
11
|
-
} from "./chunk-
|
11
|
+
} from "./chunk-CCOWDDFS.mjs";
|
12
12
|
import {
|
13
13
|
AutocompleteList
|
14
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-S53LMDD7.mjs";
|
15
15
|
import {
|
16
16
|
AutocompleteIcon
|
17
17
|
} from "./chunk-7SWSKLSA.mjs";
|
@@ -191,4 +191,4 @@ AutocompleteField.__ui__ = "AutocompleteField";
|
|
191
191
|
export {
|
192
192
|
Autocomplete
|
193
193
|
};
|
194
|
-
//# sourceMappingURL=chunk-
|
194
|
+
//# sourceMappingURL=chunk-UNGOVJSY.mjs.map
|
package/dist/index.js
CHANGED
@@ -173,6 +173,7 @@ var useAutocompleteOption = (props) => {
|
|
173
173
|
inputRef,
|
174
174
|
onFocusNext
|
175
175
|
} = useAutocompleteContext();
|
176
|
+
const id = (0, import_react2.useId)();
|
176
177
|
let {
|
177
178
|
icon: customIcon,
|
178
179
|
isDisabled,
|
@@ -243,7 +244,7 @@ var useAutocompleteOption = (props) => {
|
|
243
244
|
};
|
244
245
|
return {
|
245
246
|
ref: (0, import_utils3.mergeRefs)(itemRef, ref, register),
|
246
|
-
id
|
247
|
+
id,
|
247
248
|
role: "option",
|
248
249
|
...computedProps,
|
249
250
|
...props2,
|
@@ -259,6 +260,7 @@ var useAutocompleteOption = (props) => {
|
|
259
260
|
};
|
260
261
|
},
|
261
262
|
[
|
263
|
+
id,
|
262
264
|
optionValue,
|
263
265
|
computedProps,
|
264
266
|
isDisabled,
|
@@ -437,6 +439,7 @@ var import_utils7 = require("@yamada-ui/utils");
|
|
437
439
|
var import_utils6 = require("@yamada-ui/utils");
|
438
440
|
var import_react3 = require("react");
|
439
441
|
var useAutocompleteList = () => {
|
442
|
+
const uuid = (0, import_react3.useId)();
|
440
443
|
const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
|
441
444
|
const descendants = useAutocompleteDescendantsContext();
|
442
445
|
const beforeFocusedIndex = (0, import_react3.useRef)(-1);
|
@@ -474,16 +477,19 @@ var useAutocompleteList = () => {
|
|
474
477
|
if (!isOpen) beforeFocusedIndex.current = -1;
|
475
478
|
}, [isOpen]);
|
476
479
|
const getListProps = (0, import_react3.useCallback)(
|
477
|
-
(props = {}, ref = null) =>
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
480
|
+
(props = {}, ref = null) => {
|
481
|
+
var _a;
|
482
|
+
return {
|
483
|
+
as: "ul",
|
484
|
+
ref: (0, import_utils6.mergeRefs)(listRef, ref),
|
485
|
+
role: "listbox",
|
486
|
+
tabIndex: -1,
|
487
|
+
position: "relative",
|
488
|
+
id: (_a = props.id) != null ? _a : uuid,
|
489
|
+
...props
|
490
|
+
};
|
491
|
+
},
|
492
|
+
[listRef, uuid]
|
487
493
|
);
|
488
494
|
return {
|
489
495
|
onAnimationComplete,
|