Skip to content
Merged
Next Next commit
Update dropdown.js
  • Loading branch information
719media authored Jan 6, 2018
commit d723decd6acd32c47835e879da464304b5e5a2a7
24 changes: 16 additions & 8 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ const Dropdown = (($) => {
const Default = {
offset : 0,
flip : true,
boundary : 'scrollParent'
boundary : 'scrollParent',
reference : 'toggle'
}

const DefaultType = {
offset : '(number|string|function)',
flip : 'boolean',
boundary : '(string|element)'
boundary : '(string|element)',
reference : '(string|element)'
}


Expand Down Expand Up @@ -155,20 +157,26 @@ const Dropdown = (($) => {
if (typeof Popper === 'undefined') {
throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)')
}
let element = this._element
// for dropup with alignment we use the parent as popper container
if ($(parent).hasClass(ClassName.DROPUP)) {
if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) {
element = parent
let referenceElement = this._element

if (this._config.reference === 'parent') {
referenceElement = parent
} else if (Util.isElement(this._config.reference)) {
referenceElement = this._config.reference;

//check if it's jQuery element
if (typeof this._config.reference.jquery !== 'undefined') {
referenceElement = this._config.reference[0];
}
}

// If boundary is not `scrollParent`, then set position to `static`
// to allow the menu to "escape" the scroll parent's boundaries
// https://github.com/twbs/bootstrap/issues/24251
if (this._config.boundary !== 'scrollParent') {
$(parent).addClass(ClassName.POSITION_STATIC)
}
this._popper = new Popper(element, this._menu, this._getPopperConfig())
this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig())
}


Expand Down