diff --git a/js/src/collapse.js b/js/src/collapse.js index 13c44502ca..6f09fcadd8 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -363,7 +363,9 @@ const Collapse = (($) => { */ $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - event.preventDefault() + if (/input|textarea/i.test(event.target.tagName)) { + event.preventDefault() + } const target = Collapse._getTargetFromElement(this) const data = $(target).data(DATA_KEY) diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index a7bcaad9cd..01bc5adb96 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -513,4 +513,20 @@ $(function () { }) $target.trigger($.Event('click')) }) + + QUnit.test('should not prevent event for input', function (assert) { + assert.expect(2) + var done = assert.async() + var $target = $('').appendTo('#qunit-fixture') + + $('
') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok($target.attr('aria-expanded') === 'true') + assert.ok($target.prop('checked')) + done() + }) + + $target.trigger($.Event('click')) + }) })