@yamada-ui/autocomplete 1.5.4-next-20241008193728 → 1.6.0-dev-20241011153139

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist/autocomplete-create.js.map +1 -1
  2. package/dist/autocomplete-create.mjs +2 -2
  3. package/dist/autocomplete-empty.js.map +1 -1
  4. package/dist/autocomplete-empty.mjs +2 -2
  5. package/dist/autocomplete-option.js +9 -0
  6. package/dist/autocomplete-option.js.map +1 -1
  7. package/dist/autocomplete-option.mjs +2 -2
  8. package/dist/autocomplete.js +9 -0
  9. package/dist/autocomplete.js.map +1 -1
  10. package/dist/autocomplete.mjs +6 -6
  11. package/dist/{chunk-KLXMUIGY.mjs → chunk-2HJUFFCU.mjs} +2 -2
  12. package/dist/{chunk-DDMSYTKO.mjs → chunk-6OLHNK7O.mjs} +13 -1
  13. package/dist/chunk-6OLHNK7O.mjs.map +1 -0
  14. package/dist/{chunk-EEECVCVW.mjs → chunk-7LZUXESV.mjs} +4 -4
  15. package/dist/{chunk-WFLZPB35.mjs → chunk-AIBJWPRA.mjs} +2 -2
  16. package/dist/{chunk-BKW7XJ6R.mjs → chunk-K5HCHHCJ.mjs} +2 -2
  17. package/dist/{chunk-AXC7ILCH.mjs → chunk-Q33EMTO2.mjs} +4 -4
  18. package/dist/{chunk-BGZIX6SN.mjs → chunk-WERCEZNJ.mjs} +2 -2
  19. package/dist/index.js +9 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +7 -7
  22. package/dist/multi-autocomplete.js +9 -0
  23. package/dist/multi-autocomplete.js.map +1 -1
  24. package/dist/multi-autocomplete.mjs +6 -6
  25. package/dist/use-autocomplete-option.js +9 -0
  26. package/dist/use-autocomplete-option.js.map +1 -1
  27. package/dist/use-autocomplete-option.mjs +1 -1
  28. package/dist/use-autocomplete.js +9 -0
  29. package/dist/use-autocomplete.js.map +1 -1
  30. package/dist/use-autocomplete.mjs +3 -3
  31. package/package.json +13 -13
  32. package/dist/chunk-DDMSYTKO.mjs.map +0 -1
  33. /package/dist/{chunk-KLXMUIGY.mjs.map → chunk-2HJUFFCU.mjs.map} +0 -0
  34. /package/dist/{chunk-EEECVCVW.mjs.map → chunk-7LZUXESV.mjs.map} +0 -0
  35. /package/dist/{chunk-WFLZPB35.mjs.map → chunk-AIBJWPRA.mjs.map} +0 -0
  36. /package/dist/{chunk-BKW7XJ6R.mjs.map → chunk-K5HCHHCJ.mjs.map} +0 -0
  37. /package/dist/{chunk-AXC7ILCH.mjs.map → chunk-Q33EMTO2.mjs.map} +0 -0
  38. /package/dist/{chunk-BGZIX6SN.mjs.map → chunk-WERCEZNJ.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 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 useUpdateEffect,\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: generalCloseOnSelect,\n focusedIndex,\n inputRef,\n omitSelectedValues,\n setFocusedIndex,\n value,\n optionProps,\n onChange,\n onChangeLabel,\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 = !isMulti\n ? frontValues.some(({ node }) => node.dataset.value === (optionValue ?? \"\"))\n : false\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 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-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 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,EACA;AAAA,OACK;AACP,SAAS,aAAa,OAAO,cAAc;AAM3C,IAAM,iBAAiB,CAAC,WAAqC;AApB7D;AAqBE,uBAAc,MAAM,KAAK,CAAC,GAAC,YAAO,aAAa,MAAM,MAA1B,mBAA6B,WAAW;AAAA;AAgC9D,IAAM,wBAAwB,CAAC,UAAsC;AArD5E;AAsDE,QAAM;AAAA,IACJ,eAAe;AAAA,IACf;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;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,CAAC;AAEvC,QAAM,UAAU,OAAsB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AAuB;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"]}
@@ -2,13 +2,13 @@
2
2
  import {
3
3
  useAutocomplete,
4
4
  useAutocompleteInput
5
- } from "./chunk-BGZIX6SN.mjs";
5
+ } from "./chunk-WERCEZNJ.mjs";
6
6
  import {
7
7
  AutocompleteCreate
8
- } from "./chunk-BKW7XJ6R.mjs";
8
+ } from "./chunk-K5HCHHCJ.mjs";
9
9
  import {
10
10
  AutocompleteEmpty
11
- } from "./chunk-KLXMUIGY.mjs";
11
+ } from "./chunk-2HJUFFCU.mjs";
12
12
  import {
13
13
  AutocompleteList
14
14
  } from "./chunk-VTBUO5SK.mjs";
