mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-26 23:54:23 +01:00
extract createPopper method
This commit is contained in:
parent
b1dad0943f
commit
9916191311
@ -129,7 +129,6 @@ class Dropdown extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = Dropdown.getParentFromElement(this._element)
|
|
||||||
const relatedTarget = {
|
const relatedTarget = {
|
||||||
relatedTarget: this._element
|
relatedTarget: this._element
|
||||||
}
|
}
|
||||||
@ -140,32 +139,12 @@ class Dropdown extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parent = Dropdown.getParentFromElement(this._element)
|
||||||
// Totally disable Popper for Dropdowns in Navbar
|
// Totally disable Popper for Dropdowns in Navbar
|
||||||
if (this._inNavbar) {
|
if (this._inNavbar) {
|
||||||
Manipulator.setDataAttribute(this._menu, 'popper', 'none')
|
Manipulator.setDataAttribute(this._menu, 'popper', 'none')
|
||||||
} else {
|
} else {
|
||||||
if (typeof Popper === 'undefined') {
|
this._createPopper(parent)
|
||||||
throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)')
|
|
||||||
}
|
|
||||||
|
|
||||||
let referenceElement = this._element
|
|
||||||
|
|
||||||
if (this._config.reference === 'parent') {
|
|
||||||
referenceElement = parent
|
|
||||||
} else if (isElement(this._config.reference)) {
|
|
||||||
referenceElement = getElement(this._config.reference)
|
|
||||||
} else if (typeof this._config.reference === 'object') {
|
|
||||||
referenceElement = this._config.reference
|
|
||||||
}
|
|
||||||
|
|
||||||
const popperConfig = this._getPopperConfig()
|
|
||||||
const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false)
|
|
||||||
|
|
||||||
this._popper = Popper.createPopper(referenceElement, this._menu, popperConfig)
|
|
||||||
|
|
||||||
if (isDisplayStatic) {
|
|
||||||
Manipulator.setDataAttribute(this._menu, 'popper', 'static')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a touch-enabled device we add extra
|
// If this is a touch-enabled device we add extra
|
||||||
@ -258,6 +237,31 @@ class Dropdown extends BaseComponent {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_createPopper(parent) {
|
||||||
|
if (typeof Popper === 'undefined') {
|
||||||
|
throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)')
|
||||||
|
}
|
||||||
|
|
||||||
|
let referenceElement = this._element
|
||||||
|
|
||||||
|
if (this._config.reference === 'parent') {
|
||||||
|
referenceElement = parent
|
||||||
|
} else if (isElement(this._config.reference)) {
|
||||||
|
referenceElement = getElement(this._config.reference)
|
||||||
|
} else if (typeof this._config.reference === 'object') {
|
||||||
|
referenceElement = this._config.reference
|
||||||
|
}
|
||||||
|
|
||||||
|
const popperConfig = this._getPopperConfig()
|
||||||
|
const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false)
|
||||||
|
|
||||||
|
this._popper = Popper.createPopper(referenceElement, this._menu, popperConfig)
|
||||||
|
|
||||||
|
if (isDisplayStatic) {
|
||||||
|
Manipulator.setDataAttribute(this._menu, 'popper', 'static')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_isShown(element = this._element) {
|
_isShown(element = this._element) {
|
||||||
return element.classList.contains(CLASS_NAME_SHOW)
|
return element.classList.contains(CLASS_NAME_SHOW)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user