Skip to content
Haze UI

Rich text editor

Edit formatted prose with a compact native toolbar, safe link insertion and an editable Markdown source field.

pnpm dlx shadcn@latest add @haze/rich-text-editor
Open preview in a new tab
Livesmall script

When to use

  • Project notes or updates need headings, emphasis, lists and links without a large editor dependency.
  • The submitted document should be Markdown and remain editable with scripting disabled.

When not to use

  • Use textarea for plain prose without formatting.
  • Choose a dedicated document editor when collaborative cursors, tables, media or lossless arbitrary HTML are required.

Installation

Add the Haze registry to components.json once, then install Rich text editor with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/rich-text-editor
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique caller supplied prefix for the control and its associated content.
namestringidName submitted by the native form control.
labelstringProject updateVisible editor label shared by the formatted surface and source.
valuestringDemo handoff noteInitial Markdown; supports headings, simple emphasis, unordered lists, code and links.
placeholderstringWrite an update…Placeholder of the native Markdown textarea.
rowsnumber9Starting textarea row count in Markdown mode.
requiredbooleanfalseUses native required validation on the submitted source field.
disabledbooleanfalsePrevents user changes through the native disabled state.
readonlybooleanfalseKeeps both the formatted surface and source read only.
classstring–Additional classes on this component's outer wrapper.
[key: string]unknown–Other native textarea attributes.

Keyboard interactions

Ctrl/⌘ BI in the editor
Use the browser's native bold and italic editing commands.
Tab, EnterSpace
Reach formatting, link insertion and Markdown source controls.
EnterEsc in the link field
Insert the link, or close the link row and return focus to the Link button.
Ctrl/⌘ ZShift Z
Use the browser editing history while the formatted surface is focused.

Accessibility

  • A labelled contenteditable textbox provides formatted editing, while the Markdown toggle exposes the real textarea used for form submission.
  • Formatting buttons preserve the text selection, expose pressed state where appropriate and remain ordinary keyboard reachable buttons.
  • Pasted material is inserted as plain text; source rendering constructs DOM nodes rather than injecting HTML, and links accept only http, https or mailto destinations.
  • If native validation rejects the required source field, Markdown mode opens so the browser can focus the invalid control.
  • The enhancement uses the browser's editing commands and supports a compact Markdown subset; it is not a lossless round trip for arbitrary HTML or Markdown extensions.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Rich text editor" with `npx shadcn@latest add @haze/rich-text-editor`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import RichTextEditor from "@/components/haze/ui/rich-text-editor.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/rich-text-editor.md

  • Customize with real content

    Adapt the Haze rich-text-editor ui for our product. Replace the demo values of these props with our real content: id, name, label, value, placeholder, rows, required, disabled, readonly, class, [key: string]. Keep the layout, the heading level rules and these accessibility details: A labelled contenteditable textbox provides formatted editing, while the Markdown toggle exposes the real textarea used for form submission. Formatting buttons preserve the text selection, expose pressed state where appropriate and remain ordinary keyboard reachable buttons. Pasted material is inserted as plain text; source rendering constructs DOM nodes rather than injecting HTML, and links accept only http, https or mailto destinations. If native validation rejects the required source field, Markdown mode opens so the browser can focus the invalid control. The enhancement uses the browser's editing commands and supports a compact Markdown subset; it is not a lossless round trip for arbitrary HTML or Markdown extensions. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using rich-text-editor, check it fits: use it when project notes or updates need headings, emphasis, lists and links without a large editor dependency.; the submitted document should be markdown and remain editable with scripting disabled.. Avoid it when use textarea for plain prose without formatting.; choose a dedicated document editor when collaborative cursors, tables, media or lossless arbitrary html are required.. Alternatives: @haze/textarea, @haze/input, @haze/code-block.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog