How to prevent Bootstrap 5 modal from closing using `esc` key?

I’ve created a Bootstrap 5 modal and am using nocloseonclick="true". However, hitting the esc button closes this modal. I tried to prevent this action by using data-bs-keyboard="false" but this was unsuccessful. Removing is="dmx-bs5-modal" seems to resolve this, but then I lose other functionality.

Are data-bs-keyboard="false" and is="dmx-bs5-modal" incompatible? Is this a bug?

image

2 Likes

Hi JT, welcome back!

If you select both No Close On Click and No Keyboard properties for the modal, it will stop the modal to close when esc button is clicked or user clicks anywhere on the screen outside the modal.

2 Likes

🤦 Feel very silly for having missed that - thank you!

1 Like