Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
3cbbc70d
Commit
3cbbc70d
authored
Jun 06, 2014
by
Chris Rebert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13627 from twbs/maybe-fix-12364
Hopefully fixes trigger focus restoration on modal close
parents
a8641b4d
b058c018
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
js/modal.js
js/modal.js
+6
-3
js/tests/unit/modal.js
js/tests/unit/modal.js
+51
-0
No files found.
js/modal.js
View file @
3cbbc70d
...
@@ -268,10 +268,13 @@
...
@@ -268,10 +268,13 @@
if
(
$this
.
is
(
'
a
'
))
e
.
preventDefault
()
if
(
$this
.
is
(
'
a
'
))
e
.
preventDefault
()
Plugin
.
call
(
$target
,
option
,
this
)
$target
.
one
(
'
show.bs.modal
'
,
function
(
showEvent
)
{
$target
.
one
(
'
hide.bs.modal
'
,
function
()
{
if
(
showEvent
.
isDefaultPrevented
())
return
// only register focus restorer if modal will actually get shown
$target
.
one
(
'
hidden.bs.modal
'
,
function
()
{
$this
.
is
(
'
:visible
'
)
&&
$this
.
trigger
(
'
focus
'
)
$this
.
is
(
'
:visible
'
)
&&
$this
.
trigger
(
'
focus
'
)
})
})
})
})
Plugin
.
call
(
$target
,
option
,
this
)
})
}(
jQuery
);
}(
jQuery
);
js/tests/unit/modal.js
View file @
3cbbc70d
...
@@ -201,4 +201,55 @@ $(function () {
...
@@ -201,4 +201,55 @@ $(function () {
div
.
remove
()
div
.
remove
()
})
})
test
(
'
should restore focus to toggling element when modal is hidden after having been opened via data-api
'
,
function
()
{
stop
()
$
.
support
.
transition
=
false
var
toggleBtn
=
$
(
'
<button data-toggle="modal" data-target="#modal-test">Launch modal</button>
'
).
appendTo
(
'
#qunit-fixture
'
)
var
div
=
$
(
'
<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>
'
)
div
.
on
(
'
hidden.bs.modal
'
,
function
()
{
window
.
setTimeout
(
function
()
{
// give the focus restoration callback a chance to run
equal
(
document
.
activeElement
,
toggleBtn
[
0
],
'
toggling element is once again focused
'
)
div
.
remove
()
toggleBtn
.
remove
()
start
()
},
0
)
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
'
#close
'
).
click
()
})
.
appendTo
(
'
#qunit-fixture
'
)
toggleBtn
.
click
()
})
test
(
'
should not restore focus to toggling element if the associated show event gets prevented
'
,
function
()
{
stop
()
$
.
support
.
transition
=
false
var
toggleBtn
=
$
(
'
<button data-toggle="modal" data-target="#modal-test">Launch modal</button>
'
).
appendTo
(
'
#qunit-fixture
'
)
var
otherBtn
=
$
(
'
<button id="other-btn">Golden boy</button>
'
).
appendTo
(
'
#qunit-fixture
'
)
var
div
=
$
(
'
<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>
'
)
div
.
one
(
'
show.bs.modal
'
,
function
(
e
)
{
e
.
preventDefault
()
otherBtn
.
focus
()
window
.
setTimeout
(
function
()
{
// give the focus event from the previous line a chance to run
div
.
bootstrapModal
(
'
show
'
)
},
0
)
})
.
on
(
'
hidden.bs.modal
'
,
function
()
{
window
.
setTimeout
(
function
()
{
// give the focus restoration callback a chance to run (except it shouldn't run in this case)
equal
(
document
.
activeElement
,
otherBtn
[
0
],
'
show was prevented, so focus should not have been restored to toggling element
'
)
div
.
remove
()
toggleBtn
.
remove
()
otherBtn
.
remove
()
start
()
},
0
)
})
.
on
(
'
shown.bs.modal
'
,
function
()
{
$
(
'
#close
'
).
click
()
})
.
appendTo
(
'
#qunit-fixture
'
)
toggleBtn
.
click
()
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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