Commit 527f55c2 authored by Roman O's avatar Roman O Committed by Johann-S
Browse files

Offset option for dropdown can be function (#24222)

* Offset option can be function (Popper.js)

* Fix...add function type for offset option

* Remove constants for popper config

* Optimize code. Remove foreach loop.

* Refactoring. Remove getOffset method
parent 898708dd
6 merge requests!28721Hot test,!27561Adds font-weight-medium to font weight classes,!25494web pack,!25326Adjust examples,!23207#22402 : modal: new autofocus & keyboardBtnNav options,!17021v4
Showing with 12 additions and 5 deletions
+12 -5
...@@ -588,7 +588,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap ...@@ -588,7 +588,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
<tbody> <tbody>
<tr> <tr>
<td>offset</td> <td>offset</td>
<td>number | string</td> <td>number | string | function</td>
<td>0</td> <td>0</td>
<td>Offset of the dropdown relative to its target. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..offset.offset">offset docs</a>.</td> <td>Offset of the dropdown relative to its target. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..offset.offset">offset docs</a>.</td>
</tr> </tr>
......
...@@ -80,7 +80,7 @@ const Dropdown = (() => { ...@@ -80,7 +80,7 @@ const Dropdown = (() => {
} }
const DefaultType = { const DefaultType = {
offset : '(number|string)', offset : '(number|string|function)',
flip : 'boolean' flip : 'boolean'
} }
...@@ -246,12 +246,19 @@ const Dropdown = (() => { ...@@ -246,12 +246,19 @@ const Dropdown = (() => {
} }
_getPopperConfig() { _getPopperConfig() {
const offsetConf = {}
if (typeof this._config.offset === 'function') {
offsetConf.fn = (data) => {
data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {})
return data
}
} else {
offsetConf.offset = this._config.offset
}
const popperConfig = { const popperConfig = {
placement : this._getPlacement(), placement : this._getPlacement(),
modifiers : { modifiers : {
offset : { offset : offsetConf,
offset : this._config.offset
},
flip : { flip : {
enabled : this._config.flip enabled : this._config.flip
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment