mirror of https://github.com/twbs/bootstrap.git
Reset Popper.js styles for Dropdowns in navbar
This commit is contained in:
parent
ce98a1da5b
commit
af93db294b
|
@ -96,10 +96,11 @@ const Dropdown = (($) => {
|
||||||
class Dropdown {
|
class Dropdown {
|
||||||
|
|
||||||
constructor(element, config) {
|
constructor(element, config) {
|
||||||
this._element = element
|
this._element = element
|
||||||
this._popper = null
|
this._popper = null
|
||||||
this._config = this._getConfig(config)
|
this._config = this._getConfig(config)
|
||||||
this._menu = this._getMenuElement()
|
this._menu = this._getMenuElement()
|
||||||
|
this._inNavbar = this._detectNavbar()
|
||||||
|
|
||||||
this._addEventListeners()
|
this._addEventListeners()
|
||||||
}
|
}
|
||||||
|
@ -153,17 +154,7 @@ const Dropdown = (($) => {
|
||||||
element = parent
|
element = parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._popper = new Popper(element, this._menu, {
|
this._popper = new Popper(element, this._menu, this._getPopperConfig())
|
||||||
placement : this._getPlacement(),
|
|
||||||
modifiers : {
|
|
||||||
offset : {
|
|
||||||
offset : this._config.offset
|
|
||||||
},
|
|
||||||
flip : {
|
|
||||||
enabled : this._config.flip
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// if this is a touch-enabled device we add extra
|
// if this is a touch-enabled device we add extra
|
||||||
// empty mouseover listeners to the body's immediate children;
|
// empty mouseover listeners to the body's immediate children;
|
||||||
|
@ -253,10 +244,54 @@ const Dropdown = (($) => {
|
||||||
} else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
|
} else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
|
||||||
placement = AttachmentMap.BOTTOMEND
|
placement = AttachmentMap.BOTTOMEND
|
||||||
}
|
}
|
||||||
|
|
||||||
return placement
|
return placement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_detectNavbar() {
|
||||||
|
return $(this._element).closest('.navbar').length > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_navbarPositioning() {
|
||||||
|
const $parentNavbar = $(this._element).closest('.navbar')
|
||||||
|
if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
|
||||||
|
if (!$parentNavbar.hasClass('navbar-expand')) {
|
||||||
|
return {
|
||||||
|
position: 'static',
|
||||||
|
transform: '',
|
||||||
|
float: 'none'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
_getPopperConfig() {
|
||||||
|
const popperConfig = {
|
||||||
|
placement : this._getPlacement(),
|
||||||
|
modifiers : {
|
||||||
|
offset : {
|
||||||
|
offset : this._config.offset
|
||||||
|
},
|
||||||
|
flip : {
|
||||||
|
enabled : this._config.flip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._inNavbar) {
|
||||||
|
popperConfig.modifiers.AfterApplyStyle = {
|
||||||
|
enabled: true,
|
||||||
|
order: 901, // ApplyStyle order + 1
|
||||||
|
fn: () => {
|
||||||
|
// reset Popper styles
|
||||||
|
$(this._menu).attr('style', '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return popperConfig
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
|
|
|
@ -77,9 +77,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
position: static !important;
|
position: static;
|
||||||
float: none;
|
float: none;
|
||||||
transform: unset !important;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +141,13 @@
|
||||||
|
|
||||||
&#{$infix} {
|
&#{$infix} {
|
||||||
@include media-breakpoint-down($breakpoint) {
|
@include media-breakpoint-down($breakpoint) {
|
||||||
|
.navbar-nav {
|
||||||
|
.dropdown-menu {
|
||||||
|
position: static;
|
||||||
|
float: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
> .container,
|
> .container,
|
||||||
> .container-fluid {
|
> .container-fluid {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
|
@ -158,8 +164,17 @@
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
position: absolute !important;
|
position: absolute;
|
||||||
top: 100% !important;
|
}
|
||||||
|
|
||||||
|
.dropdown-menu-right {
|
||||||
|
right: 0;
|
||||||
|
left: auto; // Reset the default from `.dropdown-menu`
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu-left {
|
||||||
|
right: auto;
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-link {
|
.nav-link {
|
||||||
|
|
Loading…
Reference in New Issue