mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-07 22:26:57 +02:00
Restore offset option for dropdown component
This commit is contained in:
@@ -72,7 +72,7 @@ const PLACEMENT_RIGHT = isRTL ? 'left-start' : 'right-start'
|
||||
const PLACEMENT_LEFT = isRTL ? 'right-start' : 'left-start'
|
||||
|
||||
const Default = {
|
||||
offset: 0,
|
||||
offset: [0, 0],
|
||||
flip: true,
|
||||
boundary: 'clippingParents',
|
||||
reference: 'toggle',
|
||||
@@ -81,7 +81,7 @@ const Default = {
|
||||
}
|
||||
|
||||
const DefaultType = {
|
||||
offset: '(number|string|function)',
|
||||
offset: '(array|string|function)',
|
||||
flip: 'boolean',
|
||||
boundary: '(string|element)',
|
||||
reference: '(string|element|object)',
|
||||
@@ -298,6 +298,20 @@ class Dropdown extends BaseComponent {
|
||||
return this._element.closest(`.${CLASS_NAME_NAVBAR}`) !== null
|
||||
}
|
||||
|
||||
_getOffset() {
|
||||
const { offset } = this._config
|
||||
|
||||
if (typeof offset === 'string') {
|
||||
return offset.split(',').map(val => Number.parseInt(val, 10))
|
||||
}
|
||||
|
||||
if (typeof offset === 'function') {
|
||||
return popperData => offset(popperData, this._element)
|
||||
}
|
||||
|
||||
return offset
|
||||
}
|
||||
|
||||
_getPopperConfig() {
|
||||
const popperConfig = {
|
||||
placement: this._getPlacement(),
|
||||
@@ -313,6 +327,12 @@ class Dropdown extends BaseComponent {
|
||||
options: {
|
||||
fallbackPlacements: ['top', 'right', 'bottom', 'left']
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'offset',
|
||||
options: {
|
||||
offset: this._getOffset()
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user