When creating a TinyMCE editor in React, it is possible to add a custom button to the toolbar using the following code:
<Editor
...
init={{
...
setup: (editor) => {
editor.ui.registry.addButton('test' {
text: 'Test',
onAction: () => console.log('Test')
});
}
}}
/>
Besides addButton
, there are other options such as addIcon
, addMenuItem
, and addSidebar
. However, I can’t figure out how to include my own custom component.
Say I wanted to add a very simple div/component
<div>
<ul>
<li>Test 1</li>
<li>Test 2</li>
</ul>
</div>
or
<TestComponent />
to the end of the toolbar, how would I do this?
Any ideas?
4
Answers
You need to add the key
test
to thetoolbar
property in yourinit
objectofficial website
official Github
You can try to search in website or Github by keywords to explore more examples or tests.
Here are what you needed.
addButton
addIcon
addMenuItem
addSidebar
I’ve created a simple example on how to add your own custom components such as
addIcon
,addMenuItem
, andaddSidebar
.You may find more information on customization under the docs link here.
Do note most of the examples are under
How-to guides -> Creating custom UI
components.I have also included an example codepen for your reference.
you can use the Editor.ui.registry.addButton method.
Try like below example
MyCustomButton component before the Editor component so that it appears in the toolbar. When the button is clicked, it will insert the text "Hello World!" into the editor.