Blazored / Modal

A powerful and customizable modal implementation for Blazor applications.
https://blazored.github.io/Modal/
MIT License
772 stars 185 forks source link

Allowing user to press ESC to exit modal window. #512

Open davem7714 opened 1 year ago

davem7714 commented 1 year ago

It would really be nice if instead of the user having to click the "X" or somewhere outside of the window to close it. If we could trap the user pressing the ESC key and then execute the onclick of a button in the modal or just call the method that will close the form with a "cancel" that would be great.

emilg commented 1 year ago

+1, this would of course have been preferable as default behavior.

What you can do is programmatically listen for whether ESC is pressed and whether the modal is open. -> https://blazored.github.io/Modal/usage/closing-programmatically

davem7714 commented 1 year ago

I understand how to close the modal programmatically but I'm not clear how to listen for the ESC key being pressed. Any links that discuss this would be helpful. I'll start researching. Thanks!

NeskireDK commented 1 year ago

I too have yet to find a nice way to listen for ESC key, and close ANY modal open. I know there was an attempt to make ESC work for closing, but was later removed due to conflict.