Popper.js

Wut? Poppers?

A popper is an element on the screen which “pops out” from the natural flow of your application.
Common examples of poppers are tooltips, popovers and drop-downs.

So, yet another tooltip library?

Well, basically, no.
Popper.js is a positioning engine, its purpose is to calculate the position of an element
to make it possible to position it near a given reference element.

The engine is completely modular and most of its features are implemented as modifiers
(similar to middlewares or plugins).
The whole code base is written in ES2015 and its features are automatically tested on real browsers thanks to SauceLabs and TravisCI.

Tooltip.js

Since lots of users just need a simple way to integrate powerful tooltips in their projects,
we created Tooltip.js.
It’s a small library that makes it easy to automatically create tooltips using as engine Popper.js.
Its API is almost identical to the famous tooltip system of Bootstrap, in this way it will be
easy to integrate it in your projects.
The tooltips generated by Tooltip.js are accessible thanks to the aria tags.

*: Bower isn’t officially supported, it can be used to install Tooltip.js only trough the unpkg.com CDN. This method has the limitation of not being able to define a specific version of the library. Bower and Popper.js suggests to use npm or Yarn for your projects.
For more info, read the related issue.

Dist targets

Popper.js is currently shipped with 3 targets in mind: UMD, ESM and ESNext.

UMD - Universal Module Definition: AMD, RequireJS and globals;

ESM - ES Modules: For webpack/Rollup or browser supporting the spec;

ESNext: Available in dist/, can be used with webpack and babel-preset-env;

Make sure to use the right one for your needs. If you want to import it with a <script> tag, use UMD.

Usage

Given an existing popper DOM node, ask Popper.js to position it near its button

Callbacks

Popper.js supports two kinds of callbacks, the onCreate callback is called after
the popper has been initalized. The onUpdate one is called on any subsequent update.

constreference=document.querySelector('.my-button');constpopper=document.querySelector('.my-popper');newPopper(reference,popper,{onCreate:(data)=>{// data is an object containing all the informations computed// by Popper.js and used to style the popper and its arrow// The complete description is available in Popper.js documentation},onUpdate:(data)=>{// same as `onCreate` but called on subsequent updates}});

Writing your own modifiers

Popper.js is based on a “plugin-like” architecture, most of its features are fully encapsulated “modifiers”.
A modifier is a function that is called each time Popper.js needs to compute the position of the popper. For this reason, modifiers should be very performant to avoid bottlenecks.

React, Vue.js, Angular, AngularJS, Ember.js (etc…) integration

Integrating 3rd party libraries in React or other libraries can be a pain because
they usually alter the DOM and drive the libraries crazy.
Popper.js limits all its DOM modifications inside the applyStyle modifier,
you can simply disable it and manually apply the popper coordinates using
your library of choice.

For a comprehensive list of libraries that let you use Popper.js into existing
frameworks, visit the MENTIONS page.

Alternatively, you may even override your own applyStyles with your custom one and
integrate Popper.js by yourself!

functionapplyReactStyle(data){// export data in your framework and use its content to apply the style to your popper};constreference=document.querySelector('.my-button');constpopper=document.querySelector('.my-popper');newPopper(reference,popper,{modifiers:{applyStyle:{enabled:false},applyReactStyle:{enabled:true,fn:applyReactStyle,order:800,},},});

Migration from Popper.js v0

Since the API changed, we prepared some migration instructions to make it easy to upgrade to
Popper.js v1.

https://github.com/FezVrasta/popper.js/issues/62

Feel free to comment inside the issue if you have any questions.

Performances

Popper.js is very performant. It usually takes 0.5ms to compute a popper’s position (on an iMac with 3.5G GHz Intel Core i5).
This means that it will not cause any jank, leading to a smooth user experience.

Notes

Libraries using Popper.js

The aim of Popper.js is to provide a stable and powerful positioning engine ready to
be used in 3rd party libraries.