Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
21644321
Commit
21644321
authored
10 years ago
by
Chris Rebert
Browse files
Options
Download
Plain Diff
Merge pull request #14993 from twbs/fix-14991
Have Carousel ignore keyboard events from <input>s or <textarea>s
parents
db90ff6d
469dc3ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/carousel.js
+1
-0
js/carousel.js
js/tests/unit/carousel.js
+42
-0
js/tests/unit/carousel.js
with
43 additions
and
0 deletions
+43
-0
js/carousel.js
+
1
-
0
View file @
21644321
...
...
@@ -42,6 +42,7 @@
}
Carousel
.
prototype
.
keydown
=
function
(
e
)
{
if
(
/input|textarea/i
.
test
(
e
.
target
.
tagName
))
return
switch
(
e
.
which
)
{
case
37
:
this
.
prev
();
break
case
39
:
this
.
next
();
break
...
...
This diff is collapsed.
Click to expand it.
js/tests/unit/carousel.js
+
42
-
0
View file @
21644321
...
...
@@ -478,6 +478,48 @@ $(function () {
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after left arrow press
'
)
})
test
(
'
should ignore keyboard events within <input>s and <textarea>s
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false">
'
+
'
<div class="carousel-inner">
'
+
'
<div id="first" class="item active">
'
+
'
<img alt="">
'
+
'
<input type="text" id="in-put">
'
+
'
<textarea id="text-area"></textarea>
'
+
'
</div>
'
+
'
<div id="second" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="third" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
</div>
'
+
'
</div>
'
var
$template
=
$
(
templateHTML
)
var
$input
=
$template
.
find
(
'
#in-put
'
)
var
$textarea
=
$template
.
find
(
'
#text-area
'
)
strictEqual
(
$input
.
length
,
1
,
'
found <input>
'
)
strictEqual
(
$textarea
.
length
,
1
,
'
found <textarea>
'
)
$template
.
bootstrapCarousel
()
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item active
'
)
$input
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
39
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after right arrow press in <input>
'
)
$input
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
37
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after left arrow press in <input>
'
)
$textarea
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
39
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after right arrow press in <textarea>
'
)
$textarea
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
37
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after left arrow press in <textarea>
'
)
})
test
(
'
should only add mouseenter and mouseleave listeners when not on mobile
'
,
function
()
{
var
isMobile
=
'
ontouchstart
'
in
document
.
documentElement
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">
'
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets