Editor: Fix keyboard activation of the template actions preview#78641
Editor: Fix keyboard activation of the template actions preview#78641ciampo wants to merge 2 commits into
Conversation
|
Size Change: +59 B (0%) Total Size: 8.13 MB 📦 View Changed
ℹ️ View Unchanged
|
The "Change template" preview in the block-theme template actions panel used `onKeyPress` to open the swap modal. `onKeyPress` is a deprecated React event that fires on any character key while the role="button" preview is focused, so e.g. pressing any letter key would open the modal. Replace it with `onKeyDown` that only opens the modal on Enter / Space, matching the implicit native button activation keys and the existing pattern used in `default-block-appender`. Flagged as an accessibility follow-up in #78466.
0a43741 to
788dbbb
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. |
|
Flaky tests detected in 788dbbb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26416082790
|
What?
Replace the deprecated
onKeyPresshandler on the "Change template" preview in the block-theme template actions panel with a key-checkedonKeyDownhandler, so that the swap modal only opens on Enter / Space instead of on any character key.Why?
Follow-up to #78466 — see this thread.
Background
onKeyPressis deprecated in React and fires for any key that produces a character. On the<div role="button" tabIndex={ 0 }>preview that wraps the template thumbnail, that means pressing any character key while the preview is focused opens the swap modal — not just the standard Enter / Space button activation keys.How?
ENTERandSPACEfrom@wordpress/keycodes.onKeyPress={ () => setIsSwapModalOpen( true ) }with anonKeyDownhandler that gates onevent.keyCode === ENTER || event.keyCode === SPACEand callsevent.preventDefault()before opening the modal (matches the existing pattern inpackages/block-editor/src/components/default-block-appender/index.js).No visual change. The
<Tooltip.Root>/<Tooltip.Trigger>composition,role,tabIndex,aria-label, andonClickare all untouched.Testing Instructions
hasSwapTargetstruthy).Testing Instructions for Keyboard
Covered above — points 3–5 are the keyboard regression / fix surface.
Screenshots or screencast
No visual change.
Use of AI Tools
This PR was authored with assistance from Cursor (Claude). All changes were reviewed by a human before being committed.