Block Keyboard Shortcuts Are Declarable Now

Gutenberg 23.9 turns variation and transform shortcuts into something you register rather than something core hardcodes. Twenty minutes of work on the blocks people use all day.

  • 3 mins read
  • 1 View
Block Keyboard Shortcuts Are Declarable Now

For years keyboard shortcuts in the block editor were a closed shop. Core blocks had them because core wired them up inside a private component, and if you wanted the same thing in your own block you reimplemented the key handling or went without. Most of us went without.

Gutenberg 23.9 opens it up. A block variation can now carry a shortcut, and a transform can carry shortcuts, declared in the block registration alongside everything else.

Why bother

Registering through the API rather than rolling your own key handler buys you two things that are annoying to build. Your binding lands in the editor's shortcut help panel, which is the difference between a feature people use and a feature documented in a readme nobody opens. And it respects the platform modifier conventions, so you are not writing a Cmd-versus-Ctrl branch and getting it subtly wrong on Linux.

The other reason is that the old approach sat on a private export. Private in the WordPress packages sense means it can move or disappear between releases with no deprecation notice, so anything built on it was load-bearing code on a foundation nobody had promised to keep.

Which blocks earn one

Not all of them. A shortcut on a block somebody inserts twice a year is noise in the help panel and one more combination competing for keys. The blocks worth it are the ones an editor reaches for over and over inside a single session: layout primitives inserted dozens of times while building a page, or a pair of variations somebody flips between constantly.

My rough test is whether a person building a page with your block would reach for the mouse more than about once a minute to do the same repeated thing. If so, bind it.

Choosing keys without breaking something

The editor already claims a long list of combinations and the browser claims more. Everything you bind competes with both, and when you lose, your user presses a key and gets a result they did not ask for.

Read the editor's existing shortcut list properly before you settle on anything. Prefer a letter with some mnemonic connection to what the shortcut does. Stay away from anything shadowing a browser default, which in practice rules out most of the obvious single-modifier combinations.

The change is small and self-contained, which is exactly why it is worth doing in the same week you read about it. It touches your block registration and nothing else. Leave it six months and it will be sitting in a backlog next to things that need actual thought, losing every time.