Drag Handle React extension

Pro Extension

You ever wanted to drag nodes around your react-based editor? Well we too - so here is an extension for that.

The DragHandleReact component allows you to easily handle dragging nodes around in the editor. You can define custom render functions, placement, and more. It essentially wraps the DragHandle extension in a React component that will automatically register/unregister the extension with the editor.

Install

Set up access to Tiptap's private repository

Integrate this pro extension by registering for a free Tiptap account and following our access guide to Tiptap’s private repository.

npm install @tiptap-pro/extension-drag-handle-react

Props

All props follow the same structure as the DragHandle extension.

children

The content that should be displayed inside of the drag handle.

<DragHandle>
  <div>Drag Me!</div>
</DragHandle>

tippyOptions

Options for tippy.js. You can pass any options that are available in the tippy.js documentation.

Default: undefined

<DragHandle
  tippyOptions={{
    placement: 'left',
  }}
>
  <div>Drag Me!</div>
</DragHandle>

onNodeChange

Returns a node or null when a node is hovered over. This can be used to highlight the node that is currently hovered over.

Default: undefined

function Component() {
  const [selectedNode, setSelectedNode] = useState(null)

  return (
    <DragHandle
      onNodeChange={({ node, editor }) => {
        setSelectedNode(node)
        // do something with the node
      }}
    >
      <div>Drag Me!</div>
    </DragHandle>
  )
}

pluginKey

The key that should be used to store the plugin in the editor. This is useful if you have multiple drag handles in the same editor.

Default: undefined

<DragHandle pluginKey="myCustomDragHandle">
  <div>Drag Me!</div>
</DragHandle>

Commands

See the DragHandle extension for available editor commands.