diff options
| author | Emmanuel Bourgerie <[email protected]> | 2015-03-16 13:33:42 +0000 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2015-03-21 16:00:15 -0700 |
| commit | fa9d28b634dbcf057778cd755bc52aedebffbe22 (patch) | |
| tree | 0f3af5490e84be3f4545db38a5a2fac73da57d14 | |
| parent | 74ae498800fdd806b4a7edc0d6157c915911f989 (diff) | |
| download | bootstrap-fa9d28b634dbcf057778cd755bc52aedebffbe22.tar.xz bootstrap-fa9d28b634dbcf057778cd755bc52aedebffbe22.zip | |
Fix #16072: Clicking into input field within dropdown no longer closes the dropdown
Closes #16073 by merging it
| -rw-r--r-- | js/dropdown.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/dropdown.js | 38 |
2 files changed, 40 insertions, 0 deletions
diff --git a/js/dropdown.js b/js/dropdown.js index 5e6cefe84..1fbf74a31 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -99,6 +99,8 @@ if (!$parent.hasClass('open')) return + if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return + $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) if (e.isDefaultPrevented()) return diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 40c428682..e0d1df970 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -350,4 +350,42 @@ $(function () { assert.ok(!$(document.activeElement).parent().is('.disabled'), '.disabled is not focused') }) + + QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) { + assert.expect(1) + var dropdownHTML = '<div class="btn-group">' + + '<button type="button" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><input id="textField" type="text" /></li>' + + '</ul>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + $('#textField').trigger('click') + + assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open') + }) + + QUnit.test('should not close the dropdown if the user clicks on a textarea', function (assert) { + assert.expect(1) + var dropdownHTML = '<div class="btn-group">' + + '<button type="button" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><textarea id="textArea"></textarea></li>' + + '</ul>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + $('#textArea').trigger('click') + + assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open') + }) }) |
