我发现您可以向按钮添加一个className属性,并通过文档选择按钮。getElementsByClassName查询选择器。所以代码应该是这样的
( function( wp ) {
var MyCustomButton = function( props ) {
return wp.element.createElement(
wp.editor.RichTextToolbarButton, {
icon: \'editor-code\',
title: \'Sample output\',
className: "foo"
onClick: function() {
console.log( \'toggle format\' );
},
}
);
}
wp.richText.registerFormatType(
\'my-custom-format/sample-output\', {
title: \'Sample output\',
tagName: \'samp\',
className: null,
edit: MyCustomButton,
}
);
} )( window.wp );
将类名foo添加到按钮。