A Popper can be used to display some content on top of another. It's an alternative to react-popper.
Some important features of the Popper component:
disablePortal
.anchorEl
is passed as the reference object to create a new Popper.js
instance.{{ādemoā: āSimplePopper.jsā}}
The open/close state of the popper can be animated with a render prop child and a transition component. This component should respect the following conditions:
onEnter
callback prop when the enter transition starts.onExited
callback prop when the exit transition is completed.
These two callbacks allow the popper to unmount the child content when closed and fully transitioned.Popper has built-in support for react-transition-group.
{{ādemoā: āTransitionsPopper.jsā}}
Alternatively, you can use react-spring.
{{ādemoā: āSpringPopper.jsā}}
{{ādemoā: āPositionedPopper.jsā}}
{{ādemoā: āScrollPlayground.jsā, āhideToolbarā: true, ābgā: true}}
The value of the anchorEl
prop can be a reference to a fake DOM element.
You need to create an object shaped like the VirtualElement
.
Highlight part of the text to see the popper:
{{ādemoā: āVirtualElementPopper.jsā}}
For more advanced use cases you might be able to take advantage of:
The package material-ui-popup-state
that takes care of popper state for you in most cases.
{{ādemoā: āPopperPopupState.jsā}}