Value that becomes its own field in place: the tile morphs into a rimmed input, the edit ball rolls to Save and traces a check.
Press mePress me
Platform · Ticket #4821
Assignee
ALAlex Lind
Priority
High
Estimate
Description
inline-edit · , lively
inline-edit-demo.tsx
When to use
Use for values read far more often than changed, edited where they are read. Presets include cell (table) and block (textarea). Supports async save and validate; Enter saves, Escape reverts.
When not to use
For forms where every field is edited together use Form or Text Field. For a value picked from a list use Combobox.
Use it for values that are read far more often than they are changed, edited where they are read: a ticket
title, a quantity in a table, an estimate, a description. For forms where every field is edited together,
use a text field. For a value picked from a list, use a combobox or a select.
The value sits in a quiet tile with a small pencil ball at its trailing end. Pressing it sinks the tile
(charge). The tile then morphs into the field, 4 px larger on every side, while the text stays exactly
where it was and becomes a real input; the pencil ball rolls along the trailing edge to the field's end and
turns into the Save ball, and Cancel comes out of it (action). Saving contracts the field back onto the
value while a check traces inside the ball, which rolls home and becomes the pencil again (settle).
import { InlineEdit } from "@/components/ui/inline-edit"export function TicketTitle({ ticket }: { ticket: Ticket }) { return ( <InlineEdit label="Title" defaultValue={ticket.title} validate={(value) => (value.trim() ? undefined : "A ticket needs a title")} onSave={(title) => api.updateTicket(ticket.id, { title })} className="text-base font-semibold" /> )}
value and onValueChange control the value; defaultValue leaves it uncontrolled. onValueChange runs
once the value is saved, not on every keystroke. When onSave returns a promise the field stays open, the
Save ball breathes until it settles, and a rejection keeps the field open with the error's message.
validate returns a message to keep the field open. The font, size and weight come from the root, so
className sets the type for both the value and the input.
Three layout presets share one look and one motion:
<InlineEdit preset="text" /> {/* one line, Save and Cancel balls inside the field (default) */}<InlineEdit preset="cell" /> {/* table cell: pencil on hover and focus, Tab saves and moves on */}<InlineEdit preset="block" /> {/* multiline, grows with its content, actions in a row below */}
format changes how the resting value reads (3 becomes 3h) while the input edits the raw value.
The cell preset keeps the row height: the field draws over the cell, 4 px outside it, and the pencil only
appears on hover and focus. Enter saves, Tab saves and moves to the next quantity, Escape reverts. Cells
never bounce and never sink, whatever the temperament.
The block preset edits several lines in a textarea that grows with its content. Cmd/Ctrl + Enter saves,
and while the request runs the Save ball keeps its check and breathes.
The value is a <button> named Edit {label}: {value}. Activating it moves focus to the input, named
label, with its text selected.
Errors set aria-invalid on the input and are linked with aria-describedby; a polite live region
announces "Saved", "Saving" and errors.
Save and Cancel are real 24 px buttons reachable with Tab; moving focus between them does not save.
Focus leaving the field saves (or reverts with saveOnBlur={false}). Clicking Cancel never triggers a
blur save.
The resting pencil ball is 20 px inside a 24 px hit area; it is decorative for assistive technology, the
value button is the way in.
The focus halo (ring-[3px] ring-ring/50) shows on the value button and, when opened from the keyboard,
on the field. ring is used only for focus; the Save ball and its check use primary.
disabled keeps the value visible in muted-foreground with no ball; readOnly renders plain text.
Cancels: the field contracts and the value is unchanged
Tab
Moves to Cancel and Save; leaving the field saves
Tab / Shift + Tab (cell)
Saves and moves to the next or previous control
Your onKeyDown runs first: call event.preventDefault() to skip the component's Enter and Escape
handling. onClick (on the value) and onBlur (on the input) are composed, never replaced.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") the tile and the field
crossfade in place with no sink, the ball glides to its stop without squash, and the check fades in instead
of tracing. The rest pose, the rim and the error line are the same.
The morph is a shared-layout flight of one surface (transform only); its 1 px rim is counter-scaled
every frame so it never thickens. The text is never scaled: value and input share one typography class.
The ball moves on motion values (x, y, scale) on the morph's own transition, so it rides the field's
trailing edge frame by frame; positions are measured with a ResizeObserver, never on every frame.
Nothing animates at rest; the breathing loop runs only while a save is pending and pauses off screen
and in hidden tabs.
Size: our code (component plus ball, beats, morph) stays within the Pro budget; motion is a peer.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
press, keyboard focus, typing
Reduced motion
The value and the field crossfade in place with no sink, the ball glides to its stop without squash, and the check fades in instead of tracing.
Keyboard
Enter / Space (on the value)
Opens the field with the value selected
Enter
Saves (text and cell); in block it adds a line
Cmd/Ctrl + Enter
Saves the block preset
Escape
Cancels: the field contracts and the value is unchanged
Tab
Moves to Cancel and Save inside the field; leaving the field saves (or reverts with saveOnBlur false)
Tab / Shift + Tab (cell)
Saves and moves to the next or previous control
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)