Find out what's new in Tiptap Editor 3.0

Blockquote Button

A fully accessible blockquote button for Tiptap editors. Easily wrap selected content in a <blockquote> with keyboard shortcut support and flexible customization options.

Installation

Add the component via the Tiptap CLI:

npx @tiptap/cli@latest add blockquote-button

Components

<BlockquoteButton />

A prebuilt React component that toggles blockquote formatting.

Usage

import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'
import { BlockQuoteButton } from '@/components/tiptap-ui/blockquote-button'

import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'

export default function MyEditor() {
  const editor = useEditor({
    immediatelyRender: false,
    extensions: [StarterKit],
    content: `
        <blockquote>
            <p>"The best way to predict the future is to invent it."</p><p>— Alan Kay</p>
        </blockquote>
        `,
  })

  return (
    <EditorContext.Provider value={{ editor }}>
      <BlockquoteButton
        editor={editor}
        text="Quote"
        hideWhenUnavailable={true}
        showShortcut={true}
        onToggled={() => console.log('Blockquote toggled!')}
      />

      <EditorContent editor={editor} role="presentation" />
    </EditorContext.Provider>
  )
}

Props

NameTypeDefaultDescription
editorEditor | nullundefinedThe Tiptap editor instance
textstringundefinedOptional text label for the button
hideWhenUnavailablebooleanfalseHides the button when blockquote is not applicable
onToggled() => voidundefinedCallback fired after a successful toggle
showShortcutbooleanfalseShows a keyboard shortcut badge (if available)

Hooks

useBlockquote()

A custom hook to build your own blockquote toggle button with full control over rendering and behavior.

Usage

function MyBlockquoteButton() {
  const { isVisible, isActive, canToggle, handleToggle, label, shortcutKeys, Icon } = useBlockquote(
    {
      editor: myEditor,
      hideWhenUnavailable: true,
      onToggled: () => console.log('Blockquote toggled!'),
    },
  )

  if (!isVisible) return null

  return (
    <button onClick={handleToggle} disabled={!canToggle} aria-label={label} aria-pressed={isActive}>
      <Icon />
      {label}
      {shortcutKeys && <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>}
    </button>
  )
}

Props

NameTypeDefaultDescription
editorEditor | nullundefinedThe Tiptap editor instance
hideWhenUnavailablebooleanfalseHides the button if blockquote cannot be applied
onToggled() => voidundefinedCallback fired after toggling blockquote

Return Values

NameTypeDescription
isVisiblebooleanWhether the button should be rendered
isActivebooleanIf the blockquote is currently active
canTogglebooleanIf the blockquote toggle is currently allowed
handleToggle() => booleanFunction to toggle blockquote formatting
labelstringAccessible label text for the button
shortcutKeysstringKeyboard shortcut (Cmd/Ctrl + Shift + B)
IconReact.FCIcon component for the blockquote button

Utilities

canToggleBlockquote(editor, turnInto?)

Checks if blockquote can be toggled in the current editor state.

import { canToggleBlockquote } from '@/registry/tiptap-ui/blockquote-button'

const canToggle = canToggleBlockquote(editor) // Check if can toggle
const canTurnInto = canToggleBlockquote(editor, true) // Check if can turn into blockquote

toggleBlockquote(editor)

Programmatically toggles blockquote formatting for the current selection.

import { toggleBlockquote } from '@/registry/tiptap-ui/blockquote-button'

const success = toggleBlockquote(editor)
if (success) {
  console.log('Blockquote toggled successfully!')
}

Keyboard Shortcuts

The blockquote button supports the following keyboard shortcut:

  • Cmd/Ctrl + Shift + B: Toggle blockquote formatting

The shortcut is automatically registered when using either the <BlockquoteButton /> component or the useBlockquote() hook.

Requirements

Dependencies

  • @tiptap/react - Core Tiptap React integration
  • @tiptap/starter-kit - Basic Tiptap extensions including blockquote support
  • react-hotkeys-hook - Keyboard shortcut management

Referenced Components

  • use-tiptap-editor (hook)
  • button (primitive)
  • badge (primitive)
  • tiptap-utils (lib)
  • block-quote-icon (icon)