Alignment and indent
Two toolbar groups for block layout: alignment toggles and indent buttons.
Installation
This pattern is built from files in @intentui/editor. Install the editor, then copy the code above into a component of your own.
npm
pnpm
yarn
bun
npx shadcn@latest add @intentui/editor
What's included
| Piece | Why it is here |
|---|---|
RichTextExtension | Handles the align and indent commands. Every pattern needs it. |
InitialStateExtension | Applies the seeded content immediately, so the server and the client render the same. Leave it out if your editor starts empty. See Seeding initial content. |
FormatStateExtension | Tracks the alignment and indent level of the current block. Remove it and the buttons throw, because they read from it. |
TabIndentationExtension | Indents with the Tab key. Remove it and Tab moves focus out of the editor. |
ShortcutsExtension | Registers the keyboard shortcuts below. Remove it and the buttons still work, but the shortcuts do not. |
ElementFormatToolbarPlugin | The alignment toggles. |
IndentToolbarPlugin | The indent and outdent buttons. |
Toolbar | The container that holds toolbar plugins. See Toolbar. |
You can use either plugin on its own. Keep FormatStateExtension in both cases.
Alignment
The buttons are toggles, and the one matching the current block is pressed. Blocks without an explicit alignment show as left.
| Button | Shortcut |
|---|---|
| Align left | Ctrl Shift L |
| Align center | Ctrl Shift E |
| Align right | Ctrl Shift R |
| Justify | Ctrl Shift J |
| Align start, Align end | None |
Use Cmd instead of Ctrl on macOS.
Basic alignment only
Set formats="basic" to render only left, center, right and justify. The default adds start and end, which follow the text direction.
<ElementFormatToolbarPlugin formats="basic" />Indent
Outdent is disabled when the current block has no indentation. The icons flip in right-to-left layouts.
| Action | Shortcut |
|---|---|
| Indent | Ctrl ] or Tab |
| Outdent | Ctrl [ |
Styling
The indent step is a CSS variable in components/editor/theme.css.
.editor-indent {
--lexical-indent-base-value: 32px;
}API
Props of
ElementFormatToolbarPlugin. IndentToolbarPlugin takes no props.formats"basic" | "all"basic renders left, center, right and justify. all adds start and end.Default:
"all"Related patterns
- Block format to change the block type.
- Text format for inline formats.
- Floating toolbar to show controls next to the selection.