Element

PreviousNext

API reference for elements in Slate.

Element objects are a type of Node in a Slate document that contain other Element nodes or Text nodes.

interface Element {
  children: Descendant[]
  type: string
  [key: string]: unknown
}
interface Element {
  children: Descendant[]
  type: string
  [key: string]: unknown
}

Element Behavior

Elements can have different behaviors depending on the editor's configuration:

Block vs Inline

Elements can be either "block" or "inline" as defined by plugin node.isInline:

  • Block elements can only be siblings with other block elements
  • Inline elements can be siblings with Text nodes or other inline elements

Void vs Non-void

Elements can be either "void" or "non-void" as defined by plugin node.isVoid:

  • Non-void elements: Slate handles rendering of children (e.g., paragraph with Text and Inline children)
  • Void elements: Children are rendered by the Element's render code

Markable Voids

Some void elements can support marks through plugin node.markableVoid. For example, a mention element might need to support bold or italic formatting.

ElementAPI

isElementType

Check if a value implements the Element interface and has elementKey matching a specified value. Defaults to checking the 'type' key.

Parameters

    The value to check.

    The value to match against.

    The key to check. Defaults to 'type'.

Returnsboolean

    true if the value is an element with the specified key matching elementVal.

isAncestor

Check if a value implements the Ancestor interface.

Parameters

    The value to check.

Returnsboolean

    true if the value is an ancestor node.

isElement

Check if a value implements the Element interface.

Parameters

    The value to check.

Returnsboolean

    true if the value is a Slate element.

isElementList

Check if a value is an array of Element objects.

Parameters

    The value to check.

Returnsboolean

    true if the value is an array of elements.

isElementProps

Check if a set of props is a partial of Element.

Parameters

    The props to check.

Returnsboolean

    true if the props match element properties.

matches

Check if an element matches a set of properties.

Parameters

    The element to check.

    The properties to match against.

Returnsboolean

    true if the element matches all provided properties.

Types

Element

Element objects are a type of node in a Slate document that contain other element nodes or text nodes. They can be either "blocks" or "inlines" depending on the editor's configuration.

Attributes

    An array of child nodes that can be either elements or text nodes.

    A string identifier that defines the element's type (e.g., 'paragraph', 'heading', etc.).

ElementEntry

Element entries represent an Element node and its path.

Attributes

    The Element node.

    The path to the element.

ElementOrTextOf

type ElementOrTextOf<E extends Editor> = ElementOf<E> | TextOf<E>;
type ElementOrTextOf<E extends Editor> = ElementOf<E> | TextOf<E>;

The ElementOrTextOf type represents either an element or a text node from a specific editor type.

ElementOrTextIn

type ElementOrTextIn<V extends Value> = ElementIn<V> | TextIn<V>;
type ElementOrTextIn<V extends Value> = ElementIn<V> | TextIn<V>;

The ElementOrTextIn type represents either an element or a text node from a specific value type.

ElementOf

ElementOf is a utility type to get all the element node types from a given root node type.

ElementIn

type ElementIn<V extends Value> = ElementOf<V[number]>;
type ElementIn<V extends Value> = ElementOf<V[number]>;

ElementIn is a utility type to get an element type from a Plate Value type.