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
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.
Atlas
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.---
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>'use client'
import { useState } from 'react'
import { InlineEdit, Stack } from '@santi020k/lumen-react'
// Illustrative only: send the change to your server and reject when the request fails.
const saveProject = async (field: string, value: string): Promise<void> => {
const response = await fetch('/api/project', {
body: JSON.stringify({ [field]: value }),
headers: { 'Content-Type': 'application/json' },
method: 'PATCH'
})
if (!response.ok) throw new Error('Could not save the project.')
}
export function Example() {
const [projectName, setProjectName] = useState('Atlas')
return (
<Stack gap="group">
<InlineEdit
headingLevel={3}
label="Project name"
maxLength={80}
name="projectName"
onValueChange={(value, { name, previousValue }) => {
setProjectName(value)
saveProject(name, value).catch(() => {
// Show the previous value again when the request fails.
setProjectName(previousValue)
})
}}
required
value={projectName}
/>
<InlineEdit label="Description" multiline name="description" placeholder="Add a short description" />
</Stack>
)
}<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements(['InlineEdit', 'Stack'])
</script>
<lumen-stack gap="group">
<lumen-inline-edit
heading-level="3"
label="Project name"
maxlength="80"
name="projectName"
required
value="Atlas"
></lumen-inline-edit>
<lumen-inline-edit
label="Description"
multiline
name="description"
placeholder="Add a short description"
></lumen-inline-edit>
</lumen-stack>
<script type="module">
// Illustrative only: send the change to your server and reject when the request fails.
const saveProject = async (field, value) => {
const response = await fetch('/api/project', {
body: JSON.stringify({ [field]: value }),
headers: { 'Content-Type': 'application/json' },
method: 'PATCH'
})
if (!response.ok) throw new Error('Could not save the project.')
}
document.addEventListener('ui:inline-edit-change', event => {
const { name, revert, value } = event.detail
// Show the previous value again when the request fails.
saveProject(name, value).catch(revert)
})
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let mut title = use_signal(|| "Atlas".to_string());
rsx! {
InlineEdit {
label: "Project name",
max_length: 80,
name: "project_name",
on_value_change: move |change: InlineEditChangeDetail| title.set(change.value),
required: true,
value: title(),
}
}
}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.
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.
pnpm add @santi020k/lumen-astrolumen add InlineEditpnpm add @santi020k/lumen-reactlumen add InlineEdit --target reactpnpm add @santi020k/lumen-elementslumen add InlineEdit --target elementsAPI 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.
| Attribute | Values | Default | Description |
|---|---|---|---|
| label | string | required | Names the field, the Edit button ("Edit {label}"), and the saved announcement ("{label} saved."). |
| value | string | "" | 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 / defaultValue | string | "" | 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. |
| name | string | - | The field name, also sent as name with each change. |
| required, maxLength, pattern | boolean, 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. |
| placeholder | string | - | Hint in the empty field. Read mode shows it in a muted style while the value is empty. |
| multiline | boolean | false | Edits with a Textarea. Enter adds a line; Control+Enter or Command+Enter saves. |
| headingLevel | 1 | 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. |
| labels | Partial<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-change | CustomEvent<{ 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-pattern | string | browser message | Set 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, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML 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.
.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
| Hook | Values | Default | Contract |
|---|---|---|---|
| data-error-required, data-error-pattern | string | browser message | Set 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, className | string | "" | 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.
| Key | Action |
|---|---|
| Enter, Space on Edit | Open the editor and focus the field. A single-line field selects its text; a multiline field puts the caret at the end. |
| Tab | Move between the field, Save, and Cancel. |
| Enter in a single-line field | Save the value. |
| Control+Enter, Command+Enter in a multiline field | Save the value. Enter alone adds a new line. |
| Escape in the editor | Cancel, restore the saved value, and return focus to Edit. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:inline-edit-change | InlineEdit 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. |