FrameworkJavaScript
Toolbar API: control the block toolbar
Control the block toolbar and its state.
Reaching the editor instance
The methods below run on the editor you created with new Blok(). They are available once editor.isReady resolves.
TypeScript
// You already hold the instance returned by the constructor.
const editor = new Blok({ holder: 'editor' });
await editor.isReady;
// Call any API method on it.
editor.caret.setToLastBlock('end');Methods
toolbar.close(options?)
voidClose the toolbar with optional configuration.
When to use
Programmatically dismiss the block toolbar — e.g. after your custom action runs so the UI doesn't linger.
TypeScript
// Standard close (prevents hover reopen — default)
editor.toolbar.close();
// Close but allow the toolbar to reopen on hover
editor.toolbar.close({ setExplicitlyClosed: false });toolbar.open()
voidOpen the toolbar.
When to use
Force the toolbar open for the current block; it normally appears on hover/focus, so use sparingly.
TypeScript
editor.toolbar.open();toolbar.toggleBlockSettings(openingState?, trigger?, options?)
voidToggle the block settings menu (☰).
When to use
Open/close the ☰ settings menu in code; pass an explicit boolean to set state rather than flip it.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
openingState | boolean | — | toggle current state | Force the settings menu open (true) or closed (false). |
trigger | HTMLElement | — | undefined | Element to anchor the settings popover to. |
options | ToolbarBlockSettingsOptions | — | undefined | Placement overrides — placeLeftOfAnchor positions the popover to the left of the anchor. |
TypeScript
// Toggle current state
editor.toolbar.toggleBlockSettings();
// Force open
editor.toolbar.toggleBlockSettings(true);
// Force close
editor.toolbar.toggleBlockSettings(false);
// Anchor the settings popover to a custom trigger element,
// placed to the left of the anchor
editor.toolbar.toggleBlockSettings(true, triggerEl, { placeLeftOfAnchor: true });toolbar.toggleToolbox(openingState?)
voidToggle the toolbox (+ menu).
When to use
Open/close the + insert (slash) menu programmatically; pass a boolean to force a state.
TypeScript
// Toggle current state
editor.toolbar.toggleToolbox();
// Force open
editor.toolbar.toggleToolbox(true);