},
{
"path": "./dist/js/bootstrap.bundle.min.js",
- "maxSize": "22 kB"
+ "maxSize": "22.25 kB"
},
{
"path": "./dist/js/bootstrap.js",
}
const Default = {
- offset : 0,
- flip : true,
- boundary : 'scrollParent',
- reference : 'toggle',
- display : 'dynamic'
+ offset : 0,
+ flip : true,
+ boundary : 'scrollParent',
+ reference : 'toggle',
+ display : 'dynamic',
+ popperConfig : null
}
const DefaultType = {
- offset : '(number|string|function)',
- flip : 'boolean',
- boundary : '(string|element)',
- reference : '(string|element)',
- display : 'string'
+ offset : '(number|string|function)',
+ flip : 'boolean',
+ boundary : '(string|element)',
+ reference : '(string|element)',
+ display : 'string',
+ popperConfig : '(null|object)'
}
/**
}
}
- return popperConfig
+ return {
+ ...popperConfig,
+ ...this._config.popperConfig
+ }
}
// Static
boundary : '(string|element)',
sanitize : 'boolean',
sanitizeFn : '(null|function)',
- whiteList : 'object'
+ whiteList : 'object',
+ popperConfig : '(null|object)'
}
const AttachmentMap = {
boundary : 'scrollParent',
sanitize : true,
sanitizeFn : null,
- whiteList : DefaultWhitelist
+ whiteList : DefaultWhitelist,
+ popperConfig : null
}
const HoverState = {
class Tooltip {
constructor(element, config) {
- /**
- * Check for Popper dependency
- * Popper - https://popper.js.org
- */
if (typeof Popper === 'undefined') {
throw new TypeError('Bootstrap\'s tooltips require Popper.js (https://popper.js.org/)')
}
this._timeout = null
this._hoverState = null
this._activeTrigger = null
- if (this._popper !== null) {
+ if (this._popper) {
this._popper.destroy()
}
$(this.element).trigger(this.constructor.Event.INSERTED)
- this._popper = new Popper(this.element, tip, {
- placement: attachment,
- modifiers: {
- offset: this._getOffset(),
- flip: {
- behavior: this.config.fallbackPlacement
- },
- arrow: {
- element: Selector.ARROW
- },
- preventOverflow: {
- boundariesElement: this.config.boundary
- }
- },
- onCreate: (data) => {
- if (data.originalPlacement !== data.placement) {
- this._handlePopperPlacementChange(data)
- }
- },
- onUpdate: (data) => this._handlePopperPlacementChange(data)
- })
+ this._popper = new Popper(this.element, tip, this._getPopperConfig(attachment))
$(tip).addClass(ClassName.SHOW)
// Private
+ _getPopperConfig(attachment) {
+ const defaultBsConfig = {
+ placement: attachment,
+ modifiers: {
+ offset: this._getOffset(),
+ flip: {
+ behavior: this.config.fallbackPlacement
+ },
+ arrow: {
+ element: Selector.ARROW
+ },
+ preventOverflow: {
+ boundariesElement: this.config.boundary
+ }
+ },
+ onCreate: (data) => {
+ if (data.originalPlacement !== data.placement) {
+ this._handlePopperPlacementChange(data)
+ }
+ },
+ onUpdate: (data) => this._handlePopperPlacementChange(data)
+ }
+
+ return {
+ ...defaultBsConfig,
+ ...this.config.popperConfig
+ }
+ }
+
_getOffset() {
const offset = {}
assert.strictEqual(offset.offset, myOffset)
assert.ok(typeof offset.fn === 'undefined')
})
+
+ QUnit.test('should allow to pass config to popper.js with `popperConfig`', function (assert) {
+ assert.expect(1)
+
+ var dropdownHTML =
+ '<div class="dropdown">' +
+ ' <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
+ ' <div class="dropdown-menu">' +
+ ' <a class="dropdown-item" href="#">Another link</a>' +
+ ' </div>' +
+ '</div>'
+
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown({
+ popperConfig: {
+ placement: 'left'
+ }
+ })
+
+ var dropdown = $dropdown.data('bs.dropdown')
+ var popperConfig = dropdown._getPopperConfig()
+
+ assert.strictEqual(popperConfig.placement, 'left')
+ })
})
assert.strictEqual(tooltip.config.sanitize, true)
})
+
+ QUnit.test('should allow to pass config to popper.js with `popperConfig`', function (assert) {
+ assert.expect(1)
+
+ var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
+ .appendTo('#qunit-fixture')
+ .bootstrapTooltip({
+ popperConfig: {
+ placement: 'left'
+ }
+ })
+
+ var tooltip = $trigger.data('bs.tooltip')
+ var popperConfig = tooltip._getPopperConfig('top')
+
+ assert.strictEqual(popperConfig.placement, 'left')
+ })
})
<td>'dynamic'</td>
<td>By default, we use Popper.js for dynamic positioning. Disable this with <code>static</code>.</td>
</tr>
+ <tr>
+ <td>popperConfig</td>
+ <td>null | object</td>
+ <td>null</td>
+ <td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
+ </tr>
</tbody>
</table>
<td>null</td>
<td>Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.</td>
</tr>
+ <tr>
+ <td>popperConfig</td>
+ <td>null | object</td>
+ <td>null</td>
+ <td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
+ </tr>
</tbody>
</table>
<td>null</td>
<td>Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.</td>
</tr>
+ <tr>
+ <td>popperConfig</td>
+ <td>null | object</td>
+ <td>null</td>
+ <td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
+ </tr>
</tbody>
</table>