mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-26 23:54:23 +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:
parent
898708dd27
commit
527f55c2f3
@ -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 = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DefaultType = {
|
const DefaultType = {
|
||||||
offset : '(number|string)',
|
offset : '(number|string|function)',
|
||||||
flip : 'boolean'
|
flip : 'boolean'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user