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

Light years star stuff harvesting star light citizens of distant epochs encyclopaedia galactica.
<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.

Light years star stuff harvesting star light citizens of distant epochs encyclopaedia galactica.
<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.

Light years star stuff harvesting star light citizens of distant epochs encyclopaedia galactica.
<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.

Light years star stuff harvesting star light citizens of distant epochs encyclopaedia galactica.
<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 #

NameTypeDefaultDescription
autoFocusbooleantrue

Focuses the Popover content when opened

childrenMnrlReactNoderequired

Trigger for the Popover

contentReact$Elementrequired

Content of the Popover

defaultIsOpenboolean

Open the Popover immediately upon initialization

disabledbooleanrequired

Disables the Popover

hasArrowbooleantrue

Include an arrow on the Popover content pointing to the trigger

isOpenboolean

For use with controlled components, in which the app manages Popover state

modifiersObject

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

restoreFocusbooleantrue

Focuses trigger when Popover is closed

subtitleMnrlReactNode

Subtitle displayed under the title

titleMnrlReactNode

Title of the Popover

wrapContentbooleantrue

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.

VariableValue
PopoverContent_backgroundColortheme.color_white
PopoverContent_borderColortheme.color_gray_20
PopoverContent_borderRadiustheme.borderRadius_1
PopoverContent_boxShadowtheme.shadow_2
PopoverContent_paddingVerticaltheme.spacing_single
PopoverContent_zIndextheme.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 practice

Some text to explain why you should do this and when.

DON’T do this other practice

Some text to explain why you should not do this.

DO this other practice

Some text to explain why you should do this and when.

DO this third practice

Some text to explain why you should do this and when.

Copyright © 2017 CA
We welcome feedback and contributions on GitHub