Skip to content

Add custom formatting to custom block only #14104

@gregbia

Description

@gregbia

I'm adding a custom button to the formatting toolbar using the format API

( function( wp ) {
    var MyCustomButton = function( props ) {
        return wp.element.createElement(
            wp.editor.RichTextToolbarButton, {
                icon: 'editor-code',
                title: 'Sample output',
                onClick: function() {
                    props.onChange( wp.richText.toggleFormat(
                        props.value,
                        { type: 'my-custom-format/sample-output' }
                    ) );
                },
                isActive: props.isActive,
            }
        );
    }
    wp.richText.registerFormatType(
        'my-custom-format/sample-output', {
            title: 'Sample output',
            tagName: 'sample',
            className: null,
            edit: MyCustomButton,
        }
    );
} )( window.wp );

The new custom button is added to the formatting toolbar of all the blocks. Is it possible to register it to a specific block only or a list of blocks?

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions