diff options
author | Rohit Sharma <rohit2sharma95@gmail.com> | 2020-12-16 21:07:27 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2021-01-28 13:23:33 +0300 |
commit | b1bd54955ed5d6cd3eeb848dd068fc8bca88d585 (patch) | |
tree | cc5c4caa190a618508d0fabb8df8dc87bee185bc /js/src/tooltip.js | |
parent | 881f43a3b928e792185ed388e2589c73ea8c4be6 (diff) |
Restore `offset` option for tooltip/popover components
Diffstat (limited to 'js/src/tooltip.js')
-rw-r--r-- | js/src/tooltip.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 909cb0f8a7..6d85fde269 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -50,6 +50,7 @@ const DefaultType = { html: 'boolean', selector: '(string|boolean)', placement: '(string|function)', + offset: '(array|string|function)', container: '(string|element|boolean)', fallbackPlacements: 'array', boundary: '(string|element)', @@ -80,6 +81,7 @@ const Default = { html: false, selector: false, placement: 'top', + offset: [0, 0], container: false, fallbackPlacements: ['top', 'right', 'bottom', 'left'], boundary: 'clippingParents', @@ -473,6 +475,20 @@ class Tooltip extends BaseComponent { return context } + _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(attachment) { const defaultBsConfig = { placement: attachment, @@ -485,6 +501,12 @@ class Tooltip extends BaseComponent { } }, { + name: 'offset', + options: { + offset: this._getOffset() + } + }, + { name: 'preventOverflow', options: { rootBoundary: this.config.boundary |