Repository navigation
Media Editor: Prevent shortcuts modal Escape from opening discard dialog - #81775
yogeshbhutkar wants to merge 2 commits into
Conversation
45f3cfb to
961525e
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| }; | ||
|
|
||
| const handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => { | ||
| // Ignore events from nested components rendered outside this modal's DOM, | ||
| // such as portaled dialogs. | ||
| if ( ! event.currentTarget.contains( event.target as Node ) ) { | ||
| return; | ||
| } | ||
|
|
||
| const isUndoShortcut = isKeyboardEvent.primary( event, 'z' ); | ||
| const isRedoShortcut = | ||
| isKeyboardEvent.primaryShift( event, 'z' ) || |
There was a problem hiding this comment.
Nice fix, confirmed it resolves the issue locally.
One question on the approach: would event.defaultPrevented work here instead?
Modal already guards its own Escape handling that way (handleEscapeKeyDown), and since the nested shortcuts modal calls preventDefault() before this handler runs, the keystroke is already flagged as consumed by the time it gets here.
#78433 solves a similar issue, might be a useful reference.
|
Closing in favor of #81785 |
What, Why, and How?
Closes #81774
Key events from portaled Media Editor dialogs could also reach the editor behind them. This caused Escape in Keyboard shortcuts to open the discard dialog. The editor's key handler now scopes key events whose targets are within its DOM subtree.
Testing Instructions
Cropin the block toolbar.Screencast
PR.mov
Use of AI Tools
AI Usage: Yes
Model: GPT-5.6 Sol with Codex
Role: Used for scoping the issue and internal code review.