Popover
Popover component A brief, introductory couple of sentences about the component. This is a second sentence just so that there’s a second line in this document. Think of this a teaser for the When/How to Use section.
Examples #
Popover #
Simple popover. Text to explain what’s special about this example.
<Popover content={<DemoContent />}> <Button>Open Popover</Button> </Popover>
Title and Subtitle #
Popovers can display a title and a subtitle Slightly longer text to explain what’s so special about this particular example.
Title
Subtitle
<DemoLayout> <Popover content={<DemoContent />} placement="right" subtitle="Subtitle" title="Title"> <Button disabled>Open Popover</Button> </Popover> </DemoLayout>
Placement #
The placement prop determines the placement of the Popover content relative to the trigger. Text to explain what’s special about this example.
<DemoLayout> <Popover content={<DemoContent />} placement="bottom"> <Button size="jumbo" disabled>Open Popover</Button> </Popover> </DemoLayout>
Overflow #
A Popover can extend beyond its bounding container, the blue area in this example, even if the overflow is set to hidden. Slightly longer text to explain what’s so special about this particular example.
<OverflowContainer> <Popover content={<DemoContent />} placement="right"> <Button disabled>Open Popover</Button> </Popover> </OverflowContainer>
Scrolling container #
Behavior inside of a scrolling container. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.
<ScrollParent> <Popover content={<DemoContent />} placement="left" isOpen restoreFocus={false}> <Button>Open Popover</Button> </Popover> </ScrollParent>
Focus Management #
There are a couple options available to help manage focus. Note: the focus style on the popover is for illustration purposes only. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.
<DemoLayout> <Popover content={<DemoContent />}> <Button>Both autoFocus and restoreFocus</Button> </Popover> <Popover content={<DemoContent />} autoFocus={false}> <Button>No autoFocus</Button> </Popover> <Popover content={<DemoContent />} restoreFocus={false}> <Button>No restoreFocus</Button> </Popover> <Popover content={<DemoContent />} autoFocus={false} restoreFocus={false}> <Button>Neither autoFocus nor restoreFocus</Button> </Popover> </DemoLayout>
Disabled #
In addition to disabling the Popover, you should also disable the trigger component. Slightly longer text to explain what’s so special about this particular example.
<Popover disabled content={<DemoContent />}> <Button disabled>Open Popover</Button> </Popover>
Controlled #
State can be managed by the application rather than the component. Slightly longer text to explain what’s so special about this particular example.
class App extends Component { constructor(props) { super(props); this.state = { isOpen: false }; this.onOpen = this.onOpen.bind(this); this.onClose = this.onClose.bind(this); this.togglePopover = this.togglePopover.bind(this); } onOpen(event) { this.setState({ isOpen: true }); } onClose(event) { // Prevent extra call to togglePopover when clicking the controlling button. // Also avoid interactions with other popovers. const demoLayoutNode = findDOMNode(this.demoLayout); if ( !event.nativeEvent && demoLayoutNode && demoLayoutNode.contains(event.target) ) { event.stopImmediatePropagation(); } this.setState({ isOpen: false }); } togglePopover(event) { if (this.state.isOpen) { this.onClose(event); } else { this.onOpen(event); } } render() { const label = this.state.isOpen ? 'Close Popover' : 'Open Popover'; return ( <DemoLayout ref={node => { this.demoLayout = node }}> <Popover content={<DemoContent />} isOpen={this.state.isOpen} onOpen={this.onOpen} onClose={this.onClose} restoreFocus={false}> <Button>{label}</Button> </Popover> <Button onClick={this.togglePopover}>{label}</Button> </DemoLayout> ); } }
Popover Props #
| Name | Type | Default | Description |
|---|---|---|---|
| autoFocus | boolean | true | Focuses the Popover content when opened |
| children | MnrlReactNode | required | Trigger for the Popover |
| content | React$Element | required | Content of the Popover |
| defaultIsOpen | boolean | Open the Popover immediately upon initialization | |
| disabled | boolean | required | Disables the Popover |
| hasArrow | boolean | true | Include an arrow on the Popover content pointing to the trigger |
| isOpen | boolean | For use with controlled components, in which the app manages Popover state | |
| modifiers | Object | Plugins that are used to alter behavior. See PopperJS docs for options. | |
| onClose | (event: Object) => void | Called when Popover is closed | |
| onOpen | (event: Object) => void | Called when Popover is opened | |
| placement | | 'auto' | 'auto-end' | 'auto-start' | 'bottom' | 'bottom-end' | 'bottom-start' | 'left' | 'left-end' | 'left-start' | 'right' | 'right-end' | 'right-start' | 'top' | 'top-end' | 'top-start' | 'bottom' | Placement of the Popover |
| restoreFocus | boolean | true | Focuses trigger when Popover is closed |
| subtitle | MnrlReactNode | Subtitle displayed under the title | |
| title | MnrlReactNode | Title of the Popover | |
| wrapContent | boolean | true | Display the content with default styles |
Undocumented properties will be applied to the root element.
Popover Theme Variables #
These variables can be used as hooks to override this component’s
style at either a global or
local level. The
theme referenced below is whatever theme is available from props
to the instance of this component.
| Variable | Value |
|---|---|
| PopoverContent_backgroundColor | theme.color_white |
| PopoverContent_borderColor | theme.color_gray_20 |
| PopoverContent_borderRadius | theme.borderRadius_1 |
| PopoverContent_boxShadow | theme.shadow_2 |
| PopoverContent_paddingVertical | theme.spacing_single |
| PopoverContent_zIndex | theme.zIndex_100 |
When/How to Use #
An explanation of when to use this component and basics about how to use it. Could also include when not to use this component, and which component should be used instead. More detailed how-to-use info is under Best Practices, below. It might be a couple of short sentences, or it could be a full paragraph or two.
Best Practices #
DO this other practice
Some text to explain why you should do this and when.