Typically, when you hit the ESC key, that closes a modal. But if this modal contains a form that the user needs to fill out, that would mean that hitting ESC (sometimes, inadvertently) closes the modal and they lose all the information they just provided in the form.

So that said, what's the best way to go about it? Would it be better to:

  • Make sure the modal doesn't go away if the user hits the ESC key
  • Allow the use of ESC, but if the user hits ESC, we prompt them that they might lose the information they just typed in
  • Please only prompt if the user entered information. – Nash Feb 12 at 22:44
  • Typically? I think most users typically don't use the escape key for anything much less closing modals. – Rob Feb 13 at 13:54
  • We have Escape to close modals in the application I design for. In some cases the modals contain forms. We do not prompt but simply close the modal straight away. Never had any negative comments about it. The forms we have are fairly short though. I would reconsider if they are longer forms. – Martyn Feb 16 at 20:00

I would allow for the prompt, warning them they might lose information. Treat it like if someone is trying to leave the page after entering text into a form. You can use Javascript to flash an alert.

  • 1
    This. And perhaps allow the storage of the current data so that the next time they open the modal (if in the same session) it is already filled with the previously entered information. – Adriano Feb 13 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.