Forms
InlineEdit
Text that becomes a field when you activate it, for renaming and quick edits in place. Saves with Enter or when focus leaves, cancels with Escape.
import { InlineEdit } from '@reactloom/ui';Examples
Rename in place
Validation keeps the field open with the message. An empty value shows the placeholder.
import { InlineEdit, Stack } from '@reactloom/ui';
export default function Example() {
return (
<Stack gap="2" style={{ width: '100%', maxWidth: 360 }}>
<InlineEdit label="Project name" defaultValue="Website redesign" validate={(v) => (v.trim() ? undefined : 'Enter a project name.')} />
<InlineEdit label="Owner" placeholder="Add an owner" />
</Stack>
);
}Multi-line and saving to a server
Return a promise from onSave: the field shows progress, and a rejection keeps it open with the error. Try the slug “home”.
import { InlineEdit } from '@reactloom/ui';
// Simulates a server that rejects names already in use.
const saveSlug = (slug: string) =>
new Promise<void>((resolve, reject) =>
setTimeout(() => (slug === 'home' ? reject(new Error('“home” is already used by another page.')) : resolve()), 600),
);
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 420 }}>
<InlineEdit label="Page description" multiline showActions showLabel defaultValue="Pricing for teams of every size." onSave={() => saveSlug('ok')} />
<InlineEdit label="URL slug" defaultValue="pricing" showActions onSave={saveSlug} />
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
labelrequiredNames the field (visually hidden unless showLabel). | string | — |
value / defaultValue | string | — |
onValueChangeCalled after a successful save. | (value: string) => void | — |
onSavePersist the value; a rejected promise shows its message. | (value) => void | Promise<void> | — |
onCancel | () => void | — |
validateReturn a message to block saving. | (value) => string | undefined | — |
placeholderShown when the value is empty. | ReactNode | — |
multilineTextarea; Ctrl/⌘ + Enter saves. | boolean | false |
submitOnBlurSave when focus leaves. | boolean | true |
showActions · showLabelSave/Cancel buttons; a visible label while editing. | boolean | false |
renderViewCustom display of the value. | (value) => ReactNode | — |
editing / defaultEditing / onEditingChangeControl the mode. | boolean | — |
disabled · size · messagesmessages translates the button names and errors. | | — |
classNames · stylesroot, view, viewValue, placeholder, editor and actions. | Partial<Record<InlineEditSlot, …>> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, view, viewValue, placeholder, editor, actions.
CSS variables
| Variable | Default |
|---|---|
--pl-inline-edit-hover-bg | var(--pl-color-bg-subtle) |
--pl-inline-edit-padding-inline | var(--pl-space-2) |
--pl-inline-edit-radius | var(--pl-radius-md) |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-bg-subtle --pl-color-fg-disabled --pl-color-fg-subtle --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-offset --pl-focus-ring-width --pl-font-size-lg --pl-font-size-sm --pl-radius-md
Accessibility
- The value is a button named “Edit <label>: <value>”, so it is reachable with Tab and says what it does.
- While editing, the field has the label, errors are linked with aria-describedby, and focus returns to the value afterwards.
| Key | Action |
|---|---|
| Enter / Space on the value | Start editing |
| Enter (Ctrl/⌘ + Enter when multi-line) | Save |
| Escape | Cancel |
| Tab away | Save (unless submitOnBlur is false) |
Usage guidelines
Do
- Use for single values people change occasionally, like names and titles.
- Show a placeholder that says what to add.
Don’t
- Don’t use for forms with several required fields; use a form with a submit button.
- Don’t rely on blur-saving for destructive changes.