Dice UI

Editable

An accessible inline editable component for editing text content in place.

API

Installation

pnpm dlx shadcn@latest add @diceui/editable

Layout

Import the parts, and compose them together.

import {
  Editable,
  EditableLabel,
  EditableArea,
  EditablePreview,
  EditableInput,
  EditableTrigger,
  EditableToolbar,
  EditableSubmit,
  EditableCancel,
} from "@/components/ui/editable";
 
return (
  <Editable>
    <EditableLabel />
    <EditableArea>
      <EditablePreview />
      <EditableInput />
      <EditableTrigger />
    </EditableArea>
    <EditableTrigger />
    <EditableToolbar>
      <EditableSubmit />
      <EditableCancel />
    </EditableToolbar>
  </Editable>
)

Examples

With Double Click

Trigger edit mode with double click instead of single click.

With Autosize

Input that automatically resizes based on content.

Todo List

With Form

Control the editable component in a form.

API Reference

Editable

The main container component for editable functionality.

Prop

Type

EditableLabel

The label component for the editable field.

Prop

Type

Data AttributeValue
[data-disabled]Present when the editable field is disabled
[data-invalid]Present when the editable field is invalid
[data-required]Present when the editable field is required

EditableArea

Container for the preview and input components.

Prop

Type

Data AttributeValue
[data-disabled]Present when the editable field is disabled
[data-editing]Present when the field is in edit mode

EditablePreview

The preview component that displays the current value.

Prop

Type

Data AttributeValue
[data-empty]Present when the field has no value
[data-disabled]Present when the editable field is disabled
[data-readonly]Present when the field is read-only

EditableInput

The input component for editing the value.

Prop

Type

EditableTrigger

Button to trigger edit mode.

Prop

Type

Data AttributeValue
[data-disabled]Present when the editable field is disabled
[data-readonly]Present when the field is read-only

EditableToolbar

Container for action buttons.

Prop

Type

EditableSubmit

Button to submit changes.

Prop

Type

EditableCancel

Button to cancel changes.

Prop

Type

Accessibility

Keyboard Interactions

KeyDescription
EnterSubmits the current value when in edit mode.
EscapeCancels editing and reverts to the previous value.
TabMoves focus to the next focusable element.

On this page