mirror of https://github.com/twbs/bootstrap.git
				
				
				
			Fix #16072: Clicking into input field within dropdown no longer closes the dropdown
Closes #16073 by merging it
This commit is contained in:
		
							parent
							
								
									74ae498800
								
							
						
					
					
						commit
						fa9d28b634
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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') | ||||
|   }) | ||||
| }) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue