Popper
The Popper component lets you create tooltips and popovers that display information about an element on the page.
Introduction
The Popper is a utility component for creating various kinds of popups. It relies on the third-party library (Popper.js v2) for positioning.
Component
Usage
After installation, you can start building with this component using the following basic elements:
<span class="token keyword">import</span> Popper <span class="token keyword">from</span> <span class="token string">'@mui/base/Popper'</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">function</span> <span class="token function">MyApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popper</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token comment">/* the popper's content */</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popper</span></span><span class="token punctuation">></span></span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
Basics
By default, the Popper is mounted to the DOM when its open prop is set to true, and removed from the DOM when open is false.
anchorEl is passed as the reference object to create a new Popper.js instance.
The children are placed in a Portal prepended to the body of the document to avoid rendering problems.
You can disable this behavior with disablePortal prop.
The following demo shows how to create and style a basic popper. Click Toggle Popper to see how it behaves:
Customization
Placement
The popper's default placement is bottom.
You can change it using the placement prop.
Try changing this value to top in the interactive demo below to see how it works:
Transitions
You can animate the open and close states of the popper with a render prop child and a transition component, as long as the component meets these conditions:
- Is a direct child descendant of the popper
- Calls the
onEntercallback prop when the enter transition starts - Calls the
onExitedcallback prop when the exit transition is completed
These two callbacks allow the popper to unmount the child content when closed and fully transitioned.