Direct Slate path to the element. If not provided, the method will search for the element in the current selection (for inline elements) or at the root (for block elements).
// Delete link at current selection (unwrap - keeps text)editor.deleteElement({ blockId: 'paragraph-1', type: 'link', // If path not specified, finds link in current selection mode: 'unwrap', // Removes link wrapper but keeps text});// Delete link completely (removes link and text)editor.deleteElement({ blockId: 'paragraph-1', type: 'link', mode: 'remove', // Removes entire link element});// Delete link by patheditor.deleteElement({ blockId: 'paragraph-1', type: 'link', path: [0, 2], // Direct path to link element mode: 'unwrap',});
// Remove link but keep the textconst removeLink = (blockId: string) => { editor.deleteElement({ blockId, type: 'link', mode: 'unwrap', // Converts <link>text</link> to just "text" });};// Remove link completelyconst removeLinkAndText = (blockId: string) => { editor.deleteElement({ blockId, type: 'link', mode: 'remove', // Removes link and its text content });};
For inline elements (like link, mention), if path is not specified, the method will automatically search for the element in the current selection. This makes it easy to delete links or mentions where the cursor is positioned.
For inline elements, you can choose between two deletion modes:
'unwrap' - Removes the inline wrapper but preserves the text content (default)
'remove' - Completely removes the element and its content
For block elements, the element is always fully removed regardless of the mode option.
Be careful when deleting elements. There’s no undo for programmatic deletions (unless you implement it yourself).
If the element is not found, the operation will fail with a console warning. Consider checking if the element exists before deletion.
When deleting parent elements, all child elements are automatically deleted as well.