EditorToolbar
Formatting buttons for the editor, fixed above the text or floating over a selection, with pressed states that follow the cursor.
On this page
Examples
Custom buttons
A WAI-ARIA toolbar: one tab stop, arrow keys, Home and End move between buttons; Escape returns to the text.
Arrow keys move between buttons, Alt+F10 reaches the toolbar from the text.
<div class="flex w-full max-w-2xl flex-col gap-3">
<KlyFormField Label="Custom toolbar" Help="Arrow keys move between buttons, Alt+F10 reaches the toolbar from the text.">
<KlyEditor Value="@("<p>First block</p><p>Second block</p>")" Name="custom" data-testid="editor-toolbar">
<KlyEditorToolbar Items="Items" Size="KlySize.Md" />
</KlyEditor>
</KlyFormField>
</div>
@code {
private static readonly EditorToolbarItem[] Items =
[
new(EditorAction.Bold), new(EditorAction.Italic), new(EditorAction.Underline),
EditorToolbarItem.Separator,
new(EditorAction.Paragraph), EditorToolbarItem.Heading(2), new(EditorAction.BulletList),
EditorToolbarItem.Separator,
new(EditorAction.MoveUp), new(EditorAction.MoveDown),
EditorToolbarItem.Separator,
new(EditorAction.ClearFormatting), new(EditorAction.Undo), new(EditorAction.Redo),
];
}Floating
Select some text to format it.
<div class="flex w-full max-w-2xl flex-col gap-3">
<KlyFormField Label="Summary" Help="Select some text to format it.">
<KlyEditor Value="@("<p>Select a few of these words, then use the floating toolbar or press Ctrl+B.</p>")" Name="summary" data-testid="editor-bubble">
<KlyEditorToolbar Layout="EditorToolbarLayout.Bubble" />
</KlyEditor>
</KlyFormField>
<KlyFormField Label="Read only">
<KlyEditor Value="@("<p>This text can be selected and copied, not edited.</p>")" ReadOnly="true" data-testid="editor-readonly" />
</KlyFormField>
</div>Changing buttons
Replacing Items while the editor is open: each button shows the pressed and disabled state of the action it now stands for.
Items can change while the editor is open: the buttons show the state of the action they now stand for.
<div class="flex w-full max-w-2xl flex-col gap-3">
<KlyFormField Label="Changing buttons" Help="Items can change while the editor is open: the buttons show the state of the action they now stand for.">
<KlyEditor Value="@("<p><strong><em>Bold and italic</em></strong></p>")" Name="changing" data-testid="editor-changing">
<KlyEditorToolbar Items="Current" />
</KlyEditor>
</KlyFormField>
<div>
<KlyButton Variant="ButtonVariant.Outline" OnClick="Next" data-testid="editor-changing-next">Use other buttons</KlyButton>
</div>
</div>
@code {
private static readonly EditorToolbarItem[][] Sets =
[
[new(EditorAction.Bold), new(EditorAction.Italic)],
[new(EditorAction.Bold), new(EditorAction.Code)],
[new(EditorAction.Bold), new(EditorAction.Redo)],
];
private int _set;
private EditorToolbarItem[] Current => Sets[_set];
private void Next() => _set = (_set + 1) % Sets.Length;
}API
KlyEditorToolbar
Formatting toolbar of a KlyEditor .
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"primary" |
Color of pressed buttons. Values: primary, secondary, success, info, warning, error, neutral. |
Items |
IReadOnlyList |
The buttons, in order. Defaults to Defaults , or BubbleDefaults for a bubble toolbar. | |
Label |
string |
Accessible name of the toolbar. Defaults to EditorToolbar . | |
Layout |
Editor |
Editor |
Fixed (always visible, above the text) or Bubble (floats above a selection). Buttons are enabled once the editor is ready; before that, in static pages, they are disabled. Values: Fixed, Bubble. |
Size |
KlySize |
KlySize. |
Size of the toolbar buttons, from Xs to Xl . Values: Xs, Sm, Md, Lg, Xl. |
Ui |
EditorToolbarUi |
Per-instance class overrides of the slots of the editor toolbar, see EditorToolbarUi . They are merged after the theme and the Class parameter wins on the root slot. |
Ui slots
Ui takes a EditorToolbarUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyEditorToolbar , after the theme and the app configuration. |
Button |
Classes merged into the button slot of KlyEditorToolbar , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyEditorToolbar , after the theme and the app configuration. |
Separator |
Classes merged into the separator slot of KlyEditorToolbar , after the theme and the app configuration. |
LinkForm |
Classes merged into the linkForm slot of KlyEditorToolbar , after the theme and the app configuration. |
LinkInput |
Classes merged into the linkInput slot of KlyEditorToolbar , after the theme and the app configuration. |
LinkButton |
Classes merged into the linkButton slot of KlyEditorToolbar , after the theme and the app configuration. |
LinkMessage |
The explanation shown under the address field when the editor does not accept the address. |
EditorToolbarItem
A button of KlyEditorToolbar , or a separator between groups of buttons.
Parameters
| Name | Type | Description |
|---|---|---|
Action |
EditorAction |
What the button does. Values: Bold, Italic, Strike, Underline, Code, Paragraph, Heading, BulletList, OrderedList, TaskList, Blockquote, CodeBlock, HorizontalRule, Link, Image, ClearFormatting, Undo, Redo, MoveUp, MoveDown. |
IsSeparator |
bool |
True for Separator , which is a line between groups and not a button. |
Label |
string |
Accessible name and tooltip. Defaults to the text of KlyMessages for the action. |
Level |
int |
Heading level for Heading . |
EditorAction
What a toolbar button or a slash-menu item does to the editor.
EditorToolbarLayout
Where the toolbar shows.