MenuChevron Down
Editable - Docs - Artefact

Editable

Forms
Smart auto-detect

Introduction

An inline text field that displays as plain text until activated (by focus, click, or double-click), then swaps to an editable input with submit/cancel controls.

Usage

Artefact UI Suite
Add a description…
import { Editable } from "../components/ui";

export default function MyPage() {
  return (
    <Editable label="Project name" defaultValue="Artefact UI Suite" />
  );
}

Custom Composition

Pass children for full control over the preview/input/controls layout:

import { Editable } from "../components/ui";

export default function MyPage() {
  return (
    <Editable defaultValue="Untitled" activationMode="dblclick">
      <Editable.Label>Title</Editable.Label>
      <Editable.Area>
        <Editable.Preview />
        <Editable.Input />
      </Editable.Area>
      <Editable.Control>
        <Editable.EditTrigger>Edit</Editable.EditTrigger>
        <Editable.SubmitTrigger>Save</Editable.SubmitTrigger>
        <Editable.CancelTrigger>Cancel</Editable.CancelTrigger>
      </Editable.Control>
    </Editable>
  );
}

CMS Page Builder

This component is available as an editable block in the Page Builder (content/pages/*.json):

{
  "type": "editable",
  "label": "Project name",
  "defaultValue": "Artefact UI Suite",
  "placeholder": "Untitled",
  "size": "md",
  "activationMode": "focus",
  "submitMode": "both"
}

It always renders interactive in the Page Builder.

Props

Root

PropTypeDescription
valuestringThe current value (controlled).
defaultValuestringThe initial value (uncontrolled).
editbooleanWhether edit mode is active (controlled).
defaultEditbooleanThe initial edit-mode state (uncontrolled).
activationMode"focus" | "dblclick" | "click" | "none"How the preview enters edit mode. Default "focus".
submitMode"enter" | "blur" | "both" | "none"Which interactions commit the value. Default "both".
selectOnFocusbooleanWhether the input's text is selected when it's focused. Default true.
autoResizebooleanKeep the preview visible (sized to content) while editing instead of hiding it.
disabledbooleanDisables all interaction.
readOnlybooleanPrevents entering edit mode while still allowing focus.
requiredbooleanMarks the underlying input required.
invalidbooleanMarks the field invalid.
placeholderstring | { edit: string; preview: string }Placeholder text, optionally different between the input and the preview.
maxLengthnumberMaximum input length.
namestringName of the underlying input, for native form submission.
formstringAssociates the input with a <form> by id.
translationsPartial<EditableTranslations>Overrides for the edit/submit/cancel/input ARIA strings.
size"2xs" | "xs" | "sm" | "md" | "lg"Visual size. Default "md".
onValueChange(details: { value: string }) => voidCalled as the input value changes.
onValueCommit(details: { value: string }) => voidCalled when the value is submitted.
onValueRevert(details: { value: string }) => voidCalled when editing is cancelled.
onEditChange(details: { edit: boolean }) => voidCalled when edit mode toggles.
interactivebooleanForces (or suppresses) hydration as an island.
classstringCustom CSS classes for the root element.

Default composition

PropTypeDescription
labelJSX.Element | stringLabel rendered above the field.
childrenJSX.ElementExtra content appended after the default preview/input/controls.

Sub-components

PartDescription
Editable.Label<label> bound to the input; clicking it focuses the preview.
Editable.AreaWraps Preview and Input in the same layout slot.
Editable.PreviewThe read-only display shown when not editing; role="button", keyboard-activatable per activationMode.
Editable.InputThe <input> shown while editing; handles Escape-to-cancel and Enter/blur-to-submit per submitMode.
Editable.ControlWraps the edit/submit/cancel triggers.
Editable.EditTriggerEnters edit mode. Hidden while already editing.
Editable.SubmitTriggerCommits the value and exits edit mode. Hidden while not editing.
Editable.CancelTriggerDiscards changes and exits edit mode. Hidden while not editing.
Editable.ContextRender-prop access to the editable context: <Editable.Context>{(ctx) => ...}</Editable.Context>.

Accessibility

  • Preview is keyboard-operable (tabIndex={0}, Enter/Space) whenever activationMode is "click" or "dblclick"; with "focus" mode, simply tabbing to it opens edit mode.
  • EditTrigger / SubmitTrigger / CancelTrigger get aria-labels from translations, and are hidden (not just visually, via the hidden attribute) when not applicable to the current mode.
  • Input carries aria-invalid when invalid is set and aria-label from translations.input.