Usually all buttons on a dialog, and the esc key, close the dialog and returns you to the last non-dialog screen, if any. In case the dialog was initially opened from the pause menu, this means you return to the pause menu.
You can override this by setting after_action to none. This will not close the dialog when pressing any of the buttons, including the one created for the exit_action. However, I expected the esc key to behave the same way as the button for exit_action, which it currently does not.
I have also attached a video to illustrate and explain this issue, explaining what the issue is and why it is an issue for custom content (enable sound):
[embedCard]Steps to Reproduce
Download [mediaInline]
Install it in a world
If the world is open, close and re-open it, otherwise just open it
Pause the game
Click “Custom Options”
Click “Settings”
Click “Automatic Game End”
Click “Back”
Click “Automatic Game End” again
Press
escon your keyboard
Observed Behavior
esc closes the dialog and brings you back to the pause menu, ignoring after_action.
Expected Behavior
Both the back button and the esc button behave the same and respect the after_action argument.
MC-298457 confirms that the button of exit_action is in fact not supposed to close the dialog, and I expected esc to also follow this same logic.
There literally is an option for any dialog called can_close_with_escape. If you want to be unable to close the dialog with ESC, set it to false.
On the other hand, when after_action is set to close, any action, including click events etc. will close the dialog, which is often not wanted. In that case, only with the options provided (as is) it is possible to do a dialog which only closes by ESC (and other selected means).