Only close modal if escape was hit with keydown; fixes #13929

See #13929 and also #13855.

/cc @fat