Inline Edit
Text that turns into a field on click: Enter (Ctrl/⌘+Enter when multiline) commits, Escape cancels, and any control with a value that fires change can be the editor.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | The committed value. Typing only changes the draft; value updates when the draft is committed. |
placeholder | string | — | Text shown in the read view and the field while the value is empty. |
label | string | — | Accessible name of the built-in field and of the read view, e.g. Project name. A slotted editor needs its own. |
name | string | — | Form field name. The committed value is submitted under it. |
multiline | boolean | false | Edits in a textarea: Enter adds a line, Ctrl/⌘+Enter commits, and the read view keeps line breaks. |
activation | InlineEditActivation | click | What enters edit mode from the read view: click (default), dblclick, or none (only edit()). Enter and Space always work in click and dblclick. |
blur-action | InlineEditBlurAction | commit | What leaving the field does: commit (default; a refused draft stays open with its text), cancel, or none (stay in edit mode). |
controls | boolean | false | Shows save and cancel buttons next to the field while editing. |
select-on-edit | boolean | true | Selects the whole text when the built-in field opens. Set select-on-edit="false" to put the caret at the end. |
required | boolean | false | Refuses to commit an empty draft: the field stays open and is marked invalid. |
maxlength | number | -1 | Maximum number of characters, forwarded to the built-in field. |
readonly | boolean | false | Shows the value without the edit affordance. |
disabled | boolean | false | Disables editing and dims the element. |
editing | boolean | false | Whether the editor is open. Settable: true opens it with the committed value and focuses it, false closes it
without committing. No events fire. An element that renders with editing already set opens without taking
focus; call focus() to move it there. |
Slots
| Name | Description |
|---|---|
editor | A control used instead of the built-in input while editing. It must expose value and fire change on itself when a choice is made (it need not bubble), and carry its own accessible name (aria-label): label names only the built-in field and the read view. It gets aria-invalid while a required draft is refused. |
preview | Content shown in the read view instead of the value text, e.g. a badge. Update it yourself on change. |
edit-icon | Replaces the pencil shown next to the value on hover and focus. |
save-icon | Replaces the check mark of the save button (controls). |
cancel-icon | Replaces the cross of the cancel button (controls). |
Events
| Name | Type | Description |
|---|---|---|
edit-start | Event | Fired before the editor opens. Cancelable: preventDefault() keeps the read view. |
edit-commit | CustomEvent<InlineEditCommitEventDetail> | Fired when a changed draft is committed, before value updates. Cancelable: preventDefault() keeps the editor open with the draft. |
input | Event | Fired after a commit changed value. |
change | Event | Fired after a commit changed value, right after input. |
edit-cancel | Event | Fired when editing ends without committing (Escape, the cancel button, or blur with blur-action="cancel"). |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-inline-edit--min-width | pixel | 48px | Smallest width of the read view and the field, so an empty value stays clickable. |
--c2-inline-edit--padding-block | padding | 2px | |
--c2-inline-edit--padding-inline | padding | 6px | |
--c2-inline-edit--border-radius | border-radius | 6px | |
--c2-inline-edit--color | color | — | Text colour. Inherited from the page when unset. |
--c2-inline-edit--font-size | font-size | — | Inherited from the page when unset, so the element fits a heading or a table cell. |
--c2-inline-edit--font-weight | font-weight | — | |
--c2-inline-edit--font-family | font-family | — | |
--c2-inline-edit--line-height | pixel | — | |
--c2-inline-edit__placeholder--color | color | #71717a | |
--c2-inline-edit__hover--background | color | #f4f4f5 | Read view background under the pointer. |
--c2-inline-edit__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | Focus ring of the read view and the buttons. |
--c2-inline-edit__edit-icon--size | pixel | 14px | |
--c2-inline-edit__edit-icon--color | color | #71717a | |
--c2-inline-edit__edit-icon--gap | pixel | 6px | Space between the value and the pencil. |
--c2-inline-edit__edit-icon--opacity | opacity | 0 | Pencil opacity at rest. Set 1 to always show it. |
--c2-inline-edit__edit-icon__hover--opacity | opacity | 1 | Pencil opacity on hover and keyboard focus. |
--c2-inline-edit__editor--background | color | #ffffff | |
--c2-inline-edit__editor--border | border | 1px solid #0265dc | |
--c2-inline-edit__editor__error--border | border | 1px solid #dc2626 | Field border while the draft is refused (required and empty); drawn as an outline around a slotted editor. |
--c2-inline-edit__controls--gap | pixel | 4px | Space between the field and the save and cancel buttons. |
--c2-inline-edit__control--size | pixel | 24px | |
--c2-inline-edit__control--border-radius | border-radius | 4px | |
--c2-inline-edit__control--color | color | #71717a | |
--c2-inline-edit__control__icon--size | pixel | 16px | |
--c2-inline-edit__control__hover--color | color | #18181b | |
--c2-inline-edit__control__hover--background | color | #f4f4f5 | |
--c2-inline-edit__disabled--opacity | opacity | 0.38 | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under inline-edit, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
display | {0}: {1} | {0} label {1} text |
save | Save | — |
cancel | Cancel | — |
valueMissing | Please fill in this field. | — |