StartFoundationsComponentsContent

Inline edit

Inline edit shows a value as plain text and turns it into a field when clicked. Use it for a value people mostly read and sometimes change, such as a title.

Stable Figma
OverviewUsageAPIAccessibility
<tk-inline-edit label="title" value="Project Falcon" empty-label="Add a title">
  <tk-input slot="edit" aria-label="Title"></tk-input>
</tk-inline-edit>

Anatomy

Part What it is
tk-inline-edit the element; holds the value and the mode
read view a button that looks like plain text; shows the value or the empty prompt
edit slot one tk-input or tk-textarea, shown while editing
Save and Cancel buttons under a tk-textarea; none under a tk-input

The value stays in place when the view switches.

Saving and cancelling

The field you slot decides how an edit is saved.

You slot Save Cancel Click or tab away
tk-input Enter, or leave the field Esc saves
tk-textarea the Save button the Cancel button or Esc keeps the edit open
<tk-inline-edit label="description" empty-label="Add a description">
  <tk-textarea slot="edit" aria-label="Description" rows="4"></tk-textarea>
</tk-inline-edit>
  • Esc always cancels and restores the value.
  • confirm="buttons" adds Save and Cancel to a tk-input, for settings and account fields.
  • Don't use confirm="blur" with a tk-textarea: a click away would save a half-written text. It logs a console warning.

The edit field

<tk-inline-edit label="display name" value="Ada Lovelace" empty-label="Add your name">
  <tk-input slot="edit" aria-label="Display name" autocomplete="name"></tk-input>
</tk-inline-edit>
  • Put one tk-input or tk-textarea in slot="edit". Other elements get Save and Cancel buttons and log a warning.
  • Give the field its own aria-label, matching label. Don't wrap it in a Field; that adds a second visible label.
  • Don't give the field a name. The inline edit isn't a form field: to submit its value in a form, copy value into a hidden input.

States

<tk-inline-edit label="subtitle" empty-label="Add a subtitle">
  <tk-input slot="edit" aria-label="Subtitle"></tk-input>
</tk-inline-edit>

At rest the value looks like plain text. On hover it gets a light tint, and keyboard focus shows a ring.

  • Empty: with no value, the read view shows empty-label, the only sign the value can be edited. Phrase it as an action.
  • editing: the field is showing. Set it to open the field from code, or to close it after a save.
  • loading: a save is in progress; the edit stays open. The Save button shows a spinner; without buttons, the field becomes read-only.

Validation and saving to a server

inlineEdit.addEventListener('tk-commit', async (e) => {
  e.preventDefault();
  inlineEdit.loading = true;
  try {
    await save(e.detail.value);
    inlineEdit.value = e.detail.value;
    inlineEdit.editing = false;
  } catch {
    toaster.toast("Couldn't save the title. Try again");
  } finally {
    inlineEdit.loading = false;
  }
});
  • tk-commit is cancelable. If you don't cancel it, the value updates and the read view returns. Call preventDefault() to keep the field open while you check or save.
  • Show the problem yourself, such as in a Toast. The inline edit and its field have no error message of their own.
  • For a single-line value, offer an undo, such as a toast with an Undo action, because a click away saves.