Bootstrap: Popper.js messing up dropdown styles

Created on 13 Aug 2017  路  21Comments  路  Source: twbs/bootstrap

Loving the new popper.js but was wondering if there was a way to disable the custom styles it auto adds to elements?

Its adding the following:

    position: absolute;
    transform: translate3d(0px, 0px, 0px);
    top: 0px;
    left: 0px;
    will-change: transform;

This in turn overrides some custom animations I am trying to implement, it also messes up alignment if I wanted to put dropddowns in a container. The plugin is great but there must be a way to disable this custom "hardcode" style feature?

css feature has-pr js v4

Most helpful comment

You can just turn off the transform placement on Popper to make it only use top/left for positioning instead. Then you can use transform for any animations/transitions as you wish.

Popper.Defaults.modifiers.computeStyle.gpuAcceleration = false;

All 21 comments

These styles are the ones needed to actually position the dropdown. Without them the dropdown would not be positioned.

Yep but that's possible to disable Popper.js style we did it when Dropdown are in a navbar so why not add a feature to allow folks to do that

But then what's the point to use a dropdown?

Yep I agree they won't take any advantage of Popper.js

Perhaps @myorangeca can elaborate on the custom animations being applied so we can see what properties conflict? I definitely understand the desire to customize animations for positioned elements.

It's probably because of the transform property. Ideally dropdowns should allow an intermediate wrapper people can use to apply custom css and animations to it.

Doing so the outer most wrapper is used for the position and the inner one for the animations

I have customized the dropdown to do the following animation below. I had to use !important style to override popper.js styles (clearly not the best solution).

.show > .dropdown-menu {
    -moz-transform: scale(1) !important;
    -o-transform: scale(1) !important;
    -ms-transform: scale(1) !important;
    -webkit-transform: scale(1) !important;
    transform: scale(1) !important;
    moz-transform-origin: 29px -50px;
    -o-transform-origin: 29px -50px;
    -ms-transform-origin: 29px -50px;
    -webkit-transform-origin: 29px -50px;
    transform-origin: 29px -50px;
    opacity: 1;
    visibility: visible;
}

.dropdown-menu {
    -moz-transform: scale(0.8) !important;
    -o-transform: scale(0.8) !important;
    -ms-transform: scale(0.8) !important;
    -webkit-transform: scale(0.8) !important;
    transform: scale(0.8) !important;
    transition: all 400ms ease-in;
    opacity: 0;
    visibility: hidden;
    display: block;
}

.dropdown-menu-custom {
    right: 15px !important;
    top: 59px !important;
    left: auto !important;
}

Where I understand that popper inserts these classes dynamically to position the dropdown, but it causes problems if the dropdown is inside some container or in a nav bar with 'boxed layout view'

I think popper.js should have an option to check elements with certain data attributes (ie data-popper-static) to ignore hardcoded styles for that particular element.

Would like to add, if I have any custom scroll plugins inside any dropdowns (ie. slimscroll.js), popper's custom style messes up the plugin from being rendered (translate3d bug maybe). We will be needing some form of control to disable the plugins ability to add custom styles for some elements.

@myorangeca may you open an issue on the popper.js repo about the scroll plugins? I use a scroll plugin in the demo website popper.js.org and works just fine

@FezVrasta I might just do that. But don't you think a css solution would be more prefered over a JS solution. And the option to disable the popper's custom style might be needed in some cases?

But don't you think a css solution would be more prefered over a JS solution. And the option to disable the popper's custom style might be needed in some cases?

I'm a yes on both accounts, for what it's worth.

You can just turn off the transform placement on Popper to make it only use top/left for positioning instead. Then you can use transform for any animations/transitions as you wish.

Popper.Defaults.modifiers.computeStyle.gpuAcceleration = false;

@klaslundberg thanks for that! I still think there should be an option via data-tooltip to disable this;

This hurt me for several hours today as well, trying to figure out why all my dropdown animations suddenly started going crazy. A lot of people are going to want to animate their dropdowns...

my dropdown list was flying all over the document), the problem solved only by turning off the computeStyle

Popper.Defaults.modifiers.computeStyle.enabled = false;

Popper.Defaults.modifiers.computeStyle.gpuAcceleration = false no longer works when used popper in bootstrap.bundle.js

@logolevel's hack works! Thx!

In Bootstrap >=4.1 there is an 'data-display="static"' attribute that you could add to the toggle element. That way Popper wont mess with de position of that dropdown specifically.

Thank you for the breadcrumb @leitocardoso . This does indeed prevent any inlines styles, thank you. Doc - https://getbootstrap.com/docs/4.2/components/dropdowns/#responsive-alignment

FWIW, just upgraded to bootstrap 4.2 and was really surprised to find this. This should live in the core SASS bundle, like everything else, not controlled by JS (other than class toggling).

@leitocardoso thank you very much ..

'data-display="static"

This solved my issue. Thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steve-32a picture steve-32a  路  3Comments

devdelimited picture devdelimited  路  3Comments

eddywashere picture eddywashere  路  3Comments

leomao10 picture leomao10  路  3Comments

bellwood picture bellwood  路  3Comments