blockcn

Toolbar button

Add a button to the formatting toolbar.

children replaces the default row. FormattingToolbar.Button uses the same roving tabindex as the built-in buttons. To keep the defaults and add one, pass items instead of replacing children. See Basic editor.

This page's code block is examples/recipes/toolbar-button.tsx. pnpm --dir docs typecheck compiles that file and fails if this block drifts.

import type { Editor } from "@tiptap/core";
import { Pin } from "lucide-react";
import { FormattingToolbar } from "@/components/editor/FormattingToolbar";

/** `FormattingToolbar.Button` joins the same roving tabindex as Bold and Italic. */
export function PinButton({ editor }: { editor: Editor }) {
  return (
    <FormattingToolbar editor={editor}>
      <FormattingToolbar.Bold />
      <FormattingToolbar.Button icon={Pin} label="Pin" onClick={() => editor.chain().focus().run()} />
    </FormattingToolbar>
  );
}