Skip to content

Commit

Permalink
dropdown collapses after link click
Browse files Browse the repository at this point in the history
  • Loading branch information
joeframbach committed Aug 30, 2012
1 parent 4674945 commit 6952756
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@
$('html')
.on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus)
$('body')
.on('click.dropdown touchstart.dropdown.data-api', '.dropdown', function (e) { e.stopPropagation() })
.on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
})

}(window.jQuery);
}(window.jQuery);
26 changes: 25 additions & 1 deletion js/tests/unit/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,28 @@ $(function () {
dropdown.remove()
})

})
test("should collapse after link clicked", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#" id="test_link">Something else here</a></li>'
+ '<li class="divider"></li>'
+ '<li><a href="#">Another link</a></li>'
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.dropdown()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'not open before click')
dropdown.click()
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
$('#test_link').click()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed after link click')
dropdown.remove()
})

})

0 comments on commit 6952756

Please sign in to comment.