twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.84k stars 78.87k forks source link

Escape key is totally supressed in modal when data-bs-keyboard is false #40801

Closed raysuelzer closed 1 month ago

raysuelzer commented 2 months ago

Prerequisites

Describe the issue

I have a typeahead which appears within a modal. Pressing the escape key should close the typeahead results. However, it appears bootstrap is completely supressing the escape key event so any bindings to the escape key used within a modal are never triggered.

You can see in the console.log that all keys except for escape key are correctly picked up by the event listener.

Reduced test cases

Minimal reproduction: https://codepen.io/raysuelzer/pen/mdZvzKm

What operating system(s) are you seeing the problem on?

Windows, macOS, Linux

What browser(s) are you seeing the problem on?

Chrome, Safari, Firefox, Microsoft Edge, Opera

What version of Bootstrap are you using?

v5.3.3

raysuelzer commented 2 months ago

I believe this line of code is the problem, it appears to be preventing the escape key from doing anything. I feel like a better solution would be to not prevent default escape key behavior, or at least add an option to opt out of it preventing the use of the escape key within a modal.

https://github.com/twbs/bootstrap/blob/main/js/src/modal.js#L266

Edit:

Also important to note is if you change to listen for keydown event the escape key is not supressed on elements within the modal, but keyup on escape is completely intercepted.

julien-deramond commented 2 months ago

Thanks for reporting an issue @raysuelzer

I quickly created an example replicating your modal setup, adding a basic Bootstrap dropdown example along with a custom typeahead, which you can check out here: CodePen Example.

Based on your description:

I have a typeahead which appears within a modal. Pressing the escape key should close the typeahead results. However, it appears bootstrap is completely supressing the escape key event so any bindings to the escape key used within a modal are never triggered.

I'm not entirely sure I see the difference between our setups. Could you clarify the specific scenario where the escape key isn't behaving as expected in your case?

It's possible I may have misunderstood the issue, so any additional details would help :)

github-actions[bot] commented 1 month ago

As the issue was labeled with awaiting-reply, but there has been no response in 14 days, this issue will be closed. If you have any questions, you can comment/reply.