diff --git a/js/src/carousel.js b/js/src/carousel.js index 34cab4391d13..0ed4b7b5fe34 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -229,11 +229,10 @@ const Carousel = (($) => { } _keydown(event) { - event.preventDefault() - if (/input|textarea/i.test(event.target.tagName)) { return } + event.preventDefault() switch (event.which) { case 37: this.prev(); break diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index d6d0186e15d0..8fac87d9884e 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -759,4 +759,36 @@ $(function () { .bootstrapCarousel('prev') assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide') }) + + QUnit.test('should not prevent keydown for inputs and textareas', function (assert) { + assert.expect(2) + var templateHTML = '' + var $template = $(templateHTML) + var done = assert.async() + $template.appendTo('#qunit-fixture') + var $inputText = $template.find('#inputText') + var $textArea = $template.find('#txtArea') + $template.bootstrapCarousel() + + var eventKeyDown = $.Event('keydown', { which: 65 }) // 65 for "a" + $inputText.on('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + }) + $inputText.trigger(eventKeyDown) + + $textArea.on('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + done() + }) + $textArea.trigger(eventKeyDown) + }) })