UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

45 lines (44 loc) 1.91 kB
"use client"; import { getSingleElementChild } from "../../../core/utils/get-single-element-child/get-single-element-child.mjs"; import { useProps } from "../../../core/MantineProvider/use-props/use-props.mjs"; import { factory } from "../../../core/factory/factory.mjs"; import { Popover } from "../../Popover/Popover.mjs"; import { useComboboxContext } from "../Combobox.context.mjs"; import { useComboboxTargetProps } from "../use-combobox-target-props/use-combobox-target-props.mjs"; import { cloneElement } from "react"; import { useMergedRef } from "@mantine/hooks"; import { jsx } from "react/jsx-runtime"; //#region packages/@mantine/core/src/components/Combobox/ComboboxTarget/ComboboxTarget.tsx const defaultProps = { refProp: "ref", targetType: "input", withKeyboardNavigation: true, withAriaAttributes: true, withExpandedAttribute: false, autoComplete: "off" }; const ComboboxTarget = factory((props) => { const { children, refProp, withKeyboardNavigation, withAriaAttributes, withExpandedAttribute, targetType, autoComplete, ref, ...others } = useProps("ComboboxTarget", defaultProps, props); const child = getSingleElementChild(children); if (!child) throw new Error("Combobox.Target component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported"); const ctx = useComboboxContext(); const clonedElement = cloneElement(child, { ...useComboboxTargetProps({ targetType, withAriaAttributes, withKeyboardNavigation, withExpandedAttribute, onKeyDown: child.props.onKeyDown, autoComplete }), ...others }); return /* @__PURE__ */ jsx(Popover.Target, { ref: useMergedRef(ref, ctx.store.targetRef), children: clonedElement }); }); ComboboxTarget.displayName = "@mantine/core/ComboboxTarget"; //#endregion export { ComboboxTarget }; //# sourceMappingURL=ComboboxTarget.mjs.map