Bootstrap: Modal won't close when you click outside if modal-dialog is inside <form>

Created on 21 Aug 2018  路  6Comments  路  Source: twbs/bootstrap

Description
Modal won't close if you click outside to the left & right of the modal. It will however if you click above and below it.

Test Case
https://codepen.io/luckyruby/pen/xaxBNV

Tested on Mac OS 10.13.6 on Safari 11.1.2, Firefox 61.0.2, and Chrome 68.0.3440.106.

Most helpful comment

Why don't just add the form inside the .modal-content?

All 6 comments

Why don't just add the form inside the .modal-content?

yes it works after adding

tag inside div.modal-content

@MartijnCuppens Yea, that's ultimately what I did to get it working. It seems odd that the form placement would mess up the modal in that way. I don't recall seeing the issue in v3.

@luckyruby, You did something that you weren't supposed to be doing (placing a form as a child of the .modal), it worked in v3, but due some refactoring in v4 this now gives some issues.

Modals in v4 use pointer-events which allows you to click trough elements, if you place an element like a form in the .modal, you click on the form and not on the modal itself (where a eventListener is attached to to close the modal). Another option was to add pointer-events: none; to the form, but I wouldn't recommend that because Bootstrap 4 always assumes that .modal-dialog is a child of the .modal and this might cause some troubles in the future.

Your modal content should be in .modal-content as explained by @MartijnCuppens

@MartijnCuppens Appreciate the explanation. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iklementiev picture iklementiev  路  3Comments

devfrey picture devfrey  路  3Comments

ghost picture ghost  路  3Comments

leomao10 picture leomao10  路  3Comments

eddywashere picture eddywashere  路  3Comments