aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-06-06 15:59:17 -0700
committerChris Rebert <[email protected]>2014-06-06 15:59:17 -0700
commit3cbbc70d55aeff62f5b53929b60439f7cc960e19 (patch)
treee75545513a085935613f0dac6da15f31adec19e7 /js/tests
parenta8641b4db779da385782275b49abb796f64a413c (diff)
parentb058c018eba059811f0c26074b813b843cfb5cb7 (diff)
downloadbootstrap-3cbbc70d55aeff62f5b53929b60439f7cc960e19.tar.xz
bootstrap-3cbbc70d55aeff62f5b53929b60439f7cc960e19.zip
Merge pull request #13627 from twbs/maybe-fix-12364
Hopefully fixes trigger focus restoration on modal close
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/modal.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index d8bef3ea1..667de547a 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -201,4 +201,55 @@ $(function () {
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()
+ })
})