Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Popover

Popover is a non-modal dialog that floats around a trigger. Popover is used to display contextual information to users, and should be paired with a clickable trigger element.

Popover is built on top of the Popper.js library, and is composed of the Popper component.

Import

  • Popover: The wrapper that provides props, state, and context to its children
  • PopoverTrigger: Used to wrap the reference (or trigger) element
  • PopoverContent: The popover itself
  • PopoverHeader: The header of the popover
  • PopoverBody: The body of the popover
  • PopoverFooter: The footer of the popover

Basic Usage

When using this component, ensure the children passed to PopoverTrigger is focusable. Popover should be accessible and should allow users to access it using the tab key on a keyboard.

A11y: When Popover opens, the focus status is sent to PopoverContent. When Popover is closed, the focus status is returned to the trigger.

EDITABLE EXAMPLE

Focus an element when Popover opens

By default, the focus status is to sent to PopoverContent when Popover opens. You can send the focus status to a specific element when it opens by passing the initialFocusRef prop.

EDITABLE EXAMPLE

Accessing Internal state

Tonic UI provides access to two internal states: isOpen and onClose. Use the render prop pattern to access the internal states.

EDITABLE EXAMPLE

Controlled Usage

You can control the opening and closing of Popover by passing the isOpen or onClose state.

If required, you can set returnFocusOnClose to false to prevent Popver from returning the focus status to the children of PopoverTrigger.

EDITABLE EXAMPLE

Customizing Popover

Hide arrow

EDITABLE EXAMPLE

Offset position

EDITABLE EXAMPLE

Hover Trigger

To show Popover when you mouse over or focus on the trigger, pass the prop trigger and set it to hover. When you focus on or mouse over the popover trigger, Popover will open.

If you quickly move your cursor to the popover content when it is open, Popover will remain open until you move away the cursor.

EDITABLE EXAMPLE

Mouse tracking

EDITABLE EXAMPLE

Popover Placement

Since Popover is controlled by PopperJS, you can change the placement of Popover by passing the placement prop.

Although you may have specified the placement, Popover will try to reposition itself if there is not enough available space at the specified placement.

EDITABLE EXAMPLE

Accessibility

The word "trigger" refers to the children of PopoverTrigger.

Keyboard and focus

  • When Popover is opened, the focus status is moved to PopoverContent. If initialFocusRef is set, then the focus status is moved to the element with the related reference (ref).
  • When Popover is closed, the focus status returns to the trigger. If you set returnFocusOnClose to false, the focus status will not return.
  • If trigger is set to hover:
    • Focusing on or mousing over the trigger will open Popover.
    • Blurring or mousing out of the trigger will close Popover. If you move your mouse into PopoverContent, Popover remains visible.
  • If trigger is set to click:
    • Clicking the trigger or using the Space or Enter key when the focus status is on the trigger will open Popover.
    • Clicking the trigger again will close Popover.
  • Hitting the Esc key while Popover is open and the focus status is within PopoverContent will close Popover. If you set closeOnEsc to false, Popover will not close.
  • Clicking outside or blurring out of PopoverContent closes Popover. If you set closeOnBlur to false, Popover will not close.

ARIA attributes

  • If the trigger is set to click, the role of the PopoverContent element is set to dialog. If the trigger is set to hover, the PopoverContent role is set to tooltip.
  • PopoverContent has aria-labelledby set to the id attribute of PopoverHeader.
  • PopoverContent has aria-describedby set to the id attribute of PopoverBody.
  • PopoverContent has aria-hidden set to true or false depending on the open/closed state of Popover.
  • The trigger has aria-haspopup set to true to denote that it triggers a popover.
  • The trigger has aria-controls set to the 'id' attribute of PopoverContent to associate the popover with the trigger.
  • The trigger has aria-expanded set to true or false depending on the open/closed state of the popover.

Props

Popover

NameTypeDefaultDescription
isOpenbooleanIf true, the popover is shown.
initialFocusRefReact.RefThe ref of the element that should receive the focus status when the popover opens.
triggerstring'click'The interaction that triggers the popover. One of: 'click', 'hover'
placementPopperJS.placement'bottom'Position the popover relative to the trigger element as well as surrounding elements. Possible values: 'top', 'bottom', 'right', 'left', 'top-start', 'top-end', 'bottom-start', 'bottom-end', 'right-start', 'right-end', 'left-start', 'left-end'
returnFocusOnClosebooleantrueIf true, the popover will return the focus status to the trigger when closing.
closeOnBlurbooleantrueIf true, the popover will close when you use the tab key or click outside the popover dialog.
closeOnEscbooleantrueIf true, the popover will close when you press the esc key.
childrenReactNode, (props: InternalState) => ReactNodeThe children of the popover.
hideArrowbooleanIf true, hide the arrow tip on the popover.
skiddingnumber0Displaces the popover (in pixels) along the reference element. Used by popper.js
distancenumber4Displaces the popover (in pixels) away from, or toward, the reference. Used by popper.js
delaynumber or object{ show: 0, hide: 100 }If trigger is hover, delay showing and hiding the popover (ms). Object structure is: delay={{ show: 500, hide: 100 }}
usePortalbooleantrueIf true, the popover is displayed with a Portal. Rendering content inside a Portal allows the popover content to escape the physical bounds of its parent while still being positioned correctly relative to its target.
onOpen() => voidA callback called when the popover opens.
onClose() => voidA callback called when the popover closes.
nextToCursorbooleanPopover will next to mouse cursor when mouse enter the reference.
followCursorbooleanPopover will follow mouse cursor when mouse move on the reference.
arrowAtstringThe arrow is at the position of the popover. Possible values: 'left', 'right', 'top', 'bottom'

PopoverTrigger

PopoverContent

PopoverHeader

PopoverBody

PopoverFooter