From bbb0d2b573c28793358be66a1c05f2d68ded4db6 Mon Sep 17 00:00:00 2001 From: Pierre-Denis Vanduynslager Date: Mon, 2 Jan 2017 17:44:27 -0500 Subject: Dropdown: close menu when focusing outside element (#21375) * Close dropdown menu when focusing an outside element * Update unit test to new markup --- js/tests/unit/dropdown.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 53455c2a6..9a34fc0c9 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -192,6 +192,30 @@ $(function () { assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') }) + QUnit.test('should remove "show" class if body is focused', function (assert) { + assert.expect(2) + var dropdownHTML = '
' + + '' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + $(document.body).trigger('focusin') + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + }) + QUnit.test('should remove "show" class if body is clicked, with multiple dropdowns', function (assert) { assert.expect(7) var dropdownHTML = '