Find out what's new in Tiptap Editor 3.0

Duplicate Button

A fully accessible duplicate button for Tiptap editors. Clone selected nodes or blocks in the editor with keyboard shortcut support and intelligent content copying.

Installation

Add the component via the Tiptap CLI:

npx @tiptap/cli@latest add duplicate-button

Components

<DuplicateButton />

A prebuilt React component that duplicates nodes in the editor.

Usage

export default function MyEditor() {
  return (
    <DuplicateButton
      editor={editor}
      text="Duplicate"
      hideWhenUnavailable={true}
      showShortcut={true}
      onDuplicated={() => console.log('Node duplicated!')}
    />
  )
}

Props

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

Hooks

useDuplicate()

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

Usage

function MyDuplicateButton() {
  const { isVisible, handleDuplicate, canDuplicate, label, shortcutKeys, Icon } = useDuplicate({
    editor: myEditor,
    hideWhenUnavailable: true,
    onDuplicated: () => console.log('Node duplicated!'),
  })

  if (!isVisible) return null

  return (
    <button onClick={handleDuplicate} disabled={!canDuplicate} aria-label={label}>
      <Icon />
      {label}
      {shortcutKeys && <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>}
    </button>
  )
}

Props

NameTypeDefaultDescription
editorEditor | nullundefinedThe Tiptap editor instance
hideWhenUnavailablebooleanfalseHides the button if duplication cannot be performed
onDuplicated() => voidundefinedCallback fired after successful duplication

Return Values

NameTypeDescription
isVisiblebooleanWhether the button should be rendered
canDuplicatebooleanIf a node can be duplicated
handleDuplicate() => booleanFunction to duplicate the selected node
labelstringAccessible label text for the button
shortcutKeysstringKeyboard shortcut (Cmd/Ctrl + D)
IconReact.FCIcon component for the duplicate button (CopyIcon)

Utilities

canDuplicateNode(editor)

Checks if a node can be duplicated in the current editor state.

import { canDuplicateNode } from '@/registry/tiptap-ui/duplicate-button'

const canDuplicate = canDuplicateNode(editor)

duplicateNode(editor)

Programmatically duplicates the selected node or block.

import { duplicateNode } from '@/registry/tiptap-ui/duplicate-button'

const success = duplicateNode(editor)
if (success) {
  console.log('Node duplicated successfully!')
}

Keyboard Shortcuts

The duplicate button supports the following keyboard shortcut:

  • Cmd/Ctrl + D: Duplicate the selected node or block

The shortcut is automatically registered when using either the <DuplicateButton /> component or the useDuplicate() hook. Note that this overrides the browser's default bookmark behavior when the editor is focused.

Requirements

Dependencies

  • @tiptap/react - Core Tiptap React integration
  • react-hotkeys-hook - Keyboard shortcut management

Referenced Components

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