Rich Text Field

The frame around a rich text editor: a label, a toolbar of 28 px formatting buttons over a divider, and the text with the field's edge and focus. The editor engine stays in the app (the CRM's Tiptap); paragraphs, lists and links inside take the field's type.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { RichTextButton, RichTextField, RichTextSeparator } from "@leap-crm/design-system";

With a toolbar

Click into the text for the focus edge. Tab reaches the toolbar once; arrow keys move along it. A pressed button shows the pressed fill. In the CRM the children are Tiptap's EditorContent, given the editor props.

Invalid

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { Bold, Italic, Link, List, ListOrdered } from "lucide-react";

import { useState } from "react";

import { RichTextButton, RichTextField, RichTextSeparator } from "@leap-crm/design-system";

function Formatting() {
  const [on, setOn] = useState<Record<string, boolean>>({ list: true });
  const toggle = (key: string) =>
    setOn(current => ({ ...current, [key]: !current[key] }));
  return (
    <>
      <RichTextButton
        icon={<Bold />}
        label="Bold"
        shortcut="mod+b"
        pressed={on.bold ?? false}
        onClick={() => toggle("bold")}
      />
      <RichTextButton
        icon={<Italic />}
        label="Italic"
        shortcut="mod+i"
        pressed={on.italic ?? false}
        onClick={() => toggle("italic")}
      />
      <RichTextButton
        icon={<List />}
        label="Bulleted list"
        pressed={on.list ?? false}
        onClick={() => toggle("list")}
      />
      <RichTextButton
        icon={<ListOrdered />}
        label="Numbered list"
        pressed={on.numbered ?? false}
        onClick={() => toggle("numbered")}
      />
      <RichTextSeparator />
      <RichTextButton icon={<Link />} label="Link" shortcut="mod+k" />
    </>
  );
}

const sample = (
  <>
    <p>
      Prefers email. <a href="/rich-text-field">Settlement checklist</a> is in
      the matter folder.
    </p>
    <ul>
      <li>Call the vendor’s solicitor</li>
      <li>Send the costs agreement</li>
    </ul>
  </>
);

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it when the reader needs the formatting, like a note with a list of next steps or an email body with links. Use Textarea for plain text.
DoPass the editor as a function child and spread the props it receives onto the editable element, so label names the editor for screen readers.
DoGive every RichTextButton a label, and a shortcut where one exists, like mod+b for bold. The label is its name and its tooltip.
DoSeparate groups of buttons with RichTextSeparator, like text styles apart from lists.
Don'tSet invalid with nothing else. It only turns the edge red, so add text under the field that says what to do, like "Please enter a note".
Don'tPut a separate Label above it. Use label, which is wired to the editor.

Props

RichTextField

PropTypeDefaultDescription
labelReactNode—Names the editor.
toolbarReactNode—The formatting buttons: RichTextButton and RichTextSeparator.
toolbarLabelstring"Formatting"Names the toolbar for screen readers.
invalidbooleanfalseDraws the field invalid.
classNamestring—Classes added to the root element, merged with its own. Tokens only.
children *ReactNode | ((props: EditorProps) => ReactNode)—The editor. A function receives the props that name it.

RichTextButton

PropTypeDefaultDescription
icon *ReactNode—The 14 px icon.

RichTextSeparator

No props of its own.

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TabLands on the toolbar once, and Tab again leaves it.
ArrowRightArrowLeftMove between the toolbar's buttons.
EnterSpacePress the focused toolbar button.