# Rich text editor

Author controlled formatted content with constrained native editing and JSON serialization.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs author controlled formatted content with constrained native editing and json serialization.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than rich text editor.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Rich text editor

```sh
npx shadcn@latest add @tidal-pro/rich-text-editor
```

Stylesheets: `components/ui/tidal.css`, `components/ui/rich-text-editor.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/rich-text-editor.css";
import{TidalRichTextEditor}from"./components/ui/rich-text-editor";
export default()=><div className="tidal-scope"><TidalRichTextEditor label={"Demo"} onValueChange={() => {}} value={"value"}/></div>;
```

## Structured props

- `TidalRichTextEditor.label: ReactNode`: Required label value accepted by this exported component.
- `TidalRichTextEditor.onValueChange: (value: string, editor: LexicalEditor) => void`: Callback invoked when the value change interaction is proposed.
- `TidalRichTextEditor.value: string`: Required value value accepted by this exported component.
- `TidalRichTextEditor.commandButtonProps?: Partial<Record<TidalRichTextCommand, CommandButtonProps>> | undefined`: Optional command button props value accepted by this exported component.
- `TidalRichTextEditor.commandButtonRefs?: Partial<Record<TidalRichTextCommand, Ref<HTMLButtonElement>>> | undefined`: Optional command button refs value accepted by this exported component.
- `TidalRichTextEditor.contentEditableProps?: EditableProps | undefined`: Optional content editable props value accepted by this exported component.
- `TidalRichTextEditor.contentEditableRef?: Ref<HTMLDivElement> | undefined`: Optional content editable ref value accepted by this exported component.
- `TidalRichTextEditor.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalRichTextEditor.dir?: "ltr" | "rtl" | undefined` (default "ltr"): Optional dir value accepted by this exported component.
- `TidalRichTextEditor.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalRichTextEditor.editorRef?: Ref<LexicalEditor> | undefined`: Optional editor ref value accepted by this exported component.
- `TidalRichTextEditor.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalRichTextEditor.form?: string | undefined`: Optional form value accepted by this exported component.
- `TidalRichTextEditor.hiddenInputProps?: HiddenInputProps | undefined`: Optional hidden input props value accepted by this exported component.
- `TidalRichTextEditor.hiddenInputRef?: Ref<HTMLInputElement> | undefined`: Optional hidden input ref value accepted by this exported component.
- `TidalRichTextEditor.labels?: TidalRichTextEditorLabels | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalRichTextEditor.linkHref?: string | null | undefined`: Optional link href value accepted by this exported component.
- `TidalRichTextEditor.name?: string | undefined`: Optional name value accepted by this exported component.
- `TidalRichTextEditor.onPaste?: ((event: ClipboardEvent) => void) | undefined`: Callback invoked when the paste interaction is proposed.
- `TidalRichTextEditor.placeholder?: ReactNode` (default "Write content…"): Optional placeholder value accepted by this exported component.
- `TidalRichTextEditor.portalContainer?: HTMLElement | null | undefined`: Optional portal container value accepted by this exported component.
- `TidalRichTextEditor.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalRichTextEditor.theme?: "light" | "dark" | undefined` (default "light"): Optional theme value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/rich-text-editor.tsx) | [Manifest](https://tidalui.com/examples/rich-text-editor.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import "./components/ui/rich-text-editor.css";

import { useId, useState, type FormEvent } from "react";

import { TidalRichTextEditor } from "./components/ui/rich-text-editor";

import "./components/ui/toolbar.css";



const tidalExampleStyles = ".tidal-scope .rich-text-editor-demo {\n  display: grid;\n  gap: 16px;\n  inline-size: min(100%, 760px);\n  min-inline-size: 0;\n  margin-inline: auto;\n}\n\n.tidal-scope .rich-text-editor-link-row {\n  display: grid;\n  grid-template-columns: minmax(0, 130px) minmax(0, 1fr);\n  align-items: center;\n  gap: 10px;\n  padding: 12px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-subtle);\n}\n\n.tidal-scope .rich-text-editor-link-row label {\n  min-inline-size: 0;\n  font-size: 11px;\n  font-weight: 740;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .rich-text-editor-link-row input {\n  box-sizing: border-box;\n  inline-size: 100%;\n  min-inline-size: 0;\n  min-block-size: 44px;\n  padding-inline: 12px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n}\n\n.tidal-scope .rich-text-editor-link-row input:focus-visible,\n.tidal-scope .rich-text-editor-demo-footer button:focus-visible,\n.tidal-scope .rich-text-editor-guide summary:focus-visible {\n  outline: 3px solid var(--t-accent);\n  outline-offset: 2px;\n}\n\n.tidal-scope .rich-text-editor-demo-footer {\n  display: grid;\n  grid-template-columns: auto minmax(0, 1fr);\n  align-items: center;\n  gap: 12px;\n}\n\n.tidal-scope .rich-text-editor-demo-footer button {\n  min-block-size: 44px;\n  padding-inline: 16px;\n  border: 1px solid var(--t-ink);\n  border-radius: 10px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  font: 750 12px/1 var(--t-font);\n  cursor: pointer;\n}\n\n.tidal-scope .rich-text-editor-demo-footer output,\n.tidal-scope .rich-text-editor-guide,\n.tidal-scope .rich-text-editor-sample-note {\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .rich-text-editor-guide {\n  padding-block: 12px;\n  border-block: 1px solid var(--t-border);\n}\n\n.tidal-scope .rich-text-editor-guide summary {\n  min-block-size: 44px;\n  display: flex;\n  align-items: center;\n  color: var(--t-ink);\n  font-weight: 740;\n  cursor: pointer;\n}\n\n.tidal-scope .rich-text-editor-guide p,\n.tidal-scope .rich-text-editor-sample-note {\n  margin: 0;\n}\n\n@media (max-width: 520px) {\n  .tidal-scope .rich-text-editor-link-row,\n  .tidal-scope .rich-text-editor-demo-footer {\n    grid-template-columns: minmax(0, 1fr);\n  }\n\n  .tidal-scope .rich-text-editor-link-row input {\n    font-size: 16px;\n  }\n\n  .tidal-scope .rich-text-editor-demo-footer button {\n    inline-size: 100%;\n  }\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  .tidal-scope .rich-text-editor-demo-footer button {\n    transition:\n      transform 140ms var(--t-ease-out),\n      background-color 140ms var(--t-ease-out);\n  }\n\n  .tidal-scope .rich-text-editor-demo-footer button:active {\n    transform: scale(0.98);\n  }\n}";

const SAMPLE_DOCUMENT = JSON.stringify({
  root: {
    children: [
      {
        children: [
          {
            detail: 0,
            format: 0,
            mode: "normal",
            style: "",
            text: "Workspace notifications",
            type: "text",
            version: 1,
          },
        ],
        tag: "h2",
        direction: null,
        format: "",
        indent: 0,
        type: "heading",
        version: 1,
      },
      {
        children: [
          {
            detail: 0,
            format: 1,
            mode: "normal",
            style: "",
            text: "New:",
            type: "text",
            version: 1,
          },
          {
            detail: 0,
            format: 0,
            mode: "normal",
            style: "",
            text: " choose which project updates appear in your weekly summary.",
            type: "text",
            version: 1,
          },
        ],
        direction: null,
        format: "",
        indent: 0,
        textFormat: 1,
        textStyle: "",
        type: "paragraph",
        version: 1,
      },
    ],
    direction: null,
    format: "",
    indent: 0,
    type: "root",
    version: 1,
  },
});

function safeFragment(value: string) {
  return `rich-text-guide-${value.replace(/[^a-zA-Z0-9_-]/g, "")}`;
}

export function RichTextEditorDemo({
  theme = "light",
}: {
  theme?: "light" | "dark";
}) {
  const guideId = safeFragment(useId());
  const [value, setValue] = useState(SAMPLE_DOCUMENT);
  const [linkHref, setLinkHref] = useState(`#${guideId}`);
  const [status, setStatus] = useState("Sample content is ready for review.");

  function review(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const submitted = String(
      new FormData(event.currentTarget).get("product-content") ?? "",
    );
    setStatus(
      submitted === value
        ? "The current editor JSON was reviewed locally."
        : "The submitted document did not match the current value.",
    );
  }

  return (
    <form className="rich-text-editor-demo" onSubmit={review}>
      <TidalRichTextEditor
        label="Product update"
        description="Format a short update for the sample workspace guide."
        value={value}
        onValueChange={(next) => {
          setValue(next);
          setStatus("Sample content has local changes.");
        }}
        name="product-content"
        linkHref={linkHref}
        placeholder="Write a product update…"
        theme={theme}
      />

      <div className="rich-text-editor-link-row">
        <label htmlFor={`${guideId}-link`}>Link destination</label>
        <input
          id={`${guideId}-link`}
          value={linkHref}
          onChange={(event) => setLinkHref(event.currentTarget.value)}
          spellCheck={false}
        />
      </div>

      <div className="rich-text-editor-demo-footer">
        <button type="submit">Review content</button>
        <output>{status}</output>
      </div>

      <details id={guideId} className="rich-text-editor-guide">
        <summary>Workspace writing guide</summary>
        <p>Use short headings, plain links and lists that scan clearly.</p>
      </details>

      <p className="rich-text-editor-sample-note">
        Local sample only. The editor returns JSON and does not publish, upload,
        store or execute content.
      </p>
    </form>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <RichTextEditorDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required label, controlled value:string containing canonical Lexical EditorState JSON, and onValueChange(nextJson,editor). TIDAL_EMPTY_RICH_TEXT_DOCUMENT provides a valid empty value. The component uses the Lexical 0.52 extension composer with rich-text, list and link extensions plus a local history plugin; no HTML import path is exposed. The visible editor supports bold, italic, level-two heading, unordered-list, allowlisted link, undo and redo commands through the accepted TidalToolbar keyboard model. linkHref accepts hash, root-relative, http, https and mailto destinations; an unavailable value disables new link creation and renders a localized notice, while an existing selected link can still be removed. The top-level onPaste callback receives the native ClipboardEvent first; unless prevented, the editor handles the Lexical paste command at critical priority and inserts only text/plain. value remains consumer-owned: synchronous acceptance stays in place and a declined proposal is reapplied from the controlled prop. Invalid configuration JSON makes editing unavailable, while a consumer validation error sets aria-invalid and remains editable so it can be corrected. name/form serialize the exact controlled JSON through a successful native hidden input; disabled omits it from FormData, while readOnly preserves submission. Optional disabled/readOnly, description/error/placeholder, dir, theme, portalContainer, labels, native root attributes/ref, contentEditableProps/ref, hiddenInputProps/ref, editorRef and per-command native button props/refs are supported. Owned roles, accessible names, availability, content, replacement markup, controlled values and toolbar form-submit channels are type-excluded and runtime-stripped. The editable remains mounted, selection belongs to Lexical, toolbar pointer commands retain the live selection without forced focus, and consumer-directed focus is not reclaimed. No raw HTML ingestion, dangerous HTML injection, source execution, deprecated execCommand, upload, request, storage or publishing behavior is included.
