Inline Edit
ProNewText that turns into a field where it stands: Enter saves, Escape restores, with async saving and validation.
Installation
pnpm dlx shadcn@latest add @viewport/inline-edit
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| value* | stringThe saved text. | — |
| onSave* | (value: string) => void | Promise<void>Runs when the edit is confirmed. Return a promise to show a saving state; reject it to keep the field open. | — |
| label* | stringWhat is being edited, e.g. "Deal name". Used for the accessible names. | — |
| placeholder | stringShown when the value is empty. | "Empty" |
| validate | (value: string) => string | undefinedReturn a message to block saving, e.g. when the field is required. | — |
| className | string | — |
Accessibility
- The text is a button named after what it edits; the field carries the same name.
- Focus returns to the text after saving or cancelling from the keyboard.
- Errors are announced and keep the field open.
- The field matches the text's box, so nothing around it moves.