Indent List

Loading...
Files
components/demo.tsx
'use client';

import React from 'react';

import { Plate } from '@udecode/plate/react';

import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';

import { DEMO_VALUES } from './values/demo-values';

export default function Demo({ id }: { id: string }) {
  const editor = useCreateEditor({
    plugins: [...editorPlugins],
    value: DEMO_VALUES[id],
  });

  return (
    <Plate editor={editor}>
      <EditorContainer variant="demo">
        <Editor />
      </EditorContainer>
    </Plate>
  );
}

Features

  • Flexible Block Indentation:

    • Set list indentation for any block type (paragraphs, headings, etc.)
    • Transform any block into a list item through indentation
    • More intuitive Word/Google Docs-like behavior
  • Simplified Structure - Differs from the List plugin:

    • Flat DOM structure where each indented block is independent
    • Each indented list block consists of a single ul or ol with one item
    • No strict parent-child relationships enforced
    • Better for free-form content organization
  • List Types:

    • Bulleted lists (unordered)
    • Numbered lists (ordered)
  • Shortcuts:

    • Combined with the autoformat plugin, use markdown shortcuts (-, *, 1.) to create lists
    • Tab/Shift+Tab for indentation control

For more information about the underlying indentation system, see the Indent doc.

Installation

npm install @udecode/plate-indent-list @udecode/plate-indent

Usage

import { IndentPlugin } from '@udecode/plate-indent/react';
import { IndentListPlugin } from '@udecode/plate-indent-list/react';
import { HEADING_KEYS } from '@udecode/plate-heading';
import { HeadingPlugin } from '@udecode/plate-heading/react';
import { ParagraphPlugin } from '@udecode/plate/react';
 
const plugins = [
  // ...otherPlugins,
  HeadingPlugin,
  IndentPlugin.configure({
    inject: {
      targetPlugins: [ParagraphPlugin.key, HEADING_KEYS.h1],
    }
  }),
  IndentListPlugin.configure({
    inject: {
      targetPlugins: [ParagraphPlugin.key, HEADING_KEYS.h1],
    }
  }),
];

Plugins

IndentListPlugin

Options

Collapse all

    Function to determine indent list options for sibling elements.

    Function mapping HTML elements to list style types.

    Function to render components below indent list nodes.

API

getNextIndentList

Parameters

Collapse all

    The editor instance.

    Entry of the current element.

    Options for getting next indent list.

ReturnsNodeEntry | undefined

    Entry of the next sibling with an indent list, or undefined if not found.

getPreviousIndentList

Parameters

Collapse all

    The editor instance.

    Entry of the current element.

    Options for getting previous indent list.

ReturnsNodeEntry | undefined

    Entry of the previous sibling with an indent list, or undefined if not found.

indentList

Parameters

Collapse all

    The editor instance.

    Options for indenting list.

OptionsIndentListOptions

Collapse all

    List style type to use.

    • Default: ListStyleType.Disc

outdentList

Parameters

Collapse all

    The editor instance.

    Options for outdenting list.

OptionsIndentListOptions

Collapse all

    List style type to use.

    • Default: ListStyleType.Disc

someIndentList

Parameters

Collapse all

    The editor instance.

    List style type to check.

toggleIndentList

Parameters

Collapse all

    The editor instance.

    Options for toggling indent list.

OptionsIndentListOptions

Collapse all

    List style type to use.

Types

GetSiblingIndentListOptions

Options

Collapse all

    Get previous sibling entry.

    Get next sibling entry.

    Validate sibling node during lookup.

    Break lookup when sibling has equal indent level.

    Condition to stop lookup process.

    Break lookup on lower indent level.

    Break lookup on equal indent but different list style.

Hooks

useIndentListToolbarButton

State

Collapse all

    List style type.

    Whether button is pressed.

Returnsobject

Collapse all

    Props for the toolbar button.

    Optionsprops

    Collapse all

      Whether button is pressed.

      Handler to toggle indent list and focus editor.