Unstyled popper
The Popper component lets you create components that are displayed on top of other elements.
Features:
- 🕷 Popper relies on the 3rd party library (Popper.js v2) for perfect positioning.
- 💄 It's an alternative API to react-popper. It aims for simplicity.
- The
anchorElis passed as the reference object to create a newPopper.jsinstance. - The children are placed in a
Portalprepended to the body of the document to avoid rendering problems. You can disable this behavior withdisablePortalprop. - The page scroll isn't blocked when the popper opens.
- The placement of the popper updates with the available area in the viewport.
Caveats:
- Clicking away does not hide the
Poppercomponent. If you need this behavior, you can useClickAwayListener
Bundle size: 📦 8 kB gzipped.
Basic Popper
By default, the popper is mounted to the DOM when its open prop is set to true and removed from it when open turns false. If you want that to happen with a transition, use the keepMounted prop (see the Transition example below).
<button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</button>
<PopperUnstyled id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</PopperUnstyled>Placement
The popper's default placement is bottom. You can change it using the placement prop. Play around with the interactive demo below to see the many possible values there are for it.
Placement value:
ANCHOR