admin管理员组文章数量:1314588
I'm try to add a custom button to the toolbar for paragraph blocks.
I followed the steps reproduced in this great tutorial: /
The button is correctly showing up and every piece of code in that project is working good.
I have some trouble to get the content updated inside the editor when the button is clicked.
I tried to follow this guidelines: / but I get a console error saying that the method toggleFormat is undefined.
I share this github: Gutenberg Buttons, if someone can help me to fix the issue.
Thank you
I'm try to add a custom button to the toolbar for paragraph blocks.
I followed the steps reproduced in this great tutorial: https://neliosoftware/blog/how-to-add-a-button-to-the-gutenberg-editor-using-wordpress-scripts/
The button is correctly showing up and every piece of code in that project is working good.
I have some trouble to get the content updated inside the editor when the button is clicked.
I tried to follow this guidelines: https://developer.wordpress/block-editor/tutorials/format-api/3-apply-format/ but I get a console error saying that the method toggleFormat is undefined.
I share this github: Gutenberg Buttons, if someone can help me to fix the issue.
Thank you
Share Improve this question edited Nov 26, 2020 at 16:10 Tom J Nowell♦ 61k7 gold badges79 silver badges148 bronze badges asked Nov 26, 2020 at 15:24 SuPerGiuSuPerGiu 31 bronze badge1 Answer
Reset to default 1Now I can see what the problem is. You are not using the onChange
properly. It comes from the props
of the edit component:
Here you have a complete example that works:
registerFormatType(
'nelio/keyboard', {
title: __( 'Key', 'nelio' ),
tagName: 'kbd',
className: null,
edit: ( { value, onChange } ) => (
<RichTextToolbarButton
icon="editor-removeformatting"
title={ __( 'Key', 'nelio' ) }
onClick={ () => onChange( toggleFormat( value, { type: 'nelio/keyboard' } ) ) }
/>
),
}
);
本文标签: Add button to Block toolbar toggleFormat is undefined
版权声明:本文标题:Add button to Block toolbar: toggleFormat is undefined 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741961477a2407305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论