Align Toolbar Button
AlignToolbarButton is a Plate text-alignment dropdown for toolbars. It shows an icon for the current block alignment and opens a menu of left, center, right, and justify options that apply TextAlignPlugin to the selection.


Installed with shadcn add · 2 workarounds · theme from registry.json
- applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
- installed base item https://platejs.org/r/plate-ui.json (registry preview settings)
Installation
Usage
import { AlignToolbarButton } from '@/components/ui/align-toolbar-button';export function EditorToolbar() { return ( <div className='flex items-center gap-1'> <AlignToolbarButton /> </div> );}- Adding text alignment controls to a Plate editor toolbar where space is limited and an icon-only dropdown is preferred over four separate buttons.
- Letting users switch the alignment of the current block (left, center, right, justify) from a fixed or floating toolbar.
- Showing the active alignment of the current selection so the trigger icon reflects the user's current state.
- Building a rich-text editor with the @platejs/basic-styles text-align feature enabled.
Examples
Basic toolbar usage
Render the alignment dropdown inside a toolbar row next to other editor controls. It must be rendered within a Plate editor context so TextAlignPlugin and useSelectionFragmentProp can resolve.
import * as React from 'react';import { AlignToolbarButton } from '@/components/ui/align-toolbar-button';export function BasicAlignToolbar() { return ( <div className='flex items-center gap-1 p-1'> <AlignToolbarButton /> </div> );}Controlled open state
Pass open and onOpenChange through to the underlying Radix DropdownMenu. The component spreads its props after its internal open state, so these values override the internal state.
import * as React from 'react';import { AlignToolbarButton } from '@/components/ui/align-toolbar-button';export function ControlledAlignToolbar() { const [open, setOpen] = React.useState(false); return ( <AlignToolbarButton open={open} onOpenChange={setOpen} /> );}Alignment next to other formatting buttons
Place the alignment dropdown in a toolbar group alongside other formatting controls, using a wrapper that keeps the buttons on one line.
import * as React from 'react';import { AlignToolbarButton } from '@/components/ui/align-toolbar-button';export function FormattingToolbar() { return ( <div className='flex flex-wrap items-center gap-0.5 rounded-md border bg-background p-1'> <AlignToolbarButton /> </div> );}API reference
Accessibility
- The trigger is rendered through DropdownMenuTrigger with asChild, so the underlying ToolbarButton receives Radix's trigger semantics such as aria-expanded and the menu-open relationship.
- ToolbarButton is given the tooltip text 'Align', which provides an accessible name and hover hint for the icon-only trigger.
- The trigger's pressed state is bound to the open menu state (pressed={open}), so assistive technology and visual styling both reflect whether the menu is open.
- The menu items are a DropdownMenuRadioGroup with DropdownMenuRadioItem entries, so the current alignment is exposed as a checked radio item.
- The alignment items render only icons (no visible text labels), so the icon-only items rely on the radio role and the surrounding context for meaning; consider supplying a wrapping label or tooltip in your app if the toolbar must be fully self-describing.
- Selecting an alignment calls editor focus after applying the change, which returns keyboard focus to the editor.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Align Toolbar Button" component (plate/align-toolbar-button) from its shadcn registry.1. Install it with: npx shadcn@latest add https://platejs.org/r/align-toolbar-button.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: ...props (DropdownMenuProps).Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { AlignToolbarButton } from '@/components/ui/align-toolbar-button';export function EditorToolbar() { return ( <div className='flex items-center gap-1'> <AlignToolbarButton /> </div> );}```Files & dependencies
- src/registry/ui/align-toolbar-button.tsx