Align Toggle
betaA segmented start, center and end alignment control whose thumb stretches between choices above a live paragraph preview.
- Forms
- 1 file
- 2 npm packages
- Accessibility notes
Loading the example…
pnpm dlx @dowel-ui/cli add align-togglenpm packages installed: class-variance-authority, radix-ui.
import { AlignToggle } from "@/components/ui/align-toggle";Default
Demo Story
Sizes
<AlignToggle>
| Prop | Type | Default |
|---|---|---|
defaultValueThe alignment chosen at first (uncontrolled). Defaults to | Alignment | "start" |
disabledDisables every button. | boolean | — |
labelsAccessible names for the three buttons. | Partial<Record<Alignment, string>> | — |
onValueChangeCalled with the new alignment when the choice changes. | (value: Alignment) => void | — |
previewShows the small paragraph preview above the buttons. Defaults to true. | boolean | true |
size | "sm" | "md" | "lg" | "md" |
valueThe chosen alignment (controlled). | Alignment | — |
Plus every attribute of <div> except defaultValue, dir, onChange.
Built on Radix ToggleGroup in single mode: the root is a radiogroup named "Text alignment" by default (override with aria-label), arrow keys move focus between the three radio buttons, Space or Enter chooses, and the chosen one is checked. Each choice is named ("Align start", "Align center", "Align end"; override with `labels`) since it shows only an icon, and pressing the chosen one again does not clear it. The paragraph preview and the thumb are aria-hidden. Values are logical, so in right-to-left layouts start aligns right and the icons mirror. Under reduced motion the thumb and preview jump.
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes