docs/documentation/components/popover.mdx
Popovers appear either at the top, bottom, left or right of their target. The preferred and default side is the bottom. Popovers use smart positioning if there is not enough space.
The Popover uses the Positioner from Evergreen to handle the positioning logic.
Internally the Popover will make sure it is positioned within the viewport.
This means that sometimes the Popover flips — or it might move slightly to the left or right.
content, by setting the content prop, andtarget, as a single child element or a functionWhen you pass a function to the content prop you will be able to close the popover inside of the content.
<Popover
content={
<Pane width={240} height={240} display="flex" alignItems="center" justifyContent="center" flexDirection="column">
<Text>PopoverContent</Text>
</Pane>
}
>
<Button>Trigger Popover</Button>
</Popover>
When opening the Popover when bringFocusInside is true, focus will be brought inside the Popover component by looking
for elements with [autofocus] first, [tabindex] second and button last.
When passing a node as the Popover children, the Popover will handle focus management automatically when closing the Popover. When closing, it will return back focus on the target if nothing else has focus.
<Popover
bringFocusInside
content={
<Pane
width={320}
height={320}
paddingX={40}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<TextInput width="100%" />
</Pane>
}
>
<Button>Trigger Popover</Button>
</Popover>
<Popover
content={({ close }) => (
<Pane
width={320}
height={320}
paddingX={40}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Button onClick={close}>Close</Button>
</Pane>
)}
>
<Button>Trigger Popover</Button>
</Popover>
The Popover can be positioned on the following positions using the position prop:
Position.TOPPosition.TOP_LEFTPosition.TOP_RIGHTPosition.BOTTOMPosition.BOTTOM_LEFTPosition.BOTTOM_RIGHTPosition.LEFTPosition.RIGHT<Pane>
<Pane display="flex" justifyContent="space-between">
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>TOP_LEFT</Text>
</Pane>
}
position={Position.TOP_LEFT}
>
<Button>TOP_LEFT</Button>
</Popover>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>TOP</Text>
</Pane>
}
position={Position.TOP}
>
<Button>TOP</Button>
</Popover>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>TOP_RIGHT</Text>
</Pane>
}
position={Position.TOP_RIGHT}
>
<Button>TOP_RIGHT</Button>
</Popover>
</Pane>
<Pane display="flex" justifyContent="space-between" marginTop={40}>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>LEFT</Text>
</Pane>
}
position={Position.LEFT}
>
<Button>LEFT</Button>
</Popover>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>RIGHT</Text>
</Pane>
}
position={Position.RIGHT}
>
<Button>RIGHT</Button>
</Popover>
</Pane>
<Pane display="flex" justifyContent="space-between" marginTop={40}>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>BOTTOM_LEFT</Text>
</Pane>
}
position={Position.BOTTOM_LEFT}
>
<Button>BOTTOM_LEFT</Button>
</Popover>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>BOTTOM</Text>
</Pane>
}
position={Position.BOTTOM}
>
<Button>BOTTOM</Button>
</Popover>
<Popover
content={
<Pane
width={240}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Text>BOTTOM_RIGHT</Text>
</Pane>
}
position={Position.BOTTOM_RIGHT}
>
<Button>BOTTOM_RIGHT</Button>
</Popover>
</Pane>
</Pane>
<Popover
content={({ close }) => (
<Pane
width={320}
height={320}
paddingX={40}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Button onClick={close}>Close</Button>
</Pane>
)}
shouldCloseOnExternalClick={false}
>
<Button>Trigger Popover</Button>
</Popover>
<Popover
content={({ close }) => (
<Pane
width={320}
height={320}
paddingX={40}
display="flex"
alignItems="center"
justifyContent="center"
flexDirection="column"
>
<Button onClick={close}>Close</Button>
</Pane>
)}
shouldCloseOnEscapePress={false}
>
<Button>Trigger Popover</Button>
</Popover>