docs: clarify <dialog> Esc close request behavior - #42975
Conversation
Corrects the explanation of how a modal `<dialog>` is dismissed when the user presses the Esc key. It clarifies the sequence of events, `cancel` followed by `close`, if not prevented, and explains that no explicit return value is provided in this case leaving `dialog.returnValue` as an empty string. Fixes mdn#41656
|
Preview URLs (1 page) (comment last updated: 2026-02-02 14:19:26) |
chrisdavidmills
left a comment
There was a problem hiding this comment.
Hi @ross-u, and thank you for your work in fixing this issue.
I've provided a suggestion to tighten up the text a bit, however, I think there is a bigger concern here — the behavior works as described, but only in Chrome.
If you try it in Firefox and Safari, the returnValue is set to an empty string when you press Esc, only if you haven't already selected a value from the dialog dropdown or pressed the dialog "Cancel" button. If you've done one of those two things, then on subsequent presses of the "Show the dialog" button, when you press the Esc key, the returnValue remains set to the previously selected dialog value.
I don't know if this is old behavior, and Chrome's behavior has been updated to spec behavior, or something else. But it is worth investigating this and thinking about how to communicate it in the doc.
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
|
Asked Codex to investigate this. Firefox’s behavior is correct for the The specification separates two things:
For example, after Chromium’s implementation explains the discrepancy. Its constructor initializes The [PR](#42975) therefore fixes the incorrect assertion that
Any note about Chrome resetting the value should describe it as a browser discrepancy, rather than the specified behavior. |
Description
Corrects the explanation of how a modal
<dialog>is dismissed when the user presses the Esc key. It clarifies the sequence of events,cancelfollowed byclose, if not prevented, and explains that no explicit return value is provided in this case leavingdialog.returnValueas an empty string.Motivation
I would like to help and contribute to the MDN documentation and thought to give it a shot with this small issue first. 🙂
Additional details
Related issues and pull requests
Fixes #41656