<!-- generated by scripts/gen-docs.mjs from docs/system/inline-edit.md. Edit the source and rerun. -->
# InlineEdit

## Description

Lets a person change one saved value where it is shown, such as a watchlist's name or one figure in a record, and says whether the change was saved.

`import { InlineEdit, commitDraft, inlineEditLabels } from "@/components/cobalt/ui/inline-edit"`, source `registry/cobalt/ui/inline-edit.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Input` for the field, with a hand-rolled reading button. Traps checked: `trap/field-label`, `trap/label-unbound`, `trap/field-input-type`, `trap/field-error-link`, `trap/field-error-timing`, `trap/field-keeps-input`, `trap/field-form-enter`, `trap/touch-input-zoom`, `trap/touch-autofocus`, `trap/control-height`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/touch-hover-flash`, `trap/loading-label-swap`, `trap/loading-layout-shift`, `trap/submit-repeat`, `trap/disabled-drops-focus`, `trap/live-region-double`, `trap/toast-errors`, `trap/color-only-status`, `trap/escape-nested`, `trap/reduced-motion-ignored`, `trap/demo-on-timers` (n/a: the examples' waits stand in for a server, and no example steps through states on a timer).

Where each trap is answered. `trap/field-label` and `trap/label-unbound` in ARIA: `label` names the field through `aria-label` and starts the reading button's name, so there is no `<label>` to bind. `trap/field-input-type` in Props: `inputMode` passes through, `autocomplete` is off, and `maxLength` passes through. `trap/field-error-link` in ARIA: a refused field gets `aria-invalid` and `aria-describedby` on its message. `trap/field-error-timing` in States: a check runs on Enter or on leaving the field, never on a keystroke, and typing clears its message. `trap/field-keeps-input` in States: a failed save and a refused check keep the words. `trap/field-form-enter` in Keyboard: Enter is taken by the field (`preventDefault`), so a form around it does not submit. `trap/touch-input-zoom` in Tokens: on a coarse pointer the words are at least `--type-base`. `trap/touch-autofocus` in Keyboard: the field opens only on a press. `trap/control-height` in States: the box is `--control` tall in both modes. `trap/focus-ring-shape` and `trap/hover-beats-focus` in States: the reading button draws its ring inside the box (`data-focus="custom"`), and the field draws `field-focus` after Tab. `trap/disabled-still-hovers` n/a: read only renders a `span` with no hover. `trap/touch-hover-flash` in Tokens: the hover fill sits behind the guarded `hover` variant. `trap/loading-label-swap` and `trap/loading-layout-shift` in States: the words stay while a save is pending, the spinner sits in room kept at the box's end, and nothing outside the box moves. `trap/submit-repeat` in States: a press while pending does nothing. `trap/disabled-drops-focus` in Keyboard: Retry moves focus to the value before it leaves. `trap/live-region-double` in ARIA: one status line per box, and the spinner and check are `aria-hidden`. `trap/toast-errors` in `rule/inline-edit-reject-on-failure`. `trap/color-only-status` in States: "Not saved" is written and Retry has its glyph. `trap/escape-nested` in Keyboard: Escape in the field stops there. `trap/reduced-motion-ignored` in Motion.

### Foundation

| Given by the foundation                                      | Added by the team                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Base UI `Input`: the native input, its value and its events | A reading mode, a native `button` named "{label}, {value}" that shows the value in the host's type; one box for both modes, `--control` tall with 8px of padding at each side, that reaches 8px past the words and past their line above and below (`registry/cobalt/ui/inline-edit.tsx:292`), so the words line up with the text around them; a press puts the caret where it landed, and Enter, Space or F2 opens the field with every word selected; Enter or leaving saves, Escape puts the saved value back; `commitDraft()`, which decides before anything is sent whether the trimmed words are unchanged, emptied while `required`, refused by `validate`, or saved; an honest save: the new words stay with `aria-busy`, a spinner after `useSlowWait`'s 250ms held at least 400ms, a check in `--good` for `RESULT_HOLD_MS`, 1.5 seconds, and on failure the unsaved words on the red wash with "Not saved" and Retry; a check's message at the box's end, whose width is measured and kept clear of the words, up to half the box; one status line; `inlineEditLabels` for every string it speaks; read only as plain text |

## Examples

A watchlist's name in its page header. Press it, or Tab to it and press Enter, to rename it in place.

Real uses, 0 call sites (`rg -n "<InlineEdit\b" app registry --glob '!registry/cobalt/ui/*'`): no showcase page draws one outside its examples yet, and the examples folder does not count.

Uses inside the registry: none. `registry/cobalt/ui/inline-edit.test.tsx` renders it for the tests, and `docs/system/stress/inline-edit.tsx` puts it in a page title, a list of facts and a narrow cell.

### Example files

| File                                                | Covers                 | Caption                                                                                                                                                                         |
| --------------------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `docs/system/examples/inline-edit/default.tsx`      | default                | A watchlist's name in its page header. Press it, or Tab to it and press Enter, to rename it in place; Enter or leaving the field saves and Escape puts the old name back        |
| `docs/system/examples/inline-edit/failed.tsx`       | state:failure          | A rename the server turns down. The box keeps the name that was not saved on the red wash, with Not saved and Retry at its end. The first save here fails                       |
| `docs/system/examples/inline-edit/validate.tsx`     | state:invalid          | One figure in a record. The check refuses what is not a percentage between 0 and 100, and the field stays open with the reason at its end                                      |
| `docs/system/examples/inline-edit/in-data-list.tsx` | state:disabled         | Notes is read only, plain text in the value column                                                                                                                              |
| `docs/system/examples/inline-edit/in-data-list.tsx` | composition:DataList   | A saved search's details, each value edited in place. The words line up with the labels' column, and the field's fill reaches past them                                         |

Example: A watchlist's name in its page header. Press it, or Tab to it and press Enter, to rename it in place; Enter or leaving the field saves and Escape puts the old name back (`docs/system/examples/inline-edit/default.tsx`)

```tsx
import { useState } from "react";

