diff --git a/js/src/modal.js b/js/src/modal.js
index d4436bf4fe..2dc7e75d98 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -145,7 +145,7 @@ class Modal extends BaseComponent {
}
hide(event) {
- if (event) {
+ if (event && ['A', 'AREA'].includes(event.target.tagName)) {
event.preventDefault()
}
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js
index 79f3c4845b..799152e64c 100644
--- a/js/tests/unit/modal.spec.js
+++ b/js/tests/unit/modal.spec.js
@@ -988,6 +988,60 @@ describe('Modal', () => {
trigger.click()
})
+ it('should not prevent default when a click occurred on data-bs-dismiss="modal" where tagName is DIFFERENT than or ', done => {
+ fixtureEl.innerHTML = [
+ '',
+ '
',
+ ' ',
+ '
',
+ '
'
+ ].join('')
+
+ const modalEl = fixtureEl.querySelector('.modal')
+ const btnClose = fixtureEl.querySelector('button[data-bs-dismiss="modal"]')
+ const modal = new Modal(modalEl)
+
+ spyOn(Event.prototype, 'preventDefault').and.callThrough()
+
+ modalEl.addEventListener('shown.bs.modal', () => {
+ btnClose.click()
+ })
+
+ modalEl.addEventListener('hidden.bs.modal', () => {
+ expect(Event.prototype.preventDefault).not.toHaveBeenCalled()
+ done()
+ })
+
+ modal.show()
+ })
+
+ it('should prevent default when a click occurred on data-bs-dismiss="modal" where tagName is or ', done => {
+ fixtureEl.innerHTML = [
+ ''
+ ].join('')
+
+ const modalEl = fixtureEl.querySelector('.modal')
+ const btnClose = fixtureEl.querySelector('a[data-bs-dismiss="modal"]')
+ const modal = new Modal(modalEl)
+
+ spyOn(Event.prototype, 'preventDefault').and.callThrough()
+
+ modalEl.addEventListener('shown.bs.modal', () => {
+ btnClose.click()
+ })
+
+ modalEl.addEventListener('hidden.bs.modal', () => {
+ expect(Event.prototype.preventDefault).toHaveBeenCalled()
+ done()
+ })
+
+ modal.show()
+ })
+
it('should not focus the trigger if the modal is not visible', done => {
fixtureEl.innerHTML = [
'',