aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Sharma <[email protected]>2021-01-14 01:29:47 +0530
committerGitHub <[email protected]>2021-01-13 21:59:47 +0200
commite34481b6eb5c7b9db35911f428cb96af6947741e (patch)
treee3675a4b136a1202e3211e4f04e47991e4af58a2
parentd21fb9b6276cf023f99286c2e39498990ff69895 (diff)
downloadbootstrap-e34481b6eb5c7b9db35911f428cb96af6947741e.tar.xz
bootstrap-e34481b6eb5c7b9db35911f428cb96af6947741e.zip
Fix toggling modal when clicking on `data-bs-toggle="modal"` (#32691)
Co-authored-by: XhmikosR <[email protected]>
-rw-r--r--js/src/modal.js2
-rw-r--r--js/tests/unit/modal.spec.js11
2 files changed, 11 insertions, 2 deletions
diff --git a/js/src/modal.js b/js/src/modal.js
index 87c22943a..fe1b5a4c6 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -590,7 +590,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
data = new Modal(target, config)
}
- data.show(this)
+ data.toggle(this)
})
/**
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js
index f645e9892..a867bec9b 100644
--- a/js/tests/unit/modal.spec.js
+++ b/js/tests/unit/modal.spec.js
@@ -870,7 +870,7 @@ describe('Modal', () => {
})
describe('data-api', () => {
- it('should open modal', done => {
+ it('should toggle modal', done => {
fixtureEl.innerHTML = [
'<button type="button" data-bs-toggle="modal" data-bs-target="#exampleModal"></button>',
'<div id="exampleModal" class="modal"><div class="modal-dialog"></div></div>'
@@ -885,6 +885,15 @@ describe('Modal', () => {
expect(modalEl.getAttribute('aria-hidden')).toEqual(null)
expect(modalEl.style.display).toEqual('block')
expect(document.querySelector('.modal-backdrop')).toBeDefined()
+ setTimeout(() => trigger.click(), 10)
+ })
+
+ modalEl.addEventListener('hidden.bs.modal', () => {
+ expect(modalEl.getAttribute('aria-modal')).toEqual(null)
+ expect(modalEl.getAttribute('role')).toEqual(null)
+ expect(modalEl.getAttribute('aria-hidden')).toEqual('true')
+ expect(modalEl.style.display).toEqual('none')
+ expect(document.querySelector('.modal-backdrop')).toEqual(null)
done()
})