0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00

Dropdown - Disable applyStyle modifier instead of removing inline style applied by Popper.js

This commit is contained in:
Johann-S 2017-07-04 10:26:25 +02:00
parent 6797e84215
commit 0480a75a5a
2 changed files with 32 additions and 7 deletions

View File

@ -265,14 +265,10 @@ const Dropdown = (($) => {
}
}
// Disable Popper.js for Dropdown in Navbar
if (this._inNavbar) {
popperConfig.modifiers.AfterApplyStyle = {
enabled: true,
order: 901, // ApplyStyle order + 1
fn: () => {
// reset Popper styles
$(this._menu).attr('style', '')
}
popperConfig.modifiers.applyStyle = {
enabled: !this._inNavbar
}
}
return popperConfig

View File

@ -620,4 +620,33 @@ $(function () {
})
$dropdown.trigger('click')
})
QUnit.test('Dropdown should not use Popper.js in navbar', function (assert) {
assert.expect(1)
var done = assert.async()
var html = '<nav class="navbar navbar-expand-md navbar-light bg-light">'
+ '<div class="dropdown">'
+ ' <a class="nav-link dropdown-toggle" href="#" id="dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>'
+ ' <div class="dropdown-menu" aria-labelledby="dropdown">'
+ ' <a class="dropdown-item" href="#">Action</a>'
+ ' <a class="dropdown-item" href="#">Another action</a>'
+ ' <a class="dropdown-item" href="#">Something else here</a>'
+ ' </div>'
+ '</div>'
+ '</nav>'
$(html).appendTo('#qunit-fixture')
var $triggerDropdown = $('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown()
var $dropdownMenu = $triggerDropdown.next()
$triggerDropdown
.parent('.dropdown')
.on('shown.bs.dropdown', function () {
assert.ok($dropdownMenu.attr('style') === undefined, 'No inline style applied by Popper.js')
done()
})
$triggerDropdown.trigger($.Event('click'))
})
})