},
{
"path": "./dist/js/bootstrap.bundle.js",
- "maxSize": "41 kB"
+ "maxSize": "42 kB"
},
{
"path": "./dist/js/bootstrap.bundle.min.js",
boundary: '(string|element)',
reference: '(string|element|object)',
display: 'string',
- popperConfig: '(null|object)'
+ popperConfig: '(null|object|function)'
}
/**
}
_getPopperConfig() {
- const popperConfig = {
+ const defaultBsPopperConfig = {
placement: this._getPlacement(),
modifiers: [{
name: 'preventOverflow',
// Disable Popper if we have a static display
if (this._config.display === 'static') {
- popperConfig.modifiers = [{
+ defaultBsPopperConfig.modifiers = [{
name: 'applyStyles',
enabled: false
}]
}
return {
- ...popperConfig,
- ...this._config.popperConfig
+ ...defaultBsPopperConfig,
+ ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
}
}
sanitize: 'boolean',
sanitizeFn: '(null|function)',
allowList: 'object',
- popperConfig: '(null|object)'
+ popperConfig: '(null|object|function)'
}
const AttachmentMap = {
}
_getPopperConfig(attachment) {
- const defaultBsConfig = {
+ const defaultBsPopperConfig = {
placement: attachment,
modifiers: [
{
}
return {
- ...defaultBsConfig,
- ...this.config.popperConfig
+ ...defaultBsPopperConfig,
+ ...(typeof this.config.popperConfig === 'function' ? this.config.popperConfig(defaultBsPopperConfig) : this.config.popperConfig)
}
}
expect(popperConfig.placement).toEqual('left')
})
+
+ it('should allow to pass config to Popper with `popperConfig` as a function', () => {
+ fixtureEl.innerHTML = [
+ '<div class="dropdown">',
+ ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" data-bs-placement="right" >Dropdown</button>',
+ ' <div class="dropdown-menu">',
+ ' <a class="dropdown-item" href="#">Secondary link</a>',
+ ' </div>',
+ '</div>'
+ ].join('')
+
+ const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
+ const getPopperConfig = jasmine.createSpy('getPopperConfig').and.returnValue({ placement: 'left' })
+ const dropdown = new Dropdown(btnDropdown, {
+ popperConfig: getPopperConfig
+ })
+
+ const popperConfig = dropdown._getPopperConfig()
+
+ expect(getPopperConfig).toHaveBeenCalled()
+ expect(popperConfig.placement).toEqual('left')
+ })
})
describe('toggle', () => {
expect(popperConfig.placement).toEqual('left')
})
+
+ it('should allow to pass config to Popper with `popperConfig` as a function', () => {
+ fixtureEl.innerHTML = '<a href="#" rel="tooltip">'
+
+ const tooltipEl = fixtureEl.querySelector('a')
+ const getPopperConfig = jasmine.createSpy('getPopperConfig').and.returnValue({ placement: 'left' })
+ const tooltip = new Tooltip(tooltipEl, {
+ popperConfig: getPopperConfig
+ })
+
+ const popperConfig = tooltip._getPopperConfig('top')
+
+ expect(getPopperConfig).toHaveBeenCalled()
+ expect(popperConfig.placement).toEqual('left')
+ })
})
describe('enable', () => {
</tr>
<tr>
<td><code>popperConfig</code></td>
- <td>null | object</td>
+ <td>null | object | function</td>
<td><code>null</code></td>
- <td>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a></td>
+ <td>
+ <p>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a>.</p>
+ <p>When a function is used to create the Popper configuration, it's called with an object that contains the Bootstrap's default Popper configuration. It helps you use and merge the default with your own configuration. The function must return a configuration object for Popper.</p>
+ </td>
</tr>
</tbody>
</table>
+#### Using function with `popperConfig`
+
+```js
+var dropdown = new bootstrap.Dropdown(element, {
+ popperConfig: function (defaultBsPopperConfig) {
+ // var newPopperConfig = {...}
+ // use defaultBsPopperConfig if needed...
+ // return newPopperConfig
+ }
+})
+```
+
### Methods
<table class="table">
</tr>
<tr>
<td><code>popperConfig</code></td>
- <td>null | object</td>
+ <td>null | object | function</td>
<td><code>null</code></td>
- <td>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a></td>
+ <td>
+ <p>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a>.</p>
+ <p>When a function is used to create the Popper configuration, it's called with an object that contains the Bootstrap's default Popper configuration. It helps you use and merge the default with your own configuration. The function must return a configuration object for Popper.</p>
+ </td>
</tr>
</tbody>
</table>
Options for individual popovers can alternatively be specified through the use of data attributes, as explained above.
{{< /callout >}}
+#### Using function with `popperConfig`
+
+```js
+var popover = new bootstrap.Popover(element, {
+ popperConfig: function (defaultBsPopperConfig) {
+ // var newPopperConfig = {...}
+ // use defaultBsPopperConfig if needed...
+ // return newPopperConfig
+ }
+})
+```
+
### Methods
{{< callout danger >}}
</tr>
<tr>
<td><code>popperConfig</code></td>
- <td>null | object</td>
+ <td>null | object | function</td>
<td><code>null</code></td>
- <td>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a></td>
+ <td>
+ <p>To change Bootstrap's default Popper config, see <a href="https://popper.js.org/docs/v2/constructors/#options">Popper's configuration</a>.</p>
+ <p>When a function is used to create the Popper configuration, it's called with an object that contains the Bootstrap's default Popper configuration. It helps you use and merge the default with your own configuration. The function must return a configuration object for Popper.</p>
+ </td>
</tr>
</tbody>
</table>
Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.
{{< /callout >}}
+#### Using function with `popperConfig`
+
+```js
+var tooltip = new bootstrap.Tooltip(element, {
+ popperConfig: function (defaultBsPopperConfig) {
+ // var newPopperConfig = {...}
+ // use defaultBsPopperConfig if needed...
+ // return newPopperConfig
+ }
+})
+```
+
### Methods
{{< callout danger >}}
- The default value for the `fallbackPlacements` is changed to `['top', 'right', 'bottom', 'left']` for better placement of popper elements.
- All the events for the dropdown are now triggered on the dropdown toggle button and then bubbled up to the parent element.
- Dropdown menus now have a `data-bs-popper="static"` attribute set when the positioning of the dropdown is static and `data-bs-popper="none"` when dropdown is in the navbar. This is added by our JavaScript and helps us use custom position styles without interfering with Popper's positioning.
+- `popperConfig` can be passed as a function that accepts the Bootstrap's default Popper config as an argument, so that you can merge this default configuration in your way.
## v5.0.0-beta1