0 words
Installation
$ pnpm dlx shadcn@latest add @synccn/text-editorFirst time in this project? Connect synccn with one command.
Usage
import { TextEditor } from "@/components/ui/text-editor";<TextEditor onChange={setHtml} />API reference
Generated from the component's TypeScript types, so it always matches the code.
TextEditor
Lightweight rich-text editor (contentEditable) with a formatting toolbar, active-state buttons, keyboard shortcuts and a word count. onChange gets HTML. For complex documents use a dedicated editor such as Tiptap.
PropTypeDescription
- defaultValue
stringDefault
""Starting HTML.
- onChange
(html: string) => voidCalled with the HTML after every change.
- placeholder
stringDefault
"Start writing…"Shown when empty.
- minHeight
numberDefault
160Minimum editing height in pixels.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Bold, Code, Heading2, Italic, Link2, List, ListOrdered, Quote, Redo2, Strikethrough, Underline, Undo2
Keyboard
- Ctrl/⌘+BBold
- Ctrl/⌘+IItalic
- Ctrl/⌘+UUnderline
Accessibility
- Toolbar buttons report aria-pressed for the formatting at the cursor.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: textbox, toolbar
- ARIA attributes: aria-label, aria-multiline, aria-pressed
More inputs
ButtonSeven variants, four sizes and a built-in loading state.InputText field with optional leading icon and invalid state.TextareaMulti-line field that grows with its content and counts characters.CheckboxChecked, unchecked and indeterminate, with label and description.SwitchToggle with a springy thumb in three sizes.Radio GroupPick one option, shown as dots or as selectable cards.