Popover component renders an overlay of content anchored to a trigger button (or specific positioning element). It can be triggered by click (or keypress), by hover (or keyboard focus – as a tooltip), or programatically
npm install @paprika/popoverPopover component renders an overlay of content anchored to a trigger button (or specific positioning element). It can be triggered by click (or keypress), by hover (or keyboard focus – as a tooltip), or programatically
```
yarn add @paprika/popover
or with npm:
``
npm install @paprika/popover
| Prop | Type | required | default | Description |
| --------------------- | ----------------------------------------------------------------------------------------------------------- | -------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| align | [ Popover.types.align.TOP, Popover.types.align.RIGHT, Popover.types.align.BOTTOM, Popover.types.align.LEFT] | false | Popover.types.align.BOTTOM | Where the popover content is positioned relative to the trigger or getPositioningElement. |
| children | node | true | - | Content of the popover |
| isDark | bool | false | false | Displays as a "tooltip" style with white text on black background. |
| isEager | bool | false | false | Activated by mouseOver / focus instead of onClick. |
| isOpen | bool | false | null | How "controlled" popovers are shown / hidden. |
| isPortal | bool | false | true | This renders the popover inline in the DOM and not in a react portal. WARNING: will have side effects with paprika side panels and modals, use with caution. |
| defaultIsOpen | bool | false | null | How "uncontrolled" popovers can be rendered open by default. |
| edge | [ Popover.types.align.LEFT, Popover.types.align.RIGHT, null] | false | null | Where the edge of the popover content is based on the trigger or getPositioningElement |
| maxWidth | [string,number] | false | 320 | Maximum width of popover content. Using a number is recommended and implies px units. |
| minWidth | [string,number] | false | 0 | Minimumn width of popover content. Using a number is recommended and implies px units. |
| onClose | func | false | null | Callback to fire when user closes popover. |
| offset | number | false | parseInt(tokens.spaceLg, 10) | Distance, in px, between popover content edge and trigger / getPositioningElement. |
| getPositioningElement | func | false | null | Function that provides DOM element to use as target for positioning the popover. |
| getScrollContainer | func | false | null | Function that provides the scrolling DOM element that contains the popover. |
| shouldKeepFocus | bool | false | false | If focus will stay at the trigger when showing popover. Popover can still be closed when clicking outside or pressing escape key. |
| shouldUnmount | bool | false | true | Should unmount Popover Content or Tip Subcomponents from DOM when popover is closed |
| zIndex | number | false | zValue(1) | Number setting the z-index for the popover content / tip. |
| container | custom | false | null | Portal container for the Panel (DOM element) |
| Prop | Type | required | default | Description |
| -------- | ----------- | -------- | ------- | ----------------------------------------------------------------- |
| a11yText | string | false | null | Descriptive a11y text for assistive technologies for the trigger. |
| children | [func,node] | true | - | |
| Prop | Type | required | default | Description |
| -------- | ---- | -------- | ------- | ----------- |
| children | node | false | null | |
| Prop | Type | required | default | Description |
| -------- | ---- | -------- | ------- | ----------- |
| children | node | true | - | |
| Prop | Type | required | default | Description |
| ------ | ------ | -------- | ------- | -------------------------- |
| zIndex | number | false | null | Number setting the z-index |
The can be used as a controlled or uncontrolled component. If controlled, the isOpen and onClose props must be utilized.
The can be used as a tooltip by making it open "eagerly" on hover or keyboard focus via the isEager prop. Typically a very short tooltip is also designed with white text on a black background, achieved with the isDark prop.
With an uncontrolled , it may be convenient to use the to wrap the element the user will interact with to display the popover because this results in a being wrapped around that UI element, with all of the handlers it requires already hooked up.
For a controlled , or the case where the child element is a
It may not be necessary to use a element at all if the is controlled. Then its children (excluding and ) will by default be used as the positioning element (see Basic controlled example below).
Content for the is also included as children, wrapped by the . For a "card" style, the is a convenient helper.
To include an arrow that points to the trigger element, the can be included as a sibling element of the (include it _after_ the Content to avoid an explicit zIndex prop on the Tip).
`jsx
import Popover from "@paprika/popover";
...
`
`jsx
import Popover from "@paprika/popover";
...
{(onClickHandler, a11yAttributes) => (
)}
`
`jsx
import Popover from "@paprika/popover";
...
const [isOpen, setOpen] = React.useState(false);
...
``
- Storybook Showcase
- GitHub source code
- Create GitHub issue
- CHANGELOG