Skip to content

Custom keyboard shortcut #51526

Answered by devfle
abhi3315 asked this question in Q&A
Jun 15, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @abhi3315,

you could use the RichTextShortcut component from the block-editor package inside of your format types edit function.

The component: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/rich-text/shortcut.js#L12

Example from core/bold format type: https://github.com/WordPress/gutenberg/blob/trunk/packages/format-library/src/bold/index.js#L33

Code-Example:

import { registerFormatType, toggleFormat } from '@wordpress/rich-text';
import { RichTextToolbarButton, RichTextShortcut } from '@wordpress/block-editor';

const MyCustomButton = ( { isActive, onChange, value } ) => {

    const onToggle = () => {
        onChange(
             toggleFormat( 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@abhi3315
Comment options

Answer selected by abhi3315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants