flip: true,
boundary: 'scrollParent',
reference: 'toggle',
- display: 'dynamic'
+ display: 'dynamic',
+ popperConfig: null
}
const DefaultType = {
flip: 'boolean',
boundary: '(string|element)',
reference: '(string|element)',
- display: 'string'
+ display: 'string',
+ popperConfig: '(null|object)'
}
/**
}
_getPopperConfig() {
- const popperConfig = {
+ let popperConfig = {
placement: this._getPlacement(),
modifiers: {
offset: this._getOffset(),
}
}
+ if (this._config.popperConfig) {
+ popperConfig = {
+ ...popperConfig,
+ ...this._config.popperConfig
+ }
+ }
+
return popperConfig
}
expect(dropdown.toggle).toHaveBeenCalled()
})
+
+ it('should allow to pass config to popper.js thanks to popperConfig', () => {
+ fixtureEl.innerHTML = [
+ '<div class="dropdown">',
+ ' <button href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>',
+ ' <div class="dropdown-menu">',
+ ' <a class="dropdown-item" href="#">Secondary link</a>',
+ ' </div>',
+ '</div>'
+ ].join('')
+
+ const btnDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
+ const dropdown = new Dropdown(btnDropdown, {
+ popperConfig: {
+ placement: 'left'
+ }
+ })
+
+ const popperConfig = dropdown._getPopperConfig()
+
+ expect(popperConfig.placement).toEqual('left')
+ })
})
describe('toggle', () => {
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()
}
EventHandler.trigger(this.element, this.constructor.Event.INSERTED)
- this._popper = new Popper(this.element, tip, {
- placement: attachment,
- modifiers: {
- offset: this._getOffset(),
- flip: {
- behavior: this.config.fallbackPlacement
- },
- arrow: {
- element: `.${this.constructor.NAME}-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.classList.add(ClassName.SHOW)
// Private
+ _getPopperConfig(attachment) {
+ const defaultBsConfig = {
+ placement: attachment,
+ modifiers: {
+ offset: this._getOffset(),
+ flip: {
+ behavior: this.config.fallbackPlacement
+ },
+ arrow: {
+ element: `.${this.constructor.NAME}-arrow`
+ },
+ preventOverflow: {
+ boundariesElement: this.config.boundary
+ }
+ },
+ onCreate: data => {
+ if (data.originalPlacement !== data.placement) {
+ this._handlePopperPlacementChange(data)
+ }
+ },
+ onUpdate: data => this._handlePopperPlacementChange(data)
+ }
+
+ let resultConfig = defaultBsConfig
+ if (this.config.popperConfig) {
+ resultConfig = {
+ ...defaultBsConfig,
+ ...this.config.popperConfig
+ }
+ }
+
+ return resultConfig
+ }
+
_addAttachmentClass(attachment) {
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
}
tooltipInContainerEl.click()
})
+
+ it('should allow to pass config to popper.js thanks to popperConfig', () => {
+ fixtureEl.innerHTML = '<a href="#" rel="tooltip"/>'
+
+ const tooltipEl = fixtureEl.querySelector('a')
+ const tooltip = new Tooltip(tooltipEl, {
+ popperConfig: {
+ placement: 'left'
+ }
+ })
+
+ const popperConfig = tooltip._getPopperConfig('top')
+
+ expect(popperConfig.placement).toEqual('left')
+ })
})
describe('enable', () => {