# Rich text editor

- **[Atoms](/components/)**

Short formatted text edited in place: headings, bold, italic, bullet and task lists (GFM checkboxes) and links, Markdown in and out, with a toolbar that floats while it has focus.

## When to use

- **Use for**: Editing a section of a document in place: a proposal, a brief, a page's text, where bold, a list and a link are enough.
- **Not for**: Plain one-paragraph text. Use Textarea. Long documents with headings, tables and images: that needs a document editor.
- **Pairs with**: A section heading, a Save button, Banner for a conflict.

## Preview

rich-text-editor.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { RichTextEditor } from '@/components/klarhimmel/ui/rich-text-editor';

export default function Example() {
  return (
    <Theme theme="brand">
      <RichTextEditor
        label="Scope"
        value="We **redesign** the booking flow."
        onChange={(markdown) => localStorage.setItem('scope', markdown)}
      />
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add https://ui.klarhimmel.com/r/rich-text-editor.json
  ```
- **Import**

  ```
  import { RichTextEditor } from '@/components/klarhimmel/ui/rich-text-editor';
  ```

- **Files**: rich-text-editor.tsx, in components/klarhimmel/ui/. With it: icon-button, theme, utils. npm: hast-util-from-dom and 9 more.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Props

- **value**: Markdown. A new value from outside replaces the text; the editor's own changes come back through onChange.
- **onChange**: Required. Markdown. A new value from outside replaces the text; edits come back as Markdown.
- **label**: Required: names the text box (and, after the toolbar label, its toolbar).
- **placement**: Where the toolbar floats while the editor has focus. auto: above, or below when there is no room above it in the window (the top inset is the page's scroll-padding-top, so a sticky header counts). It never takes room in the page.
- **maxLength**: The longest Markdown accepted, in characters; an edit past it is undone. 0 for no limit.
- **labels**: The toolbar's and the buttons' names. English by default: pass them translated.
- **className**: Extra classes, merged after the component's own.

## Accessibility

- Type · Edits the text; Markdown comes back through onChange
- Cmd or Ctrl + B / I · Bold, italic
- Cmd or Ctrl + Z, Shift + Cmd or Ctrl + Z · Undo, redo
- Shift + Tab from the text · Reaches the toolbar
- Left / Right / Home / End in the toolbar · Move between its buttons; Tab leaves it

[Accessibility](/get-started/accessibility)

A named multi-line textbox. The toolbar has one tab stop, Bold, Italic and List say whether they are on, and it floats only while the editor has focus, so the page never moves.

[Previous](/components/chat-composer)

[Next](/components/doc-page)
