Editable Text
A title you rename by typing straight into it. There is no edit mode or box: a soft ink wash on hover hints that it can be edited, and once you click in a thin outline marks the field while you type, so the name keeps reading as a title.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Anatomy#
import { EditableText } from "@/components/ui/editable-text"
<EditableText /> // one line: a breadcrumb leaf, a tab, a card title
<EditableText multiline /> // wraps: a page headingPage heading#
With multiline the field wraps like the heading around it, with balanced lines. The wash hugs the longest line instead of filling the column, and Enter saves instead of breaking the line.
Routes new support tickets to the right queue.
Saving#
onValueChange fires once per saved edit, with the trimmed text, never on each keystroke. Escape and an empty edit leave the saved text as it was, so they never call it.
Saved as “Q3 launch plan” · 0 saves
Empty with a placeholder#
For a title that may stay blank, such as a new document, allowEmpty saves an empty edit and the placeholder shows in its place.
Keyboard#
- Tab or a click selects the whole name, ready to retype.
- Enter saves and leaves the field. Leaving it by clicking elsewhere saves too.
- Escape puts back the saved text and leaves the field.
- Focus from the keyboard adds a faint ink edge, so the field can be found without a pointer.
API reference#
EditableText
A native <input> (or a one-row <textarea> with multiline) that inherits the font of its parent, so it takes the type of the heading or label around it. Enter or blur saves the trimmed text, Escape puts back the saved text, and an empty value goes back to the saved one. Forwards input props (aria-label, placeholder, maxLength…). className goes on the wrapper, fieldClassName on the field.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The saved text, controlled. It changes only when an edit is saved, never while typing. |
| defaultValue | string | "" | The saved text when uncontrolled. |
| onValueChange | (value: string) => void | - | Called with the trimmed text when an edit is saved. |
| multiline | boolean | false | Wraps over several lines with balanced breaks, for a page heading. Enter still saves; it never adds a line break. |
| allowEmpty | boolean | false | Lets an empty edit be saved. Pair it with a placeholder. |
| tooltip | ReactNode | - | A hint on hover, such as "Rename". Hidden while editing and on touch. |
| fieldClassName | string | - | Classes for the field itself: its colour, weight and the width it truncates at. |
| disabled | boolean | false | Shows the text without the hover wash and refuses focus. |