mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 00:24:03 +02:00
Carousel - Do not prevent on keydown for input and textarea
This commit is contained in:
@@ -229,11 +229,10 @@ const Carousel = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_keydown(event) {
|
_keydown(event) {
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
if (/input|textarea/i.test(event.target.tagName)) {
|
if (/input|textarea/i.test(event.target.tagName)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
switch (event.which) {
|
switch (event.which) {
|
||||||
case 37: this.prev(); break
|
case 37: this.prev(); break
|
||||||
|
@@ -759,4 +759,36 @@ $(function () {
|
|||||||
.bootstrapCarousel('prev')
|
.bootstrapCarousel('prev')
|
||||||
assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide')
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user