Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in dropdown toggle where menu would only clear on the first dropdown #5309

Merged
merged 1 commit into from
Oct 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed bug in dropdown toggle where menu would only clear on the first…
… drop down
  • Loading branch information
erlendfh committed Sep 27, 2012
commit e9a648cd39dc6b5e0f126b7272adeac816ece758
7 changes: 4 additions & 3 deletions docs/assets/js/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@

}

function clearMenus() {
getParent($(toggle))
.removeClass('open')
function clearMenus() {
$(toggle).each(function () {
getParent($(this)).removeClass("open")
})
}

function getParent($this) {
Expand Down
7 changes: 4 additions & 3 deletions docs/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,10 @@

}

function clearMenus() {
getParent($(toggle))
.removeClass('open')
function clearMenus() {
$(toggle).each(function () {
getParent($(this)).removeClass("open")
})
}

function getParent($this) {
Expand Down
7 changes: 4 additions & 3 deletions js/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@

}

function clearMenus() {
getParent($(toggle))
.removeClass('open')
function clearMenus() {
$(toggle).each(function () {
getParent($(this)).removeClass("open")
})
}

function getParent($this) {
Expand Down
42 changes: 41 additions & 1 deletion js/tests/unit/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ $(function () {
})

test("should return element", function () {
ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
var el = $("<div />")
ok(el.dropdown()[0] === el[0], 'same element returned')
})

test("should not open dropdown if target is disabled", function () {
Expand Down Expand Up @@ -102,4 +103,43 @@ $(function () {
dropdown.remove()
})

test("should remove open class if body clicked, with multiple drop downs", function () {
var dropdownHTML =
'<ul class="nav">'
+ ' <li><a href="#menu1">Menu 1</a></li>'
+ ' <li class="dropdown" id="testmenu">'
+ ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
+ ' <ul class="dropdown-menu" role="menu">'
+ ' <li><a href="#sub1">Submenu 1</a></li>'
+ ' </ul>'
+ ' </li>'
+ '</ul>'
+ '<div class="btn-group">'
+ ' <button class="btn">Actions</button>'
+ ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
+ ' <ul class="dropdown-menu">'
+ ' <li><a href="#">Action 1</a></li>'
+ ' </ul>'
+ '</div>'
, dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
, first = dropdowns.first()
, last = dropdowns.last()

ok(dropdowns.length == 2, "Should be two dropdowns")

first.click()
ok(first.parents('.open').length == 1, 'open class added on click')
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
$('body').click()
ok($("#qunit-fixture .open").length === 0, 'open class removed')

last.click()
ok(last.parent('.open').length == 1, 'open class added on click')
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
$('body').click()
ok($("#qunit-fixture .open").length === 0, 'open class removed')

$("#qunit-fixture").html("")
})

})