Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Forms

InlineEdit

Edits one value in place: Edit swaps the text for a labelled field with Save and Cancel, checks native constraints, and returns focus to Edit.

Frameworks
Astro · React · Elements · Dioxus
Registry
lumen add InlineEdit
Interaction
Enhanced runtime
01

See it and copy it

Framework example

Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro

Atlas

Add a short description
View InlineEdit code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.
astro
---
import { InlineEdit, Stack } from '@santi020k/lumen-astro'
---

<Stack data-ex-inline-edit gap="group">
  <InlineEdit headingLevel={3} label="Project name" maxLength={80} name="projectName" required value="Atlas" />
  <InlineEdit label="Description" multiline name="description" placeholder="Add a short description" />
</Stack>

<script>
  import type { LumenInlineEditChangeDetail } from '@santi020k/lumen-core'

  const isProjectChange = (event: Event): event is CustomEvent<LumenInlineEditChangeDetail> =>
    event instanceof CustomEvent &&
    event.target instanceof HTMLElement &&
    event.target.closest('[data-ex-inline-edit]') !== null

  // Illustrative only: a real app sends detail.name and detail.value to its server and rejects on failure.
  const saveChange = (detail: LumenInlineEditChangeDetail): Promise<string> =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve(detail.value)
      }, 300)
    })

  document.addEventListener('ui:inline-edit-change', event => {
    if (!isProjectChange(event)) return

    const { revert } = event.detail

    // Show the previous value again when the request fails.
    saveChange(event.detail).catch(() => {
      revert()
    })
  })
</script>
Edit InlineEdit in browser

Framework differences

React: Pass value with onValueChange to control the saved value, or defaultValue to start uncontrolled. onValueChange receives (value, { name, previousValue, preventDefault() }); call preventDefault() to keep the editor open, and set value back to previousValue when a later request fails.

Elements: Register it with defineLumenElements(['InlineEdit']). Read or set the saved value through the value property, call open() or cancel() from script, and listen for ui:inline-edit-change on the element.

02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add InlineEdit

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
labelstringrequiredNames the field, the Edit button ("Edit {label}"), and the saved announcement ("{label} saved.").
valuestring""The saved value. Read mode shows it as plain text, so it stays readable without JavaScript. Elements also reads and sets it through the value property.
value / defaultValuestring""Pass value with onValueChange to control the saved value, or defaultValue to start uncontrolled. To undo a failed save, set value back to the previous value.
namestring-The field name, also sent as name with each change.
required, maxLength, patternboolean, number, string-Native constraints, checked on Save after surrounding spaces are trimmed. An invalid value keeps the editor open and shows the message under the field. pattern applies to single-line fields only. Elements uses maxlength.
placeholderstring-Hint in the empty field. Read mode shows it in a muted style while the value is empty.
multilinebooleanfalseEdits with a Textarea. Enter adds a line; Control+Enter or Command+Enter saves.
headingLevel1 | 2 | 3 | 4 | 5 | 6-Renders the read-mode value as a heading of this level, for example an editable page title. Elements uses heading-level.
labelsPartial<LumenInlineEditLabels>Edit {label}, Save, Cancel, {label} saved.Localizes the Edit, Save, and Cancel buttons and the saved announcement. {label} becomes the field label. Elements uses edit-label, save-label, cancel-label, and saved-label.
onValueChange(value: string, details: { name: string; previousValue: string; preventDefault(): void }) => void-Runs for a valid value that differs from the saved one. Call details.preventDefault() to keep the editor open. The application saves the value.
ui:inline-edit-changeCustomEvent<{ name: string; previousValue: string; value: string; revert(): void }>-Cancelable bubbling event for a valid, changed value. Call preventDefault() to keep the editor open, or detail.revert() to show the previous value again when a later request fails.
data-error-required, data-error-patternstringbrowser messageSet on the InlineEdit root to replace the browser message for that constraint. The other data-error-* names that Field reads work the same way.
open(), cancel()methods-Opens the editor, or cancels it and restores the saved value, from script.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Customize InlineEdit

Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.

cssScoped theme overrides
.product-inline-edit {
  --surface: 0 0% 100%;
  --ink: 220 20% 15%;
  --line: 220 15% 82%;
}

Apply product-inline-edit through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.

Documented styling parts: inline-edit inline-edit-view inline-edit-value inline-edit-trigger inline-edit-editor inline-edit-control inline-edit-error inline-edit-actions

HookValuesDefaultContract
data-error-required, data-error-patternstringbrowser messageSet on the InlineEdit root to replace the browser message for that constraint. The other data-error-* names that Field reads work the same way.
class, classNamestring""Merges custom classes with the generated ui-* root classes.

Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope

Keyboard interactions

Keyboard behavior provided by the Astro UIPrimitives runtime for this component.

KeyAction
Enter, Space on EditOpen the editor and focus the field. A single-line field selects its text; a multiline field puts the caret at the end.
TabMove between the field, Save, and Cancel.
Enter in a single-line fieldSave the value.
Control+Enter, Command+Enter in a multiline fieldSave the value. Enter alone adds a new line.
Escape in the editorCancel, restore the saved value, and return focus to Edit.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:inline-edit-changeInlineEdit root ([data-ui-inline-edit] or lumen-inline-edit)LumenInlineEditChangeDetail: { name: string, previousValue: string, value: string, revert(): void }Cancelable. Bubbles when Save or Enter commits a valid value that differs from the saved one. Call preventDefault to keep the editor open. Otherwise the new value shows, focus returns to Edit, and the status announces it. Save detail.value in the application and call detail.revert() if that request fails. React uses onValueChange instead.

Web docsFull catalog