Popovers
React Bootstrap 5 Popovers component
Documentation and examples for adding popovers, like those found in iOS, to any element on your site.
Note: Read the API tab to find all available options and advanced customization
Basic example
Overview
Things to know when using the popovers:
- Popovers are opt-in for performance reasons, so you must initialize them yourself.
-
Zero-length
<MDBPopoverHeader>
and<MDBPopoverBody>
values will never show a popover. - Triggering popovers on hidden elements will not work.
-
Popovers for
.disabled
ordisabled
elements must be triggered on a wrapper element. -
When triggered from anchors that wrap across multiple lines, popovers will be centered
between the anchors’ overall width. Add className
.text-nowrap
on your<MDBPopover>
s to avoid this behavior. - Popovers must be hidden before their corresponding elements have been removed from the DOM.
- Popovers can be triggered thanks to an element inside a shadow DOM.
Four directions
Four options are available: top, right, bottom, and left aligned.
Dismiss on next click
Use the dismiss
trigger to dismiss popovers on the user’s next click of a different
element than the toggle element.
Disabled elements
Elements with the disabled
attribute aren’t interactive, meaning users cannot
click them to trigger a popover (or tooltip). As a workaround create btnChildren
element with attribute disable
and change wrapper tag tag='span'
.
Popovers - API
Import
Properties
MDBPopover
Name | Type | Default | Description | Example |
---|---|---|---|---|
btnChildren
|
ReactNode | MDBBtn |
Render elements to button children |
<MDBPopover btnChildren="text" />
|
btnClassName
|
String | '' |
Add custom classes to MDBBtn |
<MDBPopover btnClassName="text" />
|
dismiss
|
Boolean | false |
Set dismiss on the next click |
<MDBPopover dismiss />
|
open
|
Boolean | false |
Set open popover on mounted component |
<MDBPopover open={true} />
|
options
|
Object | {} |
Set custom options from react-popper options. |
<MDBPopover options={{modifiers:{...}}} />
|
placement
|
String | top |
Set placement to popper. |
<MDBPopover placement='bottom' />
|
poperStyle
|
Object | {} |
Set styles to popper element. |
<MDBPopover poperStyle={{height:100}} />
|
popperTag
|
String | {} |
Set custom tag to popper component.. |
<MDBPopover popperTag='span' />
|
disablePortal
|
Boolean | false |
When true, component will be rendered in standard DOM hierarchy. |
<MDBPopover disablePortal />
|
MDBPopoverBody
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'span' |
Defines tag of the MDBPopoverBody element |
<MDBPopoverBody tag="section" />
|
MDBPopoverHeader
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'span' |
Defines tag of the MDBPopoverHeader element |
<MDBPopoverHeader tag="section" />
|
Events
Name | Type | Description |
---|---|---|
onClose
|
() => any | Fires when the popover demands to be hidden. |
onOpen
|
() => any | Fires when the popover demands to be shown. |
CSS variables
As part of MDB’s evolving CSS variables approach, popover now use local CSS variables on .popover
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.