Skip to content
synccn

Text Editor

New

Rich text with a toolbar, shortcuts, links and a word count.

0 words

Installation

$ pnpm dlx shadcn@latest add @synccn/text-editor

First 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.

  • defaultValue
    string

    Default ""

    Starting HTML.

  • onChange
    (html: string) => void

    Called with the HTML after every change.

  • placeholder
    string

    Default "Start writing…"

    Shown when empty.

  • minHeight
    number

    Default 160

    Minimum editing height in pixels.

  • className
    string

    Extra 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

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