import { InlineEdit } from "@/components/cobalt/ui/inline-edit";

// Stands in for the request that renames the watchlist.
const rename = (name: string) => new Promise<string>((resolve) => setTimeout(() => resolve(name), 700));

export default function Example() {
  const [name, setName] = useState("Large cap core");
  return (
    <header className="flex w-full max-w-md flex-col gap-1">
      <h1 className="text-xl font-semibold tracking-tight">
        <InlineEdit
          label="Watchlist name"
          value={name}
          maxLength={80}
          onSave={async (next) => setName(await rename(next))}
        />
      </h1>
      <p className="text-sm text-muted-foreground">24 funds, updated daily</p>
    </header>
  );
}
```

Example: A saved search's details, each value edited in place. The words line up with the labels' column, and the field's fill reaches past them (`docs/system/examples/inline-edit/in-data-list.tsx`)

```tsx
import { useState } from "react";

import { DataList, DataListItem, DataListLabel, DataListValue } from "@/components/cobalt/ui/data-list";
import { InlineEdit } from "@/components/cobalt/ui/inline-edit";

const save = () => new Promise((resolve) => setTimeout(resolve, 600));

export default function Example() {
  const [search, setSearch] = useState({ name: "Hedge funds over $1B", owner: "Ada Park", purpose: "Quarterly review of large managers" });
  const field = (key: keyof typeof search, label: string) => (
    <InlineEdit
      label={label}
      value={search[key]}
      onSave={async (next) => {
        await save();
        setSearch((now) => ({ ...now, [key]: next }));
      }}
    />
  );
  return (
    <DataList orientation="stacked" className="w-full max-w-sm">
      <DataListItem>
        <DataListLabel>Name</DataListLabel>
        <DataListValue>{field("name", "Name")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Owner</DataListLabel>
        <DataListValue>{field("owner", "Owner")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Purpose</DataListLabel>
        <DataListValue>{field("purpose", "Purpose")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Notes</DataListLabel>
        <DataListValue>
          <InlineEdit label="Notes" value="Shared with the credit team" disabled onSave={() => {}} />
        </DataListValue>
      </DataListItem>
    </DataList>
  );
}
```

## Variants

Not applicable: InlineEdit has one look, and it takes the type of the element around it. `required`, `validate` and `disabled` change what it does, shown in States.

## States

| State         | Trigger                                                         | What the user can do                                                                             | Shown by, besides color                                                                                                                                                                                                          | Checked by         |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| reading       | rendered, not `disabled`                                        | press it, or Tab to it and press Enter, Space or F2                                              | the value in the host's type, 8px in from the box's start; the text cursor (measured: the box 36px tall while an `h1` with a 28px line stays 28px tall)                                                                         | test and by hand   |
| hover         | the pointer over the reading box, under `(hover: hover)`        | press it to edit                                                                                 | the field's fill at 50 percent behind the words; nothing moves                                                                                                                                                                   | by hand            |
| focus-visible | Tab onto the reading box                                        | Enter, Space or F2 to edit                                                                       | a 2px ring drawn inside the box (measured `inset 0 0 0 2px`), so it never reaches the line above or below                                                                                                                       | by hand            |
| editing       | a press, or Enter, Space or F2 on the reading box               | type; Enter or leaving saves; Escape puts the saved value back                                   | the same box as a field with its 50 percent fill; the caret where the press landed, or every word selected from the keys; the accent edge after Tab (measured: the box keeps its y, 36px height and 464px width, words 8px in) | by hand            |
| empty         | `value` is ""                                                   | press it to add a value                                                                          | `placeholder`, or "Empty", in the muted ink; the button named "{label}, Empty"                                                                                                                                                  | test               |
| unchanged     | Enter or leaving with the saved words, or with none while `required` | nothing to do                                                                                    | the saved value again; nothing is sent and nothing is read                                                                                                                                                                       | test               |
| pending       | changed words are sent through `onSave`                         | wait; a press does nothing                                                                       | the new words stay; `aria-busy`; the progress cursor; after 250ms a spinner at the box's end, held at least 400ms; "Saving" read once (measured: no spinner at 30ms, a spinner at 330ms)                                       | by hand            |
| success       | `onSave` resolves                                               | press it to edit again                                                                           | a check at the end for 1.5 seconds, once the spinner's minimum has passed; "Saved" read once; then `value`                                                                                                                      | by hand            |
| failure       | `onSave` rejects or throws                                      | press the words to edit them, press Retry, or press Escape to put the saved value back           | the unsaved words on the red wash; "Not saved" and a Retry glyph button at the end; the button described by "Not saved", which is read once                                                                                     | by hand            |
| invalid       | `validate` returns a message on Enter, or on leaving the field  | fix the words or press Escape; once left, press the words to edit them again or press Escape    | on Enter the field stays open with `aria-invalid`, the red wash and the message at its end; once left, the words and the message on the red wash; the message read once when it appears (measured "0 to 100" in the status line after Enter) | test and by hand   |
| disabled      | `disabled`                                                      | read it                                                                                          | plain text in a `span`, with no button, no hover and no tab stop                                                                                                                                                                 | test               |

Example: A rename the server turns down. The box keeps the name that was not saved on the red wash, with Not saved and Retry at its end. The first save here fails (`docs/system/examples/inline-edit/failed.tsx`)

```tsx
import { useRef, useState } from "react";

import { InlineEdit } from "@/components/cobalt/ui/inline-edit";

export default function Example() {
  const [name, setName] = useState("Credit funds");
  const tries = useRef(0);
  // Stands in for a request that fails the first time and goes through after.
  const rename = (next: string) =>
    new Promise<void>((resolve, reject) =>
      setTimeout(() => {
        if ((tries.current += 1) === 1) reject(new Error("offline"));
        else {
          setName(next);
          resolve();
        }
      }, 600),
    );
  return (
    <div className="w-full max-w-sm text-base font-medium">
      <InlineEdit label="Watchlist name" value={name} onSave={rename} />
    </div>
  );
}
```

Example: One figure in a record. The check refuses what is not a percentage between 0 and 100, and the field stays open with the reason at its end (`docs/system/examples/inline-edit/validate.tsx`)

```tsx
import { useState } from "react";

import { InlineEdit } from "@/components/cobalt/ui/inline-edit";

export default function Example() {
  const [weight, setWeight] = useState("12.5");
  return (
    <dl className="flex w-full max-w-sm items-center justify-between gap-4 text-sm">
      <dt className="text-muted-foreground">Target weight, percent</dt>
      <dd className="w-32 tabular-nums">
        <InlineEdit
          label="Target weight, percent"
          value={weight}
          inputMode="decimal"
          validate={(next) => {
            const n = Number(next);
            return Number.isFinite(n) && n >= 0 && n <= 100 ? null : "0 to 100";
          }}
          onSave={(next) => new Promise<void>((resolve) => setTimeout(() => (setWeight(next), resolve()), 500))}
        />
      </dd>
    </dl>
  );
}
```

Example: Notes is read only, plain text in the value column (`docs/system/examples/inline-edit/in-data-list.tsx`)

```tsx
import { useState } from "react";

import { DataList, DataListItem, DataListLabel, DataListValue } from "@/components/cobalt/ui/data-list";
import { InlineEdit } from "@/components/cobalt/ui/inline-edit";

const save = () => new Promise((resolve) => setTimeout(resolve, 600));

export default function Example() {
  const [search, setSearch] = useState({ name: "Hedge funds over $1B", owner: "Ada Park", purpose: "Quarterly review of large managers" });
  const field = (key: keyof typeof search, label: string) => (
    <InlineEdit
      label={label}
      value={search[key]}
      onSave={async (next) => {
        await save();
        setSearch((now) => ({ ...now, [key]: next }));
      }}
    />
  );
  return (
    <DataList orientation="stacked" className="w-full max-w-sm">
      <DataListItem>
        <DataListLabel>Name</DataListLabel>
        <DataListValue>{field("name", "Name")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Owner</DataListLabel>
        <DataListValue>{field("owner", "Owner")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Purpose</DataListLabel>
        <DataListValue>{field("purpose", "Purpose")}</DataListValue>
      </DataListItem>
      <DataListItem>
        <DataListLabel>Notes</DataListLabel>
        <DataListValue>
          <InlineEdit label="Notes" value="Shared with the credit team" disabled onSave={() => {}} />
        </DataListValue>
      </DataListItem>
    </DataList>
  );
}
```

### State precedence

- Pending and a press: pending wins. The press does nothing until the save answers.
- Pending and editing: Not applicable: the field cannot open while a save is pending.
- Pending and a new `value` from elsewhere: pending wins. The box keeps the words being saved until the answer.
- Failure or invalid and a new `value` from elsewhere: failure or invalid wins. The unsaved words stay until they are saved or put back with Escape.
- Success and a new `value`: success wins for 1.5 seconds, showing the words just saved, then the box shows `value`.
- Spinner and the success check: the spinner wins until its 400ms minimum ends, then the check shows. The two never show together.
- Hover and failure or invalid: failure or invalid wins. The red wash stays and the hover adds no fill.
- Focus-visible and failure: both show. The ring is drawn inside the box over the red wash.
- Editing and invalid: both show. The field stays open on the red wash with the message at its end.
- Disabled and every other state: disabled wins. No save can start.

### Motion

| Trigger                                   | Kind     | Preset                                            | Properties       | Reduced motion                                     |
| ----------------------------------------- | -------- | ------------------------------------------------- | ---------------- | -------------------------------------------------- |
| the pointer enters or leaves the box      | input    | `duration-press`, `--t-press` 140ms on `--curve`  | background-color | the same fade                                      |
| the field is reached with Tab             | input    | `duration-press`, `--t-press` 140ms on `--curve`  | box-shadow       | the same fade                                      |
| a slow save shows or hides its spinner    | announce | `duration-fade`, `--t-fade` 150ms on `--curve`    | opacity          | the same fade                                      |
| the spinner turns                         | announce | `animate-spin`                                    | rotate           | the spin stops and the still glyph stays           |
| the check shows, and leaves 1.5s later    | announce | `duration-fade`, `--t-fade` 150ms on `--curve`    | opacity          | the same fade                                      |

## Props

<!-- Props generated from registry/cobalt/ui/inline-edit.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `label` | `string` |  | What the value is, such as "Watchlist name": the field's name and the start of the button's. |
| `onSave` | `(next: string) => void \| Promise<unknown>` |  | Sends the new value. |
| `value` | `string` |  | The saved value. |
| `className?` | `string` |  | Placement only. |
| `disabled?` | `boolean` | `false` | Read only: the value shows and cannot be edited. |
| `inputMode?` | `"search" \| "text" \| "none" \| "tel" \| "url" \| "email" \| "numeric" \| "decimal"` |  |  |
| `labels?` | `Partial<{ value: (label: string, value: string) => string; empty: string; saving: string; saved: string; failed: string; retry: string; retryFor: (label: string) => string; }>` |  |  |
| `maxLength?` | `number` |  |  |
| `placeholder?` | `string` |  | Shown while the value is empty. |
| `required?` | `boolean` | `true` | An empty value reverts to the saved one instead of saving. |
| `validate?` | `(next: string) => string` |  | Says what is wrong with the trimmed words, in a few words, or nothing when they can be saved. |

`value` is the saved value; set it when a save succeeds. `onSave` sends the trimmed words; resolve when they are saved, reject or throw when they are not. `label` says what the value is, such as "Watchlist name": it names the field and starts the reading button's name. `placeholder` shows while the value is empty. `required`, on by default, reverts an emptied value instead of saving it. `validate` returns a message that fits half the box (Limits), or nothing when the words can be saved. `disabled` shows the value as plain text. `maxLength` and `inputMode` pass to the input. `labels` replaces any string from `inlineEditLabels`. `className` is for placement only; the words take the type of the element around them. `commitDraft()` is the decision Enter and leaving make, exported for a host that needs the same answer.

## Usage

### When to use

- One value on a record's page that its owner renames or corrects now and then, such as a watchlist's name in its header or one detail in a list of a saved search's details.
- A value that saves on its own, in one request, when the person presses Enter or leaves the field.

### When not to use

- Several values that are saved together, or are checked before they go. Use Field instead, with Input in a form and one Save.
- A value picked from a fixed set, such as how often an alert runs. Use Select instead.
- Text that runs to more than one line, such as a note. Use Textarea instead.
- A number a person steps up and down, or whose bounds hold while typing. Use NumberField instead.

### Rules

- `rule/inline-edit-update-value`: When `onSave` resolves, set `value` to the saved words in the same handler instead of leaving it as it was, because the box shows the words just saved only while the check holds, 1.5 seconds, and then shows `value` again, so a `value` left behind puts the old words back under a check that said Saved. Evidence: single use docs/system/examples/inline-edit/default.tsx:18, where `onSave` sets the name it saved, as every example does; principle heuristic: visibility of system status, a value shown after Saved must be the saved one. Check: review of every `onSave` passed to `InlineEdit`.
  - Don't: `<InlineEdit label="Owner" value={owner} onSave={(next) => api.saveOwner(next)} />`
  - Do: `<InlineEdit label="Owner" value={owner} onSave={async (next) => setOwner(await api.saveOwner(next))} />`
- `rule/inline-edit-reject-on-failure`: When the request behind `onSave` fails, let `onSave` reject or throw instead of catching the error and calling `toast()`, because a rejection is what keeps the words on the red wash with "Not saved" and Retry, and a caught error resolves, so the box shows Saved for words the server did not keep. Evidence: person D39; principle heuristic: help users recognize, diagnose and recover from errors, the failure stays where the words are. Check: review of every `try` inside an `onSave`.
  - Don't: `onSave={async (next) => { try { await rename(next) } catch { toast("Could not rename") } }}`
  - Do: `onSave={async (next) => setName(await rename(next))}`
- `rule/inline-edit-type-from-host`: When the value needs a size or a weight, set it on the element around `InlineEdit`, such as the `h1`, instead of `className`, because the box takes the host's type and line to keep the words where plain text would sit and to take the room of one line, and `className` is for placement. Evidence: person D4; measured an `h1` with a 28px line staying 28px tall around a 36px box, with the words 8px in from the box (Playwright on /components/inline-edit). Check: review of every `className` passed to `InlineEdit`.
  - Don't: `<InlineEdit className="text-xl font-semibold" label="Watchlist name" value={name} onSave={rename} />`
  - Do: `<h1 className="text-xl font-semibold"><InlineEdit label="Watchlist name" value={name} onSave={rename} /></h1>`
- `rule/inline-edit-label-matches`: When a visible label names the value, such as a `DataListLabel`, pass the same words as `label` instead of a verb such as "Edit", because `label` is the field's only name and the start of the button's name, "{label}, {value}", and speech input users say the words they see. Evidence: principle wcag: 2.5.3 Label in name; single use docs/system/examples/inline-edit/in-data-list.tsx:24-25. Check: review of every `InlineEdit` beside a visible label.
  - Don't: `<DataListLabel>Owner</DataListLabel><DataListValue><InlineEdit label="Edit" value={owner} onSave={save} /></DataListValue>`
  - Do: `<DataListLabel>Owner</DataListLabel><DataListValue><InlineEdit label="Owner" value={owner} onSave={save} /></DataListValue>`

### Content

- Follows `rule/writing-field-label-noun`.
- Follows `rule/field-error-names-the-fix`.
- `rule/inline-edit-message-names-the-range`: When `validate` refuses the words, return what it takes, such as "0 to 100" or "Use a number", instead of "Invalid" or "Error", because the message is the only thing at the box's end and is read as the field's description, and a person fixes the words from it. Evidence: principle heuristic: help users recognize, diagnose and recover from errors; single use docs/system/examples/inline-edit/validate.tsx:18. Check: review of every `validate` passed to `InlineEdit`.
  - Don't: `validate={(next) => (Number.isFinite(Number(next)) ? null : "Invalid")}`
  - Do: `validate={(next) => (Number.isFinite(Number(next)) ? null : "Use a number")}`

### Anti-slop

- `rule/inline-edit-no-pencil-swap`: When a value can be edited in place, render `InlineEdit` instead of the value beside a pencil `IconButton` that swaps in an `Input`, because the value itself is the button, one tab stop named "{label}, {value}", and its box keeps its place between reading and editing, where a pencil adds a second target and the swap moves the words. Evidence: person D37; measured the box at the same y, 36px height and 464px width in both modes, with the words 8px in (Playwright on /components/inline-edit). Check: review of every pencil glyph beside a value.
  - Don't: `{editing ? <Input value={name} onChange={change} /> : <span>{name}</span>}<IconButton label="Edit name"><PencilIcon /></IconButton>`
  - Do: `<InlineEdit label="Watchlist name" value={name} onSave={rename} />`
- `rule/inline-edit-no-save-buttons`: When a value is edited in place with `InlineEdit`, let Enter or leaving the field save and Escape put the value back, instead of adding "Save" and "Cancel" buttons beside the field, because the box keeps its end for the save's spinner, check and Retry, and buttons beside it widen the row and move what follows. Evidence: principle platform: a file name renamed in place in the macOS Finder saves on Return or a click away and reverts on Escape; person D37. Check: review of every `Button` rendered beside an `InlineEdit`.
  - Don't: `<InlineEdit label="Name" value={name} onSave={rename} /><Button>Save</Button><Button variant="ghost">Cancel</Button>`
  - Do: `<InlineEdit label="Name" value={name} onSave={rename} />`

### Limits

- `rule/inline-edit-message-length`: When an `InlineEdit` with `validate` sits in a column under 160px wide, keep its message to 8 characters, such as "0 to 100", instead of a phrase, because the message takes at most half the box, less 4px, and is cut past it, so in a 144px box "0 to 100" fits while "Use a number", 12 characters, does not. Evidence: measured by setting the message's text in the validate example's 144px box on /components/inline-edit (Playwright, 1440 wide): 68px of room, "0 to 100" at 46px whole, "Use 0 to 100" at 70px and "Use a number" at 76px cut; measured "Not a number" cut from 74px to 52px in the 112px Weight box on /stress/inline-edit; measured a 47-character message cut at 200px, half of a 400px box, with the words stopping short of it. Check: review of every `validate` passed to an `InlineEdit` in a column under 160px.
  - Don't: `<dd className="w-32"><InlineEdit label="Target weight" value={weight} validate={(n) => (inRange(n) ? null : "Use a number from 0 to 100")} onSave={save} /></dd>`
  - Do: `<dd className="w-32"><InlineEdit label="Target weight" value={weight} validate={(n) => (inRange(n) ? null : "0 to 100")} onSave={save} /></dd>`

## Accessibility

Rests on a native `button` for reading and Base UI `Input`, a native `input`, for editing. The read-only form is plain text. Screen reader pass with VoiceOver: NEEDS REVIEW.

### Keyboard

| Key              | Where focus is                               | Effect                                                                                     | Focus after                                                                             | Checked by |
| ---------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | ---------- |
| Tab              | before the value                             | focuses the reading button and draws its ring inside the box                               | the reading button                                                                      | by hand    |
| Enter or Space   | the reading button                           | opens the field with every word selected                                                   | the field                                                                               | by hand    |
| F2               | the reading button                           | opens the field with every word selected                                                   | the field                                                                               | by hand    |
| Enter            | the field                                    | saves changed words, puts back unchanged or emptied ones, or shows the check's message     | the reading button; the field when the check refuses                                    | by hand    |
| Escape           | the field                                    | puts the saved value back, and stops there, so a dialog around it stays open               | the reading button                                                                      | by hand    |
| Tab              | the field                                    | leaves the field, which saves; a refused value stays on the red wash with its message     | the next control                                                                        | by hand    |
| Escape           | the reading button, holding unsaved words    | puts the saved value back                                                                  | stays on the reading button                                                             | by hand    |
| Enter or Space   | Retry                                        | sends the unsaved words again                                                              | the reading button, which Retry focuses before it leaves (`registry/cobalt/ui/inline-edit.tsx:409-413`) | by hand    |

### ARIA

| Part              | Role                 | Accessible name from                                                  | States and properties                                                                                     | Announced                                                                                                              | Checked by         |
| ----------------- | -------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------ |
| reading button    | button               | `aria-label` from `labels.value`, "{label}, {value}", or "{label}, Empty" | `aria-busy` while pending; `aria-describedby` the message while it holds unsaved words                    | "Watchlist name, Large cap core, button"                                                                               | test               |
| field             | textbox              | `aria-label` from `label`                                             | `aria-invalid` and `aria-describedby` the message when the check refuses; `autocomplete="off"`            | the label and the words                                                                                                | by hand            |
| status line       | status               | its text                                                              | visually hidden; empty at rest                                                                            | "Saving", "Saved", "Not saved", or the check's message when it appears, once each                                       | test and by hand   |
| Retry             | button               | `aria-label` from `labels.retryFor`, "Retry saving {label}"           | none                                                                                                      | "Retry saving Watchlist name, button"                                                                                  | by hand            |
| spinner and check | none, `aria-hidden`  | none                                                                  | none                                                                                                      | nothing                                                                                                                | by hand            |
| read-only value   | none, plain text     | its text                                                              | none                                                                                                      | the text                                                                                                               | test               |

## Tokens

| Part                   | State                       | Token                                                            |
| ---------------------- | --------------------------- | ---------------------------------------------------------------- |
| box                    | all                         | `--control`, `--r-control`                                       |
| box                    | hover, editing              | `--input`, at 50 percent                                         |
| box                    | failure, invalid            | `--destructive`, at 10 percent                                   |
| words on a coarse pointer | all                      | `--type-base`, as the least size                                 |
| empty value, placeholder | empty                     | `--muted-foreground`                                             |
| reading ring           | focus-visible               | `--ring`                                                         |
| field edge             | editing, after Tab          | `--primary`, and `--destructive` when invalid, through `field-focus` |
| message                | failure, invalid            | `--destructive`                                                  |
| check                  | success                     | `--good`                                                         |
| fills and fades        | all                         | `--t-press`, `--t-fade`, `--curve`                               |

## Related

- Field: several values saved together with one Save, or checked before they go.
- SaveLine: the save state of a form or a document that saves as it is edited.
- StateButton: an action that reports its own request in its button.
- DataList: the list of a record's details an InlineEdit often sits in.
- Select: a value picked from a fixed set.
- NumberField: a number with steps and bounds.
