Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Inline Edit

ProNew

Text 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

PropTypeDefault
value*string

The 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*string

What is being edited, e.g. "Deal name". Used for the accessible names.

—
placeholderstring

Shown when the value is empty.

"Empty"
validate(value: string) => string | undefined

Return a message to block saving, e.g. when the field is required.

—
classNamestring—

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.