A split button contains a basic button and a menu button, wrapped up into one toolbar item. Clicking the menu button section opens a dropdown list. The basic button section and the menu items can be configured to trigger different actions when clicked.
| Name | Value | Target component | Requirement | Description |
|---|---|---|---|---|
text |
string |
Primary button |
optional |
Text displayed if no icon is found. |
icon |
string |
Primary button |
optional |
|
tooltip |
string |
Primary button |
optional |
Text displayed when hovering over the main button. |
chevronTooltip |
string |
Chevron button |
optional |
Text displayed when hovering over the chevron button. If not provided, it will be generated using the tooltip of the main button. ie: |
onAction |
|
Primary button |
required |
Function invoked when the basic button section is clicked. |
select |
|
Choice menu items |
optional |
default: |
columns |
number or |
Drop-down menu |
optional |
default: |
fetch |
|
Drop-down menu |
required |
A callback function that should be passed a list of choice menu items for the dropdown menu. |
onItemAction |
|
Choice menu items |
required |
Function invoked when a dropdown list option is clicked. The |
onSetup |
|
All |
optional |
default: |
context |
string |
All |
optional |
default: |
| Name | Value | Description |
|---|---|---|
isEnabled |
|
Checks if the button is enabled. |
setEnabled |
|
Sets the button’s enabled state. |
isActive |
|
Checks the button’s toggle state. |
setActive |
|
Sets the button’s toggle state. |
setText |
|
Sets the text label to display. |
setIcon |
|
Sets the icon of the button. |
setTooltip |
|
Sets the main button tooltip. |
The following example sets up a split button with a text label and a static dropdown menu.
liveDemo::custom-toolbar-split-button[tab="js"]
A split button is similar to a basic button in that they both require an onAction callback. The onAction callback function should take the button’s API and return nothing. It is called when the basic button section is clicked. In this example, onAction calls editor.insertContent(value) which inserts the given content into the editor.
onItemAction is called when a menu item is clicked. The callback function is passed the split button’s API and the value of the selected menu item. Nothing should be returned. The example calls editor.insertContent(value) to insert the value into the editor’s content.
The fetch function is called whenever the split button’s drop-down menu is opened. It is a function that takes a callback and passes it an array of menu items to be rendered in the button’s drop-down menu. This allows for asynchronous fetching of the menu items.