UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

38 lines (36 loc) 1.23 kB
'use client'; import * as React from 'react'; import { FloatingPortal } from "../../floating-ui-react/index.js"; import { usePopoverRootContext } from "../root/PopoverRootContext.js"; import { PopoverPortalContext } from "./PopoverPortalContext.js"; /** * A portal element that moves the popup to a different part of the DOM. * By default, the portal element is appended to `<body>`. * Renders a `<div>` element. * * Documentation: [Base UI Popover](https://base-ui.com/react/components/popover) */ import { jsx as _jsx } from "react/jsx-runtime"; export const PopoverPortal = /*#__PURE__*/React.forwardRef(function PopoverPortal(props, forwardedRef) { const { keepMounted = false, ...portalProps } = props; const { store } = usePopoverRootContext(); const mounted = store.useState('mounted'); const shouldRender = mounted || keepMounted; if (!shouldRender) { return null; } return /*#__PURE__*/_jsx(PopoverPortalContext.Provider, { value: keepMounted, children: /*#__PURE__*/_jsx(FloatingPortal, { ref: forwardedRef, ...portalProps, renderGuards: false }) }); }); if (process.env.NODE_ENV !== "production") PopoverPortal.displayName = "PopoverPortal";