1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-08 14:46:34 +02:00

Support Popper virtual elements (#32376)

Adds the ability to use objects implementing the virtual element interface as the value for the reference option of a dropdown config.

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
Nils K
2020-12-21 13:32:11 +01:00
committed by GitHub
parent 44667d89fa
commit 2d46e47464
3 changed files with 64 additions and 3 deletions

View File

@@ -84,7 +84,7 @@ const DefaultType = {
offset: '(number|string|function)',
flip: 'boolean',
boundary: '(string|element)',
reference: '(string|element)',
reference: '(string|element|object)',
display: 'string',
popperConfig: '(null|object)'
}
@@ -172,6 +172,8 @@ class Dropdown extends BaseComponent {
if (typeof this._config.reference.jquery !== 'undefined') {
referenceElement = this._config.reference[0]
}
} else if (typeof this._config.reference === 'object') {
referenceElement = this._config.reference
}
this._popper = Popper.createPopper(referenceElement, this._menu, this._getPopperConfig())
@@ -257,6 +259,13 @@ class Dropdown extends BaseComponent {
typeCheckConfig(NAME, config, this.constructor.DefaultType)
if (typeof config.reference === 'object' && !isElement(config.reference) &&
typeof config.reference.getBoundingClientRect !== 'function'
) {
// Popper virtual elements require a getBoundingClientRect method
throw new Error(`${NAME}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`)
}
return config
}