UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

45 lines (44 loc) 2.01 kB
"use client"; import { getRefProp } from "../../core/utils/get-ref-prop/get-ref-prop.mjs"; 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/Combobox.context.mjs"; import { useComboboxTargetProps } from "../Combobox/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/ComboboxPopover/ComboboxPopoverTarget.tsx const defaultProps = { refProp: "ref" }; const ComboboxPopoverTarget = factory((props) => { const { children, refProp, ref, ...others } = useProps("ComboboxPopoverTarget", defaultProps, props); const child = getSingleElementChild(children); if (!child) throw new Error("ComboboxPopover.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 targetRef = useMergedRef(ref, ctx.store.targetRef, getRefProp(child)); const clonedElement = cloneElement(child, { ...useComboboxTargetProps({ targetType: "button", withAriaAttributes: true, withKeyboardNavigation: true, withExpandedAttribute: true, onKeyDown: child.props.onKeyDown, onClick: (event) => { ctx.store.toggleDropdown(); child.props.onClick?.(event); }, autoComplete: "off" }), ...others, [refProp]: targetRef }); return /* @__PURE__ */ jsx(Popover.Target, { refProp, children: clonedElement }); }); ComboboxPopoverTarget.displayName = "@mantine/core/ComboboxPopoverTarget"; //#endregion export { ComboboxPopoverTarget }; //# sourceMappingURL=ComboboxPopoverTarget.mjs.map