Examples

Rename in place

Validation keeps the field open with the message. An empty value shows the placeholder.

Preview
Example.tsx
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”.

Preview
Example.tsx
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

InlineEdit props
PropTypeDefault
labelrequired
Names the field (visually hidden unless showLabel).
string—
value / defaultValue
string—
onValueChange
Called after a successful save.
(value: string) => void—
onSave
Persist the value; a rejected promise shows its message.
(value) => void | Promise<void>—
onCancel
() => void—
validate
Return a message to block saving.
(value) => string | undefined—
placeholder
Shown when the value is empty.
ReactNode—
multiline
Textarea; Ctrl/⌘ + Enter saves.
booleanfalse
submitOnBlur
Save when focus leaves.
booleantrue
showActions · showLabel
Save/Cancel buttons; a visible label while editing.
booleanfalse
renderView
Custom display of the value.
(value) => ReactNode—
editing / defaultEditing / onEditingChange
Control the mode.
boolean—
disabled · size · messages
messages translates the button names and errors.
—
classNames · styles
root, 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

VariableDefault
--pl-inline-edit-hover-bgvar(--pl-color-bg-subtle)
--pl-inline-edit-padding-inlinevar(--pl-space-2)
--pl-inline-edit-radiusvar(--pl-radius-md)

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
Enter / Space on the valueStart editing
Enter (Ctrl/⌘ + Enter when multi-line)Save
EscapeCancel
Tab awaySave (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.