Design system / Molecules
Molecule / Editing
InlineEditableField
InlineEditableField switches between a supplied display value and editor slot. The caller controls editing, saving, errors and commands. The component supplies label association, activation and save/cancel controls.
Live example
Current component with fictional data. Example changes are not persisted.
A shared language
Save updates only local text. The selector supplies pending/error props; it does not simulate a network request.
Responsibility
Display content, the editor slot, label association and actions form one single-field editing contract. The caller supplies state and commands. Submission editing uses the separate shared batch form defined by ADR-0084.
Public contract
The table describes supported inputs, exported parts and caller responsibilities. A callback supplies a command, such as saving a draft. These notes are maintained manually; check current source types before integration.
| Prop / part | Type | Requirement | Responsibility |
|---|---|---|---|
| label | string | Required | Used in visible labeling and “Edit {label}” accessible name. |
| displayValue | ReactNode | Required | Read-mode content supplied by the consumer. |
| isEditing | boolean | Required | Selects the display or edit branch. |
| saving | boolean | Required | Disables the two actions and changes Save to “Saving...”. |
| error | string | null | Optional | Edit-mode feedback with role="alert". |
| children | ReactNode | Optional | Editor slot. A valid React element receives aria-labelledby through cloning. |
| onStartEdit / onSave / onCancel | () => void | Required | Intent callbacks; the component does not implement persistence. |
| onKeyDown | (event: KeyboardEvent) => void | Required | Consumer keyboard handler attached to the editor region. |
API notes are curated documentation, not generated types. The source linked above is the current implementation; update these notes alongside API changes.
State and behavior
Identify which values the caller controls and which behavior the component or underlying primitive owns. A local example does not supply persistence, authorization or a complete product lifecycle.
Editing, saving, draft data and error are externally supplied. The component generates a label ID and handles Enter/Space activation in read mode. The documentation adapter binds useExampleEditor for local-only editing; no request hook is embedded in the molecule. EditSubmissionForm no longer consumes it after the ADR-0084 batch-editing change.
Dependencies
- React useId, cloneElement, isValidElement
- Lucide Pencil
- Native save/cancel buttons
- Consumer-supplied editor (for example Input)
Token and styling contract
These notes identify theme roles, utilities and direct style values used by the source. Direct colors or timings are implementation exceptions, not recommendations to bypass the theme.
bg-primary / text-primary-foreground- Native Save button consumes action roles.
text-destructive- Edit-mode error text.
text-muted-foreground / border-input- Supporting labels and consumer editor styling.
rounded-md, p-4, text-xs, text-supporting, focus-visible:ring-primary- Source structure, compact label/actions and read-mode focus utilities. Native actions are not imported Button components.
Boundaries and limitations
- No value, onChange, disabled, className or transport prop is exposed by the molecule. These are responsibilities of the editor slot or consumer.
- The source’s action buttons are native buttons, not imports from ui/button. Changes to Button markup do not automatically reach them.
- Saving disables Save and Cancel, but the consumer must separately disable its editor when needed. Label cloning only applies to a valid React element; a custom child must forward the association correctly.
Where to make a change
Change shared editing structure and action styles in inline-editable-field.tsx. Change lifecycle and operation semantics in the owning hook/adapter. Renaming callbacks, changing label cloning or keyboard semantics requires consumer migration. A shared Input style change can reach an Input child, not all possible editor children.
Selected real uses
Documentation InlineEditExample
Uses the real field with useExampleEditor to edit local text and demonstrate pending/error props. The former submission consumer has been replaced by a shared batch form; this preview demonstrates the remaining generic contract, not the current submission workflow.
Repository path: src/app/(public)/design-system/_components/moleculeExamples.tsx
These traces describe selected uses, not every dependency. Repository-only paths are shown as references; only approved files have public source views.
Usage contract
import { InlineEditableField } from "@/components/ui/inline-editable-field";
// Consumer owns these values and commands.
<InlineEditableField
label="Campaign Title" displayValue={<p>{value}</p>}
isEditing={isEditing} saving={saving} error={error}
onStartEdit={startEditing} onSave={save}
onCancel={cancel} onKeyDown={handleKeyDown}
>
<Input value={draft} onChange={e => setDraft(e.target.value)} disabled={saving} />
</InlineEditableField>Illustrative consumer bindings, not a self-contained product workflow. Live examples supply only local state or explicit fictional props.