Find out what's new in Tiptap Editor 3.0

Delete Node Button

A fully accessible delete node button for Tiptap editors. Remove selected nodes or blocks from the editor with keyboard shortcut support and smart selection handling.

Installation

Add the component via the Tiptap CLI:

npx @tiptap/cli@latest add delete-node-button

Components

<DeleteNodeButton />

A prebuilt React component that deletes nodes from the editor.

Usage

export default function MyEditor() {
  return (
    <DeleteNodeButton
      editor={editor}
      text="Delete"
      hideWhenUnavailable={true}
      showShortcut={true}
      onDeleted={() => console.log('Node deleted!')}
    />
  )
}

Props

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

Hooks

useDeleteNode()

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

Usage

function MyDeleteNodeButton() {
  const { isVisible, handleDeleteNode, canDeleteNode, label, shortcutKeys, Icon } = useDeleteNode({
    editor: myEditor,
    hideWhenUnavailable: true,
    onDeleted: () => console.log('Node deleted!'),
  })

  if (!isVisible) return null

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

Props

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

Return Values

NameTypeDescription
isVisiblebooleanWhether the button should be rendered
canDeleteNodebooleanIf a node can be deleted
handleDeleteNode() => booleanFunction to delete the selected node
labelstringAccessible label text for the button
shortcutKeysstringKeyboard shortcut (Backspace)
IconReact.FCIcon component for the delete button (TrashIcon)

Utilities

canDeleteNode(editor)

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

import { canDeleteNode } from '@/registry/tiptap-ui/delete-node-button'

const canDelete = canDeleteNode(editor)

deleteNode(editor)

Programmatically deletes the selected node or block.

import { deleteNode } from '@/registry/tiptap-ui/delete-node-button'

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

deleteNodeAtPosition(editor, pos, nodeSize)

Low-level utility to delete a node at a specific position.

import { deleteNodeAtPosition } from '@/registry/tiptap-ui/delete-node-button'

const success = deleteNodeAtPosition(editor, position, nodeSize)

Keyboard Shortcuts

The delete node button supports the following keyboard shortcut:

  • Backspace: Delete the selected node or block

The shortcut is automatically registered when using either the <DeleteNodeButton /> component or the useDeleteNode() hook. Note that this enhances the default backspace behavior to work with node selections.

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)
  • trash-icon (icon)