Creating custom Group toolbar buttons
A group toolbar button is a toolbar button that contains a collection of other toolbar buttons that are displayed in a pop-up when clicked. The style of toolbar shown is based on the current toolbar mode. For example, if toolbar_mode is set to floating, the toolbar group pop-up will appear in a floating shelf.
The group toolbar button is only supported when using the floating toolbar mode. If the toolbar_groups option is used with other toolbar modes, the toolbar group button will not be displayed and a warning message will be printed in the console.
|
Options
| Name | Value | Requirement | Description |
|---|---|---|---|
text |
string |
optional |
Text to display if no icon is found. |
icon |
string |
optional |
Name of the icon to be displayed. Must correspond to an icon: in the icon pack, in a custom icon pack, or added using the |
tooltip |
string |
optional |
Text for button tooltip. |
items |
string or |
required |
A string of space separated toolbar button names, or an array of labelled toolbar buttons. |
onSetup |
|
optional |
default: |
context |
string |
optional |
default: |
API
| Name | Value | Description |
|---|---|---|
isEnabled |
|
Checks if the button is enabled. |
setEnabled |
|
Sets the button’s enabled state. |
setText |
|
Sets the text label to display. |
setIcon |
|
Sets the icon of the button. |
Group toolbar button example and explanation
The following is a simple group toolbar button example:
The example above configures a custom alignment group toolbar button. When clicked the button will show a floating shelf containing the align left, center, right and justify toolbar buttons.
Using onSetup
onSetup accepts a function that receives the component’s API. This function should return a callback that returns nothing after being passed the component’s API. This occurs because onSetup runs whenever the component is rendered, and the callback returned by onSetup is executed when the component is destroyed. The function returned from onSetup is essentially an onTeardown handler, and can be used to unbind events and callbacks.
To clarify, in code onSetup may look like this:
onSetup: (api) => {
// Runs when the component is created
// Configure the component or bind event listeners
return (api) => {
// Runs when the component is destroyed
// Unbind event listeners or clean up resources
};
};
To bind a callback function to an editor event use +editor.off(eventName, callback)`]. To unbind an event listener use `xref:apis/tinymce.editor.adoc#off[`+editor.off(eventName, callback). Any event listeners should be unbound in the teardown callback. The only editor event which does not need to be unbound is `init e.g. editor.on('init', callback).
|