Olddevs UI4.14.0
Recipes

Your own toolbar outside the field

A formatting toolbar in the screen header instead of the kit's Toolbar — on the useRichTextEditorState hook and the Handle.

Sometimes formatting buttons belong in the screen header, not above the field. toolbar="none" removes the kit's Toolbar, and the screen builds its own on useRichTextEditorState and engine commands via the Handle (ref).

Try it

Select a word and press “Bold” in the bar above the field; “Undo” reverts the edit, and “Insert signature” inserts a signature at the caret.

How it works

A state slice

useRichTextEditorState(ref, selector) re-renders the toolbar only when the slice changes. Typing that doesn't change “bold” or “can undo” leaves the toolbar alone. Before the engine and on the server the hook returns null.

Engine commands

The commands in the ref.current.editor.chain().focus()…run() chain are the same ones that your Tool's run receives. undo(), redo() and insertHTML() are available directly on the Handle.

preventDefault on mousedown

Call preventDefault on the button's mousedown: without it a click would take focus away from the Document, and the selection would vanish for the Bubble menu and the floating Toolbar.

Tiptap extensions declare commands like toggleBold and undo through module augmentation. For TypeScript to see them, load the types: import type {} from "@tiptap/starter-kit".

On this page