Inline Edit
Text that turns into a pre-filled field when clicked, for renaming titles and labels in place.
<arc-inline-edit>Overview
Inline Edit shows its value as plain text, with no field chrome and only a faint pencil on hover or focus. Clicking it, or pressing Enter, Space or F2 while it's focused, swaps in a field with the current value selected, ready to type over. Enter or clicking away commits, and Escape throws the edit away.
The display text inherits the surrounding typography and the field matches it, so the text doesn't change size or move when it swaps. In a heading it edits at heading size, and in a table cell at cell size. Use it for renames and titles, where a visible input box would make the page look like a form.
While someone types, the draft streams out as arc-input events. value, and the value a surrounding form submits, change only on commit, which fires one arc-change. Committing an unchanged value fires nothing. Cancelling fires arc-cancel and restores the previous text.
From script, edit() enters edit mode with the field focused and its text selected, for a "Rename" menu item or a freshly added row. commit() and cancel() leave edit mode the two ways the keyboard does and fire the same events. Call commit() when something outside the component ends the edit (a toolbar Save, a route change), and cancel() when a save fails and the old text should come back. edit() does nothing when the component is disabled, readonly or already editing, so you can call it without checking first.
Guidelines
Do
- Always set `label`. It names both the display button ("Edit Track title") and the field
- Listen for `arc-change` to save a rename
- Use `multiline` for short notes that may wrap, and tell people that Cmd/Ctrl+Enter saves
- Set a `placeholder` that fits the content, such as "Untitled track", so an empty value still looks clickable
- Use `readonly` when a value is temporarily locked. The text stays in the reading order but can't be edited
Don't
- Don't use it in a conventional form layout. A labeled Input tells people there's something to fill in, and Inline Edit hides that
- Don't use it for values that need heavy validation or structured entry, such as emails, dates and numbers. Use Input, Date Picker or Number Input
- Don't treat `arc-input` as a save signal. It carries the draft, which Escape can still throw away
- Don't rely on the pencil to show that text is editable on touch screens. It appears on hover and focus, and touch has no hover
Features
- Takes part in forms through ElementInternals, like Input: the committed value submits under `name`, and `form.reset()` restores the initial text
- `required` makes an empty committed value invalid, shown as a faint error tint even in display state
- `multiline` edits in a textarea, where Enter inserts a newline and Cmd/Ctrl+Enter commits
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<!-- A renameable track list: text until clicked, field until committed -->
<div style="display:flex; flex-direction:column; max-width:440px; gap:2px;">
<arc-inline-edit value="Midnight Signal" label="Track 1 title" placeholder="Untitled track"></arc-inline-edit>
<arc-inline-edit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track"></arc-inline-edit>
<arc-inline-edit label="Track 3 title" placeholder="Untitled track"></arc-inline-edit>
</div>
<script>
document.querySelectorAll('arc-inline-edit').forEach((el) => {
el.addEventListener('arc-change', (e) => {
console.log('renamed to', e.detail.value);
});
});
</script>
<!-- Multiline notes: Enter newlines, Cmd/Ctrl+Enter commits -->
<arc-inline-edit multiline label="Session notes" placeholder="Add a note"></arc-inline-edit>import { InlineEdit } from '@arclux/arc-ui-react';
export default function TrackList() {
return (
<div style={{ display: 'flex', flexDirection: 'column', maxWidth: 440, gap: 2 }}>
<InlineEdit
value="Midnight Signal"
label="Track 1 title"
placeholder="Untitled track"
onArcChange={(e) => console.log('renamed to', e.detail.value)}
/>
<InlineEdit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track" />
<InlineEdit label="Track 3 title" placeholder="Untitled track" />
</div>
);
}<script setup>
import { InlineEdit } from '@arclux/arc-ui-vue';
function onRename(e) {
console.log('renamed to', e.detail.value);
}
</script>
<template>
<div style="display:flex; flex-direction:column; max-width:440px; gap:2px;">
<InlineEdit value="Midnight Signal" label="Track 1 title" placeholder="Untitled track" @arc-change="onRename" />
<InlineEdit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track" />
<InlineEdit label="Track 3 title" placeholder="Untitled track" />
</div>
</template><script>
import { InlineEdit } from '@arclux/arc-ui-svelte';
function onRename(e) {
console.log('renamed to', e.detail.value);
}
</script>
<div style="display:flex; flex-direction:column; max-width:440px; gap:2px;">
<InlineEdit value="Midnight Signal" label="Track 1 title" placeholder="Untitled track" on:arc-change={onRename} />
<InlineEdit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track" />
<InlineEdit label="Track 3 title" placeholder="Untitled track" />
</div>import { Component } from '@angular/core';
import { InlineEdit } from '@arclux/arc-ui-angular';
@Component({
imports: [InlineEdit],
template: `
<div style="display:flex; flex-direction:column; max-width:440px; gap:2px;">
<arc-inline-edit value="Midnight Signal" label="Track 1 title" placeholder="Untitled track" (arc-change)="onRename($event)"></arc-inline-edit>
<arc-inline-edit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track"></arc-inline-edit>
<arc-inline-edit label="Track 3 title" placeholder="Untitled track"></arc-inline-edit>
</div>
`,
})
export class TrackListComponent {
onRename(e: CustomEvent<{ value: string }>) {
console.log('renamed to', e.detail.value);
}
}import { InlineEdit } from '@arclux/arc-ui-solid';
export default function TrackList() {
return (
<div style={{ display: 'flex', 'flex-direction': 'column', 'max-width': '440px', gap: '2px' }}>
<InlineEdit
value="Midnight Signal"
label="Track 1 title"
placeholder="Untitled track"
on:arc-change={(e) => console.log('renamed to', e.detail.value)}
/>
<InlineEdit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track" />
<InlineEdit label="Track 3 title" placeholder="Untitled track" />
</div>
);
}import { InlineEdit } from '@arclux/arc-ui-preact';
export default function TrackList() {
return (
<div style={{ display: 'flex', flexDirection: 'column', maxWidth: 440, gap: 2 }}>
<InlineEdit
value="Midnight Signal"
label="Track 1 title"
placeholder="Untitled track"
onArcChange={(e) => console.log('renamed to', e.detail.value)}
/>
<InlineEdit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track" />
<InlineEdit label="Track 3 title" placeholder="Untitled track" />
</div>
);
}<div style="display:flex; flex-direction:column; max-width:440px; gap:2px;">
<arc-inline-edit value="Midnight Signal" label="Track 1 title" placeholder="Untitled track"></arc-inline-edit>
<arc-inline-edit value="Glass Harbor" label="Track 2 title" placeholder="Untitled track"></arc-inline-edit>
<arc-inline-edit label="Track 3 title" placeholder="Untitled track"></arc-inline-edit>
</div>API
valuestring''- The committed text. Updated only when an edit commits (Enter or blur); keystrokes accumulate in an internal draft until then.
labelstring''- Accessible name for the control. The display state announces as "Edit {label}" and the edit field is labeled with it. Always provide one.
namestring''- The
nameattribute sent with form data on submission. The submitted value is the committedvalue, never an in-progress draft. placeholderstring'Empty'- Text shown in muted italic when
valueis empty, and as the field placeholder while editing. Defaults to "Empty". disabledbooleanfalse- Prevents activation and applies a muted treatment. The value is excluded from form submission while disabled.
multilinebooleanfalse- When true, editing uses a
<textarea>: Enter inserts a newline and Cmd/Ctrl+Enter commits. Single-line commits on plain Enter. requiredbooleanfalse- Marks the field as required. An empty committed value is invalid, including in display state, which shows a subtle error tint.
readonlybooleanfalse- Renders the display state only: the text remains focusable for reading order, but activation is inert and no pencil affordance appears.
formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessage
Methods
focus(options?)options?: FocusOptions- Move focus to whichever element is currently the control: the field while
editing, the display row otherwise.
The host sets no
delegatesFocusand everything focusable lives in the shadow root, soel.focus()used to do nothing at all, silently, which cost a consumer a "Rename" menu item that appeared dead.edit()is the way *into* editing and stays that way; this is only the obvious call landing where a caller expects it. edit()- Enter edit mode: focus the field and select its text. No-op when disabled, readonly, or already editing.
commit()- Commit the current draft and leave edit mode. Fires arc-change only if the value changed.
cancel()- Discard the draft, keep the previous value, and leave edit mode. Fires arc-cancel.
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-changedetail:{ value: string }- Fired once on commit when the value actually changed, with the new value in detail.value.
arc-canceldetail:{ value: string }- Fired when an edit is canceled (Escape or cancel()), with the retained value in detail.value. No arc-change accompanies it.
arc-inputdetail:{ value: string }- Fired on each keystroke while editing, with the draft text in detail.value.
See also
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.
- TextareaA multi-line text field with a label, an optional character counter and an error message.
- FormWraps ARC UI inputs in a form that validates them on submit and fires arc-submit with their values.
- LabelForm label with a required indicator, description text and a tooltip slot. Clicking it focuses the control whose id is in `for`.