0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

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
This commit is contained in:
Roman O 2017-10-03 15:34:44 +03:00 committed by Johann-S
parent 898708dd27
commit 527f55c2f3
2 changed files with 12 additions and 5 deletions

View File

@ -588,7 +588,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
<tbody>
<tr>
<td>offset</td>
<td>number | string</td>
<td>number | string | function</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>
</tr>

View File

@ -80,7 +80,7 @@ const Dropdown = (() => {
}
const DefaultType = {
offset : '(number|string)',
offset : '(number|string|function)',
flip : 'boolean'
}
@ -246,12 +246,19 @@ const Dropdown = (() => {
}
_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 = {
placement : this._getPlacement(),
modifiers : {
offset : {
offset : this._config.offset
},
offset : offsetConf,
flip : {
enabled : this._config.flip
}