Popover
A Popover is essentially an interactive
Tooltip for displaying an overlay anchored to a
particular element. It can set up to open automatically using a trigger
element that also serves as its anchor point, or it can be opened manually
positioned relative to an anchor
element.
React
import { Popover } from '@hover/blueprint';
Basic usage
It is used to display contextual information to the user, and should be paired with a clickable trigger element.
When Popover opens, focus is sent to the popover content. When it closes, focus is returned to the trigger.
Close button
Pass isClosable
to enable the built-in close button.
Hover
Pass isHover
to open the popover when the trigger is hovered instead of
clicked.
Dark color scheme
Rendering the Popover in a Portal
To render a popover in a Portal
, pass the
inPortal
prop.
Initial focus
By default, focus is to sent to the popover content when it opens. Pass the
initialFocusRef
prop to send focus to a specific element instead.
Controlled usage
You can control the opening and closing of the popover by passing the isOpen
,
and onClose
props.
Sometimes you might need to set the returnFocusOnClose
prop to false
to
prevent popover from returning focus to PopoverTrigger
's children.
Anchor
Pass anchor
instead of trigger
to prevent trigger any action. The wrapped
component will become a position reference.
When passing an anchor
instead of a trigger, the state of the Popover must
be controlled with external state (controlled mode).
Accessing internal state
All Popover elements have access to the internal popover state (isOpen
and
onClose
). Use the render prop pattern to gain access to them.
Placement
Since popover is powered by Popper, you can change the
placement of the popover by passing the placement
prop.
The possible values are:
Start | Center | End |
---|---|---|
bottom-start | bottom (default) | bottom-end |
auto-start | auto | auto-end |
top-start | top | top-end |
left-start | left | left-end |
right-start | right | right-end |
Lazily mounting Popover
By default, the Popover
component renders its content to the DOM, meaning that
invisible popover contents are still rendered but are hidden by styles.
If you want to defer rendering of popover content until that Popover
is
opened, you can use the isLazy
prop. This is useful if your content needs to
be extra performant, or make network calls on mount that should only happen when
the component is displayed.
Accessibility
Keyboard and Focus
- When the popover is opened, focus is moved to the
PopoverContent
. If theinitialFocusRef
is set, then focus moves to the element with thatref
. - When the popover is closed, focus returns to the trigger. If you set
returnFocusOnClose
tofalse
, focus will not return. - If trigger is set to
hover
:- Focusing on or mousing over the trigger will open the popover.
- Blurring or mousing out of the trigger will close the popover. If you move
your mouse into the
PopoverContent
, it'll remain visible.
- If trigger is set to
click
:- Clicking the trigger or using the
Space
orEnter
when focus is on the trigger will open the popover. - Clicking the trigger again will close the popover.
- Clicking the trigger or using the
- Hitting the
Esc
key while the popover is open and focus is within thePopoverContent
, will close the popover. If you setcloseOnEsc
tofalse
, it will not close. - Clicking outside or blurring out of the
PopoverContent
closes the popover. If you setcloseOnBlur
tofalse
, it will not close.
ARIA Attributes
- If the trigger is set to
click
, thePopoverContent
element has role set todialog
. If the trigger is set tohover
, thePopoverContent
hasrole
set totooltip
. - The
PopoverContent
hasaria-labelledby
set to theid
of thePopoverHeader
. - The
PopoverContent
hasaria-describedby
set to theid
of thePopoverBody
. - The
PopoverContent
hasaria-hidden
set totrue
orfalse
depending on the open/closed state of the popover. - The trigger has
aria-haspopup
set totrue
to denote that it triggers a popover. - The trigger has
aria-controls
set to theid
of thePopoverContent
to associate the popover and the trigger. - The trigger has
aria-expanded
set totrue
orfalse
depending on the open/closed state of the popover.