Popovers
A popover is a small overlay that displays supplemental information to the user. It can contain rich content and is triggered when the UI element it relates to is selected.
Code
Relies on the third-party librarybootstrap.js(4.6)for its features and functionality.View Bootstrap’s popover doc
<button class="btn btn--brand" type="button" data-toggle="popover" data-trigger="focus" data-placement="top" data-content="…">…</button>
NameAttributeCopy
- content
data-content=""
- has header
title=""
- on top
data-placement=“top”
- on left
data-placement=“left”
- on right
data-placement=“right”
- on bottom
data-placement=“bottom”
A popover can be invoked using the @standardButton Twirl component.
@standardButton( id = "myId", classes = "btn-light", text = "Button label", popoverPlacement = "top", popoverBody = "Sed posuere consectetur est at lob ortis. Aenean eu leo quam." title="Popover header")
import {Button, Popover, OverlayTrigger} from 'react-p21';
const popover = ( <Popover id="popover-basic"> <Popover.Body>Sed posuere consectetur est at lob ortis. Aenean eu leo quam.</Popover.Body> </Popover>);
const Example = () => ( <OverlayTrigger trigger="click" placement="top" overlay={popover}> <Button variant="light">Popover Top</Button> </OverlayTrigger>);
render(<Example />);
In Practice
Use popovers for non-essential information that provides the user with additional guidance or actions.
- Can contain a header, formatted text, links, etc.
- Displaying a popover requires a user action (click, tap, or select via key command).
- Dismissing a popover also requires a user action.
- Be mindful of placement - a popover should not obscure critical elements on the page.
Accessibility
- Popovers should be operable using the keyboard alone.
- Popovers should be announced by screen readers.
- When a popover is opened, focus should be moved to the popover so that keyboard users can interact with it.
- When the popover is closed, focus should be returned to the element that triggered it.
For more information, see our accessibility guidelines.