Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2022-09-07 11:56:33 +0300
committerGitHub <noreply@github.com>2022-09-07 11:56:33 +0300
commit23fb7a79156d1ea4ce2ab5713debbbc251b4e22f (patch)
tree47960992a48a2c16ff3e872e2636140fd84f28cb
parent949456984aa21536afd35eddf7ea38b3648830a3 (diff)
Fix modal event-listeners during dismiss click (#36863)
ref: #36855
-rw-r--r--.bundlewatch.config.json4
-rw-r--r--js/src/modal.js28
-rw-r--r--js/tests/unit/modal.spec.js4
3 files changed, 22 insertions, 14 deletions
diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json
index 41cea2119d..4c9acc990e 100644
--- a/.bundlewatch.config.json
+++ b/.bundlewatch.config.json
@@ -34,7 +34,7 @@
},
{
"path": "./dist/js/bootstrap.bundle.js",
- "maxSize": "43.0 kB"
+ "maxSize": "43.25 kB"
},
{
"path": "./dist/js/bootstrap.bundle.min.js",
@@ -50,7 +50,7 @@
},
{
"path": "./dist/js/bootstrap.js",
- "maxSize": "28.5 kB"
+ "maxSize": "28.75 kB"
},
{
"path": "./dist/js/bootstrap.min.js",
diff --git a/js/src/modal.js b/js/src/modal.js
index 3e990e7cc9..1f281e2a3d 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -30,6 +30,7 @@ const EVENT_HIDDEN = `hidden${EVENT_KEY}`
const EVENT_SHOW = `show${EVENT_KEY}`
const EVENT_SHOWN = `shown${EVENT_KEY}`
const EVENT_RESIZE = `resize${EVENT_KEY}`
+const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY}`
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
@@ -222,18 +223,21 @@ class Modal extends BaseComponent {
})
EventHandler.on(this._element, EVENT_MOUSEDOWN_DISMISS, event => {
- if (event.target !== event.currentTarget) { // click is inside modal-dialog
- return
- }
-
- if (this._config.backdrop === 'static') {
- this._triggerBackdropTransition()
- return
- }
-
- if (this._config.backdrop) {
- this.hide()
- }
+ EventHandler.one(this._element, EVENT_CLICK_DISMISS, event2 => {
+ // a bad trick to segregate clicks that may start inside dialog but end outside, and avoid listen to scrollbar clicks
+ if (this._dialog.contains(event.target) || this._dialog.contains(event2.target)) {
+ return
+ }
+
+ if (this._config.backdrop === 'static') {
+ this._triggerBackdropTransition()
+ return
+ }
+
+ if (this._config.backdrop) {
+ this.hide()
+ }
+ })
})
}
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js
index 1bdf4e66ad..e774fc4e8e 100644
--- a/js/tests/unit/modal.spec.js
+++ b/js/tests/unit/modal.spec.js
@@ -644,7 +644,9 @@ describe('Modal', () => {
const mouseDown = createEvent('mousedown')
modalEl.dispatchEvent(mouseDown)
+ modalEl.click()
modalEl.dispatchEvent(mouseDown)
+ modalEl.click()
setTimeout(() => {
expect(spy).toHaveBeenCalledTimes(1)
@@ -719,9 +721,11 @@ describe('Modal', () => {
const mouseDown = createEvent('mousedown')
dialogEl.dispatchEvent(mouseDown)
+ modalEl.click()
expect(spy).not.toHaveBeenCalled()
modalEl.dispatchEvent(mouseDown)
+ modalEl.click()
expect(spy).toHaveBeenCalled()
resolve()
})