Skip to content

Commit

Permalink
Merge pull request #19058 from Johann-S/carouselInput
Browse files Browse the repository at this point in the history
Carousel - Do not prevent on keydown for input and textarea
  • Loading branch information
mdo authored Nov 26, 2016
2 parents bb6c197 + 14ec4fd commit ce31f54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ const Carousel = (($) => {
}

_keydown(event) {
event.preventDefault()

if (/input|textarea/i.test(event.target.tagName)) {
return
}
event.preventDefault()

switch (event.which) {
case ARROW_LEFT_KEYCODE:
Expand Down
32 changes: 32 additions & 0 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div id="myCarousel" class="carousel" data-interval="false">'
+ '<div class="carousel-inner">'
+ '<div id="first" class="carousel-item">'
+ '<input type="text" id="inputText" />'
+ '</div>'
+ '<div id="second" class="carousel-item active">'
+ '<textarea id="txtArea"></textarea>'
+ '</div>'
+ '</div>'
+ '</div>'
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)
})
})

0 comments on commit ce31f54

Please sign in to comment.