Display popover section relative to given target element
You can control the Popover state with the opened and onChange props:
Controlled example with mouse events:
If you need to use interactive elements (inputs, buttons, etc.) inside Popover.Dropdown , set the trapFocus prop:
Enable the inline middleware to use Popover with inline elements:
Stantler’s magnificent antlers were traded at high prices as works of art. As a result, this Pokémon was hunted close to extinction by those who were after the priceless antlers. When visiting a junkyard , you may catch sight of it having an intense fight with Murkrow over shiny objects.Ho-Oh’s feathers glow in seven colors depending on the angle at which they are struck by light. These feathers are said to bring happiness to the bearers. This Pokémon is said to live at the foot of a rainbow.
Set the width="target" prop to make the Popover dropdown take the same width as the target element:
Set the offset prop to a number to change the dropdown position relative to the target element. This way you can control the dropdown offset on the main axis only.
To control offset on both axes, pass an object with mainAxis and crossAxis properties:
You can enable or disable Floating UI middlewares with the middlewares prop:
Example of turning off shift and flip middlewares:
To customize Floating UI middleware options, pass them as an object to the middlewares prop. For example, to change the shift middleware padding to 20px , use the following configuration:
Set the withArrow prop to add an arrow to the dropdown. The arrow is a div element rotated with transform: rotate(45deg) .
The arrowPosition prop determines how the arrow is positioned relative to the target element when position is set to *-start and *-end values on the Popover component. By default, the value is center – the arrow is positioned in the center of the target element if it is possible.
If you change arrowPosition to side , then the arrow will be positioned on the side of the target element, and you will be able to control the arrow offset with the arrowOffset prop. Note that when arrowPosition is set to center , the arrowOffset prop is ignored.
Set the withOverlay prop to add an overlay behind the dropdown. You can pass additional configuration to the Overlay component with the overlayProps prop:
Use the hideDetached prop to configure how the dropdown behaves when the target element is hidden with styles ( display: none , visibility: hidden , etc.), removed from the DOM, or when the target element is scrolled out of the viewport.
By default, hideDetached is enabled – the dropdown is hidden with the target element. You can change this behavior with hideDetached={false} . To see the difference, try to scroll the root element of the following demo:
Set the disabled prop to prevent Popover.Dropdown from rendering:
By default, Popover closes when you click outside of the dropdown. To disable this behavior, set closeOnClickOutside={false} .
You can configure events that are used for click-outside detection with the clickOutsideEvents prop. By default, Popover listens to mousedown and touchstart events. You can change it to any other events, for example, mouseup and touchend :
If you need to control the opened state, but still want to close the popover on outside clicks and escape key presses, use the onDismiss prop:
Popover uses the FocusTrap component to manage focus. Add the data-autofocus attribute to the element that should receive initial focus:
Popover .Target requires an element or a component as a single child – strings, fragments, numbers, and multiple elements/components are not supported and will throw an error . Custom components must provide a prop to get the root element ref; all Mantine components support ref out of the box.
Custom components that are rendered inside Popover .Target are required to support the ref prop:
Pass ref to the root element:
Use Popover.ContextMenu to open the dropdown at the cursor position on right-click. It replaces Popover.Target and wraps the element that should respond to the contextmenu event – the browser's default context menu is suppressed, and Popover.Dropdown is positioned at the cursor. Right-clicking again repositions the dropdown to the new coordinates. Popover.Dropdown can contain any content. Set disabled to restore the browser's default context menu:
Right-click anywhere inside this area
A popover will open at the cursor position
On touch devices (most notably iOS Safari, which does not fire the contextmenu event), the dropdown is opened with a long-press instead. Use the longPressDelay prop to control how long the element must be pressed before the dropdown opens, 500 ms by default. To prevent the native text-selection callout from appearing under the dropdown on touch devices, Popover.ContextMenu disables text selection ( user-select: none ) on the wrapped element.
Nested popovers require children rendering without Portal . Usually, you should disable the portal with props of the component that renders popover content. For example, Select has a comboboxProps={{ withinPortal: false }} prop. Check the documentation of the component that you are using to render popover content to find out how to disable the portal. If the portal is not disabled, outside clicks will close all popovers.
Example of disabling the portal in Select and DatePickerInput components:
Popover follows WAI-ARIA recommendations :
An uncontrolled Popover will be accessible only when used with a button element or component that renders it ( Button , ActionIcon , etc.). Other elements will not support Space and Enter key presses.