@@ -270,4 +270,4 @@ MultiAutocompleteField.__ui__ = "MultiAutocompleteField";
270
270
  export {
271
271
  MultiAutocomplete
272
272
  };
273
- //# sourceMappingURL=chunk-EEECVCVW.mjs.map
273
+ //# sourceMappingURL=chunk-7LZUXESV.mjs.map
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteOption
4
- } from "./chunk-DDMSYTKO.mjs";
4
+ } from "./chunk-6OLHNK7O.mjs";
5
5
  import {
6
6
  AutocompleteItemIcon
7
7
  } from "./chunk-V6YCG642.mjs";
@@ -60,4 +60,4 @@ AutocompleteCheckIcon.__ui__ = "AutocompleteCheckIcon";
60
60
  export {
61
61
  AutocompleteOption
62
62
  };
63
- //# sourceMappingURL=chunk-WFLZPB35.mjs.map
63
+ //# sourceMappingURL=chunk-AIBJWPRA.mjs.map
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  useAutocompleteCreate
4
- } from "./chunk-DDMSYTKO.mjs";
4
+ } from "./chunk-6OLHNK7O.mjs";
5
5
  import {
6
6
  AutocompleteItemIcon
7
7
  } from "./chunk-V6YCG642.mjs";
@@ -60,4 +60,4 @@ AutocompletePlusIcon.__ui__ = "AutocompletePlusIcon";
60
60
  export {
61
61
  AutocompleteCreate
62
62
  };
63
- //# sourceMappingURL=chunk-BKW7XJ6R.mjs.map
63
+ //# sourceMappingURL=chunk-K5HCHHCJ.mjs.map
@@ -2,13 +2,13 @@
2
2
  import {
3
3
  useAutocomplete,
4
4
  useAutocompleteInput
5
- } from "./chunk-BGZIX6SN.mjs";
5
+ } from "./chunk-WERCEZNJ.mjs";
6
6
  import {
7
7
  AutocompleteCreate
8
- } from "./chunk-BKW7XJ6R.mjs";
8
+ } from "./chunk-K5HCHHCJ.mjs";
9
9
  import {
10
10
  AutocompleteEmpty
11
- } from "./chunk-KLXMUIGY.mjs";
11
+ } from "./chunk-2HJUFFCU.mjs";
12
12
  import {
13
13
  AutocompleteList
14
14
  } from "./chunk-VTBUO5SK.mjs";
@@ -191,4 +191,4 @@ AutocompleteField.__ui__ = "AutocompleteField";
191
191
  export {
192
192
  Autocomplete
193
193
  };
194
- //# sourceMappingURL=chunk-AXC7ILCH.mjs.map
194
+ //# sourceMappingURL=chunk-Q33EMTO2.mjs.map
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-4SBNPEK7.mjs";
5
5
  import {
6
6
  AutocompleteOption
7
- } from "./chunk-WFLZPB35.mjs";
7
+ } from "./chunk-AIBJWPRA.mjs";
8
8
  import {
9
9
  useAutocompleteContext,
10
10
  useAutocompleteDescendants,
@@ -958,4 +958,4 @@ export {
958
958
  useAutocomplete,
959
959
  useAutocompleteInput
960
960
  };
961
- //# sourceMappingURL=chunk-BGZIX6SN.mjs.map
961
+ //# sourceMappingURL=chunk-WERCEZNJ.mjs.map
package/dist/index.js CHANGED
@@ -191,6 +191,15 @@ var useAutocompleteOption = (props) => {
191
191
  const values = descendants.values();
192
192
  const frontValues = values.slice(0, index);
193
193
  const isMulti = (0, import_utils3.isArray)(value);
194
+ if ((0, import_utils3.isUndefined)(optionValue)) {
195
+ if ((0, import_utils3.isString)(children) || (0, import_utils3.isNumber)(children)) {
196
+ optionValue = children.toString();
197
+ } else {
198
+ console.warn(
199
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
200
+ );
201
+ }
202
+ }
194
203
  const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
195
204
  const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
196
205
  const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});