diff --git a/js/src/modal.js b/js/src/modal.js
index 1ea630c415..399adc4c12 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -169,12 +169,6 @@ const Modal = (() => {
return
}
- const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)
-
- if (transition) {
- this._isTransitioning = true
- }
-
const hideEvent = $.Event(Event.HIDE)
$(this._element).trigger(hideEvent)
@@ -185,6 +179,12 @@ const Modal = (() => {
this._isShown = false
+ const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)
+
+ if (transition) {
+ this._isTransitioning = true
+ }
+
this._setEscapeEvent()
this._setResizeEvent()
diff --git a/js/tests/visual/modal.html b/js/tests/visual/modal.html
index 6e9f0f7107..fcc96035bd 100644
--- a/js/tests/visual/modal.html
+++ b/js/tests/visual/modal.html
@@ -171,6 +171,12 @@
+
+
+
+
@@ -203,6 +209,22 @@
$('#firefoxModal').on('focus', reportFirefoxTestResult.bind(false))
$('#ff-bug-input').on('focus', reportFirefoxTestResult.bind(true))
})
+
+ $('#btnPreventModal').on('click', function () {
+ $('#firefoxModal').one('shown.bs.modal', function () {
+ $(this).modal('hide')
+ })
+ .one('hide.bs.modal', function (event) {
+ event.preventDefault()
+ if ($(this).data('bs.modal')._isTransitioning) {
+ console.error('Modal plugin should not set _isTransitioning when hide event is prevented')
+ } else {
+ console.log('Test passed')
+ $(this).modal('hide') // work as expected
+ }
+ })
+ .modal('show')
+ })
})