Popover
Popovers provide the container and styles to overlay menus, tooltips, controls or text. They’re visually represented as a layer above other components and objects in a view, and float above a content view after being triggered by a click-event (or hover) such as a button, link, menu or icon. Popovers can contain range of content from simple text strings to inputs, or lightly structured content and imagery/illustration. It’s usage depends on the context.
When to use
- Describe the difference between visually similar elements.
- Hide information that's irrelevant once the user if familiar with the UI.
Accessibility
- The anchor will be focusable and user can tab to it using their keyboard.
- When triggerType="hover" focusing on the anchor will open the tooltip automatically
- When triggerType="click" a focused tooltip can be triggered via spacebar (assuming the anchor is a button)
- Both the escape key and clicking outside the popover will close it
- Supports a prop
accessibilityType: 'none' | 'menu' | 'tooltip'that defaults tomenu - When used as a
menu, the anchor will havearia-haspopup="true" aria-expanded="true" aria-controls="popover-id"and the popover will haveid="popover-id" - When used as a
tooltip, the anchor will haveid="jzowpv-anchor" aria-describedby="jzowpv-popover"and the popover will haveid="jzowpv-popover" aria-ownedby="jzowpv-anchor" role="tooltip"(note thatjzowpvis a random uuid generated at runtime). - When
accessibilityTypeis set tonone, nothing will be added so the user can do whatever they wish.
Examples
Overrides
Additionally, you can fully customize any part of the Popover through the overrides prop. The Popover consists of multiple subcomponents that are listed bellow and you can override each one of them. To help you identify the names of these subcomponents, you can highlight them through this selector:
Note: You should always use longhand CSS properties. Mixing shorthands and longhands will lead into strange behaviors!
API
Popover API
accessibilityType $Keys<typeof ACCESSIBILITY_TYPE> =
Controls how this popover behaves for screen readers and other assistive devices. See the A11Y section at the bottom of this document for more details.
$Keys{ none: "none", menu: "menu", tooltip: "tooltip" }"data-baseweb" string
id string
ignoreBoundary boolean = false
If true, popover element will not avoid element boundaries.
onMouseEnterDelay number = 200
Number of milliseconds to wait before showing the popover after mouse enters the trigger element (for triggerType hover).
onMouseLeaveDelay number = 200
Number of milliseconds to wait before showing the popover after mouse leaves the trigger element (for triggerType hover).
onClick function
Handler for click events on trigger element.
Event => mixedoverrides object = {}
Body { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Arrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Inner { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required placement $Keys<typeof TETHER_PLACEMENT> =
How to position the popover relative to the target.
$Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }showArrow boolean = false
Whether or not to show the arrow pointing from the popover to the trigger.
triggerType $Keys<typeof TRIGGER_TYPE> =
Whether to toggle the popover when trigger is clicked or hovered.
$Keys{ click: "click", hover: "hover" }mountNode HTMLElement
Where to mount the popover
HTMLElementanimateOutTime number
How long should be fade out animation in ms, default 0ms
popperOptions any
Popper options override https://popper.js.org/popper-documentation.html#Popper.Defaults eslint-disable-next-line flowtype/no-weak-types
children Node required
Content that should trigger the popover to be shown (also acts as the anchor against which the popover will be positioned).
Nodecontent union required
Content to render within the popover when it's shown.
One of Node, => NodeisOpen boolean required
Whether or not to show the popover.
onBlur function
Handler for blur events on trigger element.
() => mixedonClickOutside function
Handler for clicks outside the anchor/popover elements.
MouseEvent => mixedonEsc function
Handler for click events on trigger element.
() => mixedonFocus function
Handler for 'Esc' keypress events
() => mixedonMouseEnter function
Handler for mouseenter events on trigger element.
() => mixedonMouseLeave function
Handler for mouseleave events on trigger element.
() => mixedStateful Popover API
accessibilityType $Keys<typeof ACCESSIBILITY_TYPE> =
Controls how this popover behaves for screen readers and other assistive devices. See the A11Y section at the bottom of this document for more details.
$Keys{ none: "none", menu: "menu", tooltip: "tooltip" }"data-baseweb" string
id string
ignoreBoundary boolean = false
If true, popover element will not avoid element boundaries.
onMouseEnterDelay number = 200
Number of milliseconds to wait before showing the popover after mouse enters the trigger element (for triggerType hover).
onMouseLeaveDelay number = 200
Number of milliseconds to wait before showing the popover after mouse leaves the trigger element (for triggerType hover).
onClick function
Handler for click events on trigger element.
Event => mixedoverrides object = {}
Body { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Arrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Inner { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required placement $Keys<typeof TETHER_PLACEMENT> =
How to position the popover relative to the target.
$Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }showArrow boolean = false
Whether or not to show the arrow pointing from the popover to the trigger.
triggerType $Keys<typeof TRIGGER_TYPE> =
Whether to toggle the popover when trigger is clicked or hovered.
$Keys{ click: "click", hover: "hover" }mountNode HTMLElement
Where to mount the popover
HTMLElementanimateOutTime number
How long should be fade out animation in ms, default 0ms
popperOptions any
Popper options override https://popper.js.org/popper-documentation.html#Popper.Defaults eslint-disable-next-line flowtype/no-weak-types
children Node required
Content that should trigger the popover to be shown (also acts as the anchor against which the popover will be positioned).
Nodecontent union required
Content to render within the popover when it's shown.
One of Node, close function required () => undefined => NodedismissOnClickOutside boolean = true
Whether to hide the popover when the user clicks anywhere outside the trigger/popover.
dismissOnEsc boolean = true
Whether to hide the popover when the user presses the escape key.
initialState object
Initial state populated into the component
isOpen boolean required onClose function
Event handler when popover is hidden.
() => mixedonOpen function
Event handler when popover is shown.
() => mixedstateReducer function = (_, nextState) => undefined
Reducer function to manipulate internal state updates.
function $Keys{ open: "open", close: "close" }, isOpen boolean required , isOpen boolean required => isOpen boolean required Stateful Container API
children function required
$DiffaccessibilityType $Keys{ none: "none", menu: "menu", tooltip: "tooltip" }"data-baseweb" string id string ignoreBoundary boolean onMouseEnterDelay number onMouseLeaveDelay number onClick function Event => mixedoverrides Body { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Arrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required Inner { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>$arrowOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$isAnimating boolean required $isOpen boolean required $popoverOffset required top number required left number required $placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }$showArrow boolean required placement required $Keys{ auto: "auto", topLeft: "topLeft", top: "top", topRight: "topRight", rightTop: "rightTop", right: "right", rightBottom: "rightBottom", bottomRight: "bottomRight", bottom: "bottom", bottomLeft: "bottomLeft", leftBottom: "leftBottom", left: "left", leftTop: "leftTop" }showArrow boolean triggerType required $Keys{ click: "click", hover: "hover" }mountNode HTMLElementanimateOutTime number popperOptions any &children required Nodecontent union required One of Node, => NodeisOpen boolean required onBlur function () => mixedonClickOutside function MouseEvent => mixedonEsc function () => mixedonFocus function () => mixedonMouseEnter function () => mixedonMouseLeave function () => mixed, children required Node => NodePopover exports
You can import this module like so:
import {StatefulPopover} from 'baseui/popover'
It exports the following components or utility functions:
- StatefulPopover
- StatefulContainer
- Popover
- ACCESSIBILITY_TYPE
- PLACEMENT
- TRIGGER_TYPE
- STATE_CHANGE_TYPE
- ANIMATE_IN_TIME
- ANIMATE_OUT_TIME
- StyledArrow
- StyledBody
- StyledInner
- StyledPadding