Popovers are floating overlays that contain additional information or interactive content.
The components can be imported via:
A Popover is composed of several components:
PlumaPopover - the root component, which sets up the context, state and interactionsPlumaPopoverTrigger - the element that triggers the popover to showPlumaPopoverTriggerButton - a Button component that acts as a trigger for the popoverPlumaPopoverContent - the content that will be shown when the trigger is clickedIf the content of the popover is simple, header and description props accept
strings to be rendered inside the popover:
The popover "trigger" will render as an unstyled button tag, to make it
focusable and visible to assistive technology.
When the popover is attached to text, the isUnderlined prop can be used on
the trigger to add a bottom border to it, to draw more attention to it:
The component accepts a placement argument, which accepts one of these values:
For example:
Usually, the contents of a popover will be more than a simple string.
To render any custom content inside the popover, use the PopoverContent component, and
do not use the description and header props:
You'll notice that when the popover opens, the first focusable element inside it will receive focus. This is an accessibility feature.
In addition to moving focus into the popover, the popover can also "trap" focus, as recommended in the Dialog ARIA pattern. While popovers aren't usually as prominent as a Modal, they may have to be treated as such depending on use case.
Enabling the focus trap will ensure that focus stays within the popover: when tabbing through items in the popover, tabbing past the last item will move focus to the first item, and vice versa.
The focus trap can be enabled with the shouldTrapFocus prop:
More focus trap options are available via the following props:
isFocusManagerDisabledshouldTrapFocusinitialFocusshouldReturnFocusshouldRenderFocusGuardsshouldShowVisuallyHiddenDismissfocusOrderBy default, PopoverTrigger will render an unstyled button tag. It is important
to render an element that is focusable, and that indicates it can be clicked.
If you'd like to use a different component as a trigger, PopoverTrigger is
polymorphic, and accepts an as prop. When doing this, make sure the component
or element you use is focusable and clickable.
The PopoverTriggerButton component is a convenient way to use a Button as the trigger for your popover. It supports all Button props (variant, size, icon, etc.).
Alternatively, the Popover component also exposes Floating UI props, which can
be used to attach trigger interactions to any element.
This can be used by passing in a render function into the content,
passing setReference into the component's ref, and spreading getReferenceProps:
By default, the popover will open when the trigger is clicked. Popovers typically contain long form or interactive content, and as such require intent to open and close.
However, if you'd like to open the popover on hover, this can be enabled via
shouldTriggerOnHover:
In addition to the existing middlewareOptions prop for customizing the behavior of the tooltip,
it's possible to provide entire custom middleware functions, which can be used for more complex scenarios or special use cases.
For example, we can create a middleware that changes the position of the tooltip's arrow:
Additional middleware to apply to Floating UI, for example custom middleware for more control. These will be applied after the default middleware.
Default:125
The duration (in ms) for the popover animation.
The text content to show in the popover.
Deprecated: use description instead
Whether the popover should be open initially
The text content to show in the popover
Default:['content']
The order in which focus should be moved when navigating through the popover. See Floating UI for more details.
Header text to display in the popover
Default:0
Which element to initially focus when the popover is opened.
Can be a number (a tabbable index as specified by focusOrder) or an HTMLElement.
See Floating UI for more details.
Default:false
Whether the popover should be disabled. Can be used to conditionally enable/disable a popover depending on state.
Default:false
Whether the popover should be draggable.
Default:false
Whether the focus manager (for the opened popover) should be disabled entirely. See Floating UI for more details.
Whether the popover should be open. Only use this along with onOpenChange if you want to control the state of the popover
Called when the open state of the popover is changing
Where the popover should be placed in relation to the trigger
Default:true
Whether focusout event listeners are attached to the trigger and popover,
to close the popover when focus moves outside of it.
See Floating UI for more details.
Default:true
Whether the focus guards are rendered by the focus manager. See Floating UI for more details.
Default:true
Whether the popover content's max width and/or max height should be restricted using the Floating UI size middleware.
By default, this is enabled, to prevent popovers from growing larger than the available viewport size.
Default:true
Whether focus should be returned to the trigger when the popover is closed. See Floating UI for more details.
Default:false
Whether visually hidden close buttons are rendered before and after the popover. See Floating UI for more details.
Default:false
If the popover contains interactive elements, the dialog pattern should be applied.
Enable shouldTrapFocus to ensure focus is kept within the popover while it's open.
See Floating UI for more details.
Default:true
Whether the popover should open when the trigger is clicked. This is the recommended default.
Default:false
Whether the popover should open when the trigger is focused.
Defaults to true when shouldTriggerOnHover is true.
Default:false
Whether the popover should open when the trigger is hovered. Only use if absolutely necessary, as Popovers are meant to be triggered by clicks.
The position CSS property to use on the floating element
Additional classes to apply on the popover component (the floating element, not the trigger). Should only be used as a last resort
Additional classes to apply on the popover content component. Should only be used as a last resort
Additional inline styles to apply on the popover component (the floating element, not the trigger). Should only be used as a last resort
An internal function to pass the Floating UI nodeId up to a parent if necessary.
Default:true
Whether the popover content should show an arrow.
Default:false
Whether "typeahead" functionality should be enabled, which focuses items while typing.
See Floating UI for more details.
Enabled by default when shouldNavigateList is true.
Whether the trigger element should show a bottom border for emphasis.
PlumaPopoverTriggerButton extends Button