Search docs

Editable

An inline editable text field that switches between a static preview and a native text input or textarea.

Editable uses native <input> or <textarea> and <button type="button"> elements so screen readers and keyboard navigation work out of the box.

Click or focus to edit
import { component$, useStyles$ } from '@builder.io/qwik';
import { Editable } from '@leve-ui/editable';
import { LuCheck, LuPencil, LuX } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <Editable.Root
      defaultValue="Click or focus to edit"
      placeholder="Enter a title..."
      class="editable-default"
    >
      <Editable.Label class="editable-default-label">Project title</Editable.Label>
      <div class="editable-default-row">
        <Editable.Area class="editable-default-area">
          <Editable.Preview class="editable-default-preview" />
          <Editable.Input class="editable-default-input" />
        </Editable.Area>
        <Editable.Control class="editable-default-control">
          <Editable.EditTrigger class="editable-default-trigger" aria-label="Edit">
            <LuPencil class="editable-default-icon" aria-hidden="true" />
          </Editable.EditTrigger>
          <Editable.SubmitTrigger
            class="editable-default-trigger editable-default-submit"
            aria-label="Save"
          >
            <LuCheck class="editable-default-icon" aria-hidden="true" />
          </Editable.SubmitTrigger>
          <Editable.CancelTrigger class="editable-default-trigger" aria-label="Cancel">
            <LuX class="editable-default-icon" aria-hidden="true" />
          </Editable.CancelTrigger>
        </Editable.Control>
      </div>
    </Editable.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/editable

Anatomy#

import { Editable } from '@leve-ui/editable'; // or '@leve-ui/core'

<Editable.Root defaultValue="Hello">
  <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.Root>
PartElementDescription
Editable.Root<div>Wraps the parts and manages committed value, draft value, and edit state.
Editable.Label<label>Accessible label associated with Editable.Input.
Editable.Area<div>Wraps Editable.Preview and Editable.Input.
Editable.Preview<span>Displays the committed value or placeholder when not editing.
Editable.Input<input> | <textarea>Edits the draft value. Renders <textarea> when multiline is true.
Editable.Control<div>Wraps the action trigger buttons.
Editable.EditTrigger<button>Enters edit mode and focuses Editable.Input.
Editable.SubmitTrigger<button>Commits the draft value, exits edit mode, and restores focus.
Editable.CancelTrigger<button>Reverts the draft value, exits edit mode, and restores focus.

Examples#

Controlled#

Use bind:value and bind:edit to control both the committed value and edit mode from parent state.

Controlled value
Committed: Controlled value

Double Click#

Set activationMode="dblclick" so edit mode only opens on double-click or via Editable.EditTrigger.

Double-click to edit

Multiline#

Set multiline to render a <textarea>. Enter inserts a newline, and Ctrl+Enter / Cmd+Enter commits.

First line of notes. Press Ctrl+Enter (or Cmd+Enter) to save.

Disabled#

disabled on Editable.Root disables editing and all triggers.

Cannot be edited

Read Only#

readOnly on Editable.Root prevents entering edit mode while keeping the preview readable.

Read-only value

With Field#

Inside a Field.Root, use Field.Label instead of Editable.Label. The Field provides the IDs, description, error message, and disabled / required / invalid states.

Enter your name...
Shown on your public profile.

API Reference#

Root#

PropDefaultType
ids–{ input?: string; label?: string; preview?: string }

Overrides the element IDs of the parts. Only used outside a Field.

defaultValue''string

The initial committed value when uncontrolled.

bind:value–Signal<string>

A signal with the committed value (controlled).

onValueChange$–QRL<(value: string) => void>

Called when the committed value changes.

defaultEditfalseboolean

Whether the editable starts in edit mode when uncontrolled.

bind:edit–Signal<boolean>

A signal with the edit mode state (controlled).

onEditChange$–QRL<(edit: boolean) => void>

Called when the edit mode state changes.

onValueCommit$–QRL<(value: string) => void>

Called when the draft value is committed.

onValueRevert$–QRL<(value: string) => void>

Called when editing is cancelled and the draft reverts to the committed value.

activationMode'focus''focus' | 'dblclick' | 'click' | 'none'

How the user enters edit mode from the preview.

submitMode'both''enter' | 'blur' | 'both' | 'none'

How edits are committed from the input.

selectOnFocustrueboolean

Whether to select all text in the input when entering edit mode.

placeholder–string

Placeholder text shown when the value is empty.

multilinefalseboolean

Whether to render a <textarea> instead of <input> in edit mode.

disabledfalseboolean

Disables editing and interaction. Inside a Field, the Field's disabled also applies.

readOnlyfalseboolean

Marks the editable as read-only. Inside a Field, the Field's readOnly also applies.

requiredfalseboolean

Marks the input as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the editable as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-editableAlways present
data-state"preview" | "edit"
data-emptyPresent when the committed value is empty
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Label#

No props of its own. Accepts all <label> attributes.

Data attributeValue
data-leve-editable-labelAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Area#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-editable-areaAlways present
data-state"preview" | "edit"
data-emptyPresent when the committed value is empty
data-placeholder-shownPresent when empty and placeholder is set
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Preview#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-editable-previewAlways present
data-state"preview" | "edit"
data-emptyPresent when the committed value is empty
data-placeholder-shownPresent when empty and placeholder is set
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Input#

No props of its own. Accepts all <input> attributes.

Data attributeValue
data-leve-editable-inputAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Control#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-editable-controlAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled
data-readonlyPresent when read-only

EditTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-editable-edit-triggerAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled or read-only

SubmitTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-editable-submit-triggerAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled or read-only

CancelTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-editable-cancel-triggerAlways present
data-state"preview" | "edit"
data-disabledPresent when disabled or read-only

Accessibility#

  • Editable.Label (or Field.Label) is linked to Editable.Input via for / id.
  • When activationMode is "focus", Editable.Preview has tabIndex={0} so keyboard users can tab to it and enter edit mode.
  • Pressing Enter or Space on Editable.Preview enters edit mode (unless activationMode="none", disabled, or readOnly).
  • Exiting edit mode via Enter, Escape, SubmitTrigger, or CancelTrigger restores focus to Editable.EditTrigger (or Editable.Preview without re-triggering focus activation).

Keyboard Interactions#

KeyDescription
Enter / Space (on Preview)Enters edit mode and focuses Editable.Input.
Enter (on single-line Input)Commits the draft value and exits edit mode (when submitMode is "enter" or "both").
Ctrl+Enter / Cmd+Enter (on multiline Input)Commits the draft value and exits edit mode (when submitMode is "enter" or "both").
Escape (on Input)Reverts the draft value and exits edit mode.