aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorNils K <[email protected]>2020-12-21 13:32:11 +0100
committerGitHub <[email protected]>2020-12-21 14:32:11 +0200
commit2d46e47464d15182c44a7d92c8f2476e70f4434e (patch)
tree39be89ab0696d4508df55ecc46db23f3e7df0ce1 /js/src
parent44667d89fa1bf8de15db57fad43696c62860e288 (diff)
downloadbootstrap-2d46e47464d15182c44a7d92c8f2476e70f4434e.tar.xz
bootstrap-2d46e47464d15182c44a7d92c8f2476e70f4434e.zip
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 <[email protected]>
Diffstat (limited to 'js/src')
-rw-r--r--js/src/dropdown.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 4d65008f8..008294e9b 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -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
}