shadcn.io is an independent project built on shadcn/ui
On this page9 sections
An editable shows a value as plain text and turns it into a field when someone clicks it, then saves the change or puts the old text back. It suits values that change now and then, in place, such as a display name on a profile card or the title of a document.
When a value is edited as often as it's read, an always-open Input is clearer.
Installation
Anatomy

Usage
<script setup lang="ts">
import {
Editable, EditableArea, EditableInput, EditablePreview,
} from "@/components/ui/editable";
import { Input } from "@/components/ui/input";
</script>
EditableInput renders a bare input, so pass your styled Input as its child with asChild. EditablePreview is the text people see until the field opens.
<template>
<Editable defaultValue="Vinicius Vicentini">
<EditableArea>
<EditableInput as-child>
<Input />
</EditableInput>
<EditablePreview />
</EditableArea>
</Editable>
</template>
Accessibility
The text is focusable whenever editing is allowed, and the field is a real input. Inside a Field, the input takes its name from the FieldLabel, and with no label it is called "editable input". Ark UI calls the text "edit", so pass translations to Editable with an edit string that names the value, such as "Edit name". With activationMode set to click or dblclick, a keyboard can focus the text but not open it, so add an EditableEditTrigger, as the Activation click demo does.
- Enter
- Saves the edited content and exits edit mode.
- EscEscape
- Discards the changes and exits edit mode.
- Tab
- Moves focus onto the text, which opens the field when
activationModeisfocus, the default. Once focus leaves an open field and its buttons, the edit is saved, or discarded whensubmitModeisenterornone. - Ctrl+Enter
- In a textarea, where Enter adds a line, saves the edit. On a Mac, use Cmd + Enter.
Demos
Activation click
Name and Username open for editing on a single click, and tabbing past the text doesn't start an edit, which helps in a form people move through by keyboard. Enter on the text does nothing, so each field has an edit button, an EditableEditTrigger, as the keyboard's way in. Cancel and save take its place while the field is open.
Activation focus
activationMode is focus, the default, so the field opens as soon as the text gets focus, by Tab or by a click. It's the quickest way through a short profile form of two or three values. The flip side is that tabbing through the page opens every field on the way and saves each one as focus leaves it.
Activation none
activationMode is none, so clicking or focusing the text does nothing, and the edit button, an EditableEditTrigger, is the only way in. Cancel and save take its place while the field is open. Use it when editing is rare enough to deserve a button, or when people should be able to select the text without opening it.
Controlled
An Edit button in the card header opens Name and Username together and turns into Save while they're open. Both fields set activationMode to none and take edit from the page's state, so only the header button changes them. Use it when several values enter and leave edit mode as one, such as the fields of a profile card.
Dblclick
activationMode set to dblclick leaves a single click alone and opens the field on the second, the way renaming a file works on a desktop, where the first click selects it. Cancel and save show while the field is open. A keyboard can't double-click, so each field also has an edit button, an EditableEditTrigger, for people who don't use a mouse.
Orientation horizontal
One line of text, with cancel and save buttons that appear on the same row while it's being edited. orientation is horizontal, the default, which suits a short value such as a name or a URL slug when the row has room for the field and two icon buttons.
Orientation vertical
orientation set to vertical stacks a textarea above the buttons, which sit at the end of the row underneath. Use it for a value that runs to several lines, or in a narrow card where a single row would squeeze the text. In the textarea, Enter adds a line, and Ctrl + Enter or Cmd + Enter saves.
Size lg
size set to lg on EditablePreview, a 36-pixel input and large icon buttons make a taller row. Only the height changes, not the size of the text, so use it in a row of other large inputs and buttons, where the default row would sit short.
Size md
md is the default, a 32-pixel row with medium icon buttons, written out here to compare with the other two. It matches the default Input, so leave size out in a settings form and the editable lines up with the fields around it.
Size sm
size set to sm on EditablePreview, a 28-pixel input and small icon buttons make a shorter row for a table cell, a sidebar or a dense list of settings. Only the height changes, and the value is edited the same way.
With textarea
A Description field holds a two-sentence paragraph, edited in a textarea with the buttons underneath because orientation is vertical. Use it for a bio, a note or a product description. It keeps the default focus mode, so a click on the text or Tab opens the field.
Without controls
Name and Email have no buttons at all: click the text to edit, press Enter to save and Escape to put the old value back, and clicking or tabbing away saves too. Use it in a list where buttons on every row would be clutter. Show the buttons when people need to see how to finish.
FAQ
How do I control the text of an Editable in Vue?
Bind v-model on Editable to a string ref, which follows every keystroke while the field is open, so it holds the draft. Save to your server from @value-commit instead, which fires once, when the edit is saved, and @value-revert tells you it was canceled.
Use defaultValue when the text only needs a starting value, as most of the demos do.
If you control edit as well, setting it to false keeps the typed text only when a save, by Enter, the save button or a click outside, came just before. Set it from anywhere else, such as a keyboard shortcut, and Ark UI puts the old text back.
How do I save an Editable value only when the person confirms it?
Save from @value-commit, which fires with the final value when the edit is saved by Enter, by the save button or by focus leaving the field. Escape and the cancel button fire @value-revert with the old value instead.
submitMode decides what counts as saving. both, the default, saves on Enter and when focus leaves, enter saves on Enter and discards the edit when focus leaves, blur saves when focus leaves and ignores Enter, and none saves only from an EditableSubmitTrigger.
How do I start editing an Editable on click instead of focus?
Set activationMode on Editable. focus, the default, opens the field when the text gets focus, click on a click, dblclick on a double-click, and none only from an EditableEditTrigger or the edit prop.
With click or dblclick, add an EditableEditTrigger too. The text takes focus, but Enter and Space don't open it, so that button is the keyboard's way in, as the Activation click and Dblclick demos show.
Can I submit an Editable value with a form?
Yes. Give Editable a name, and Ark UI puts it on the input, which stays in the form while hidden, so the form submits the current text. While the field is open that's the draft, saved or not.
Setting required, maxLength, disabled or readOnly on Editable reaches that input too. A disabled editable sends nothing, so use readOnly for a value that must be submitted but not changed.
How do I show a placeholder when an Editable is empty?
Pass placeholder to Editable. A string shows in the text while the value is empty and in the input while editing, and an object with preview and edit keys sets the two apart, such as Add a title in the text and Title in the input.
While the placeholder shows, the text carries data-placeholder-shown, which the component already uses to gray it out.
How do I make an Editable with several lines of text?
Pass a Textarea to EditableInput with asChild in place of the Input, give EditablePreview the same minimum height, and set orientation to vertical so the buttons sit underneath, as the With textarea demo does.
In a textarea, Enter adds a line, so Ctrl + Enter, or Cmd + Enter on a Mac, saves. The text keeps line breaks only once you add a class such as whitespace-pre-wrap to EditablePreview.
How do I style an Editable to look like a page title?
Put the same text classes on EditablePreview and on the Input inside EditableInput, such as text-2xl font-semibold, so the text doesn't jump when the field opens.
EditableArea is a fixed 32 pixels tall, or 28 and 36 with size set to sm or lg on the preview, so give it a taller height class as well, such as h-12. The component is your file once installed, so a title style you reuse can live in components/ui/editable.
Is the Editable accessible to keyboard and screen reader users?
Partly, until you name the text. Inside a Field, the input reads its FieldLabel, but Ark UI calls the text "edit", so pass translations to Editable with an edit string that names the value, such as "Edit name".
The text is in the tab order, Enter saves and Escape cancels. With activationMode set to click or dblclick the text can't be opened from the keyboard, so add an EditableEditTrigger there, as the Dblclick demo does.
API Reference
Editable
<div> data-slot="editable"
edit?boolean
Whether the editable is in edit mode. Two-way with v-model:edit.
defaultEdit?boolean
Whether the editable is in edit mode by default.
value?string
The controlled value of the editable. Two-way with v-model.
defaultValue?string
The initial value of the editable when rendered. Use when you don't need to control the value of the editable.
activationMode?"focus" | "dblclick" | "click" | "none"
The activation mode for the preview element. - "focus" - Enter edit mode when the preview is focused - "dblclick" - Enter edit mode when the preview is double-clicked - "click" - Enter edit mode when the preview is clicked - "none" - Edit can be triggered programmatically only
- Type
"focus" | "dblclick" | "click" | "none"- Default
"focus"
autoResize?boolean
Whether the editable should auto-resize to fit the content.
dir?"ltr" | "rtl"
The document's text/writing direction.
- Type
"ltr" | "rtl"- Default
"ltr"
disabled?boolean
Whether the editable is disabled.
finalFocusEl?() → HTMLElement | null
The element to receive focus when the editable is closed.
- Type
() → HTMLElement | null- Returns
HTMLElement | null
form?string
The associate form of the underlying input.
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the editable. Useful for composition.
- Type
{ root?: string; area?: string; label?: string; preview?: string; input?: string; control?: string; submitTrigger?: string; cancelTrigger?: string; editTrigger?: string }
invalid?boolean
Whether the input's value is invalid.
maxLength?number
The maximum number of characters allowed in the editable.
name?string
The name attribute of the editable component. Used for form submission.
orientation?"horizontal" | "vertical"
The orientation of the editable.
- Type
"horizontal" | "vertical"- Default
"horizontal"
placeholder?string | { edit: string; preview: string; }
The placeholder text for the editable.
- Type
string | { edit: string; preview: string; }
readOnly?boolean
Whether the editable is read-only.
required?boolean
Whether the editable is required.
selectOnFocus?boolean
Whether to select the text in the input when it is focused.
- Default
true
submitMode?"enter" | "blur" | "both" | "none"
The action that triggers submit in the edit mode:
- "enter" - Trigger submit when the enter key is pressed
- "blur" - Trigger submit when the editable is blurred
- "none" - No action will trigger submit. You need to use the submit button
- "both" - Pressing Enter and blurring the input will trigger submit
- Type
"enter" | "blur" | "both" | "none"- Default
"both"
translations?object
The translations for the editable.
- Type
{ edit?: string; submit?: string; cancel?: string; input?: string }
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
@edit-change(details: EditChangeDetails) → void
Function to call when the edit mode changes.
- Type
(details: EditChangeDetails) → void- Parameters
details– { edit: boolean }- Returns
void
@value-change(details: ValueChangeDetails) → void
Function to call when the value changes.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
@focus-outside(event: FocusOutsideEvent) → void
Function called when the focus is moved outside the component.
- Type
(event: FocusOutsideEvent) → void- Parameters
event– FocusOutsideEvent- Returns
void
@interact-outside(event: InteractOutsideEvent) → void
Function called when an interaction happens outside the component.
- Type
(event: InteractOutsideEvent) → void- Parameters
event– InteractOutsideEvent- Returns
void
@pointer-down-outside(event: PointerDownOutsideEvent) → void
Function called when the pointer is pressed down outside the component.
- Type
(event: PointerDownOutsideEvent) → void- Parameters
event– PointerDownOutsideEvent- Returns
void
@value-commit(details: ValueChangeDetails) → void
Function to call when the value is committed.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
@value-revert(details: ValueChangeDetails) → void
Function to call when the value is reverted.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
data-orientation?string
Mirrors orientation.
EditableArea
<div> data-slot="editable-area"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
data-disabled?string
Present when disabled.
data-focus?string
Present when focused.
data-placeholder-shown?string
Present when placeholder is shown.
EditablePreview
<span> data-slot="editable-preview"
size?"sm" | "md" | "lg"
The size.
- Type
"sm" | "md" | "lg"- Default
"md"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
data-autoresize?string
Present when autoResize is true.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-placeholder-shown?string
Present when placeholder is shown.
data-readonly?string
Present when read-only.
data-size?string
Mirrors size.
EditableInput
<input> data-slot="editable-input"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
data-autoresize?string
Present when autoResize is true.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-readonly?string
Present when read-only.
EditableEditTrigger
<button> data-slot="editable-edit-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
EditableSubmitTrigger
<button> data-slot="editable-submit-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
EditableCancelTrigger
<button> data-slot="editable-cancel-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
EditableControl
<div> data-slot="editable-control"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
useEditable
edit?boolean
Whether the editable is in edit mode. Two-way with v-model:edit.
defaultEdit?boolean
Whether the editable is in edit mode by default.
value?string
The controlled value of the editable. Two-way with v-model.
defaultValue?string
The initial value of the editable when rendered. Use when you don't need to control the value of the editable.
activationMode?"focus" | "dblclick" | "click" | "none"
The activation mode for the preview element. - "focus" - Enter edit mode when the preview is focused - "dblclick" - Enter edit mode when the preview is double-clicked - "click" - Enter edit mode when the preview is clicked - "none" - Edit can be triggered programmatically only
- Type
"focus" | "dblclick" | "click" | "none"- Default
"focus"
autoResize?boolean
Whether the editable should auto-resize to fit the content.
disabled?boolean
Whether the editable is disabled.
finalFocusEl?() → HTMLElement | null
The element to receive focus when the editable is closed.
- Type
() → HTMLElement | null- Returns
HTMLElement | null
form?string
The associate form of the underlying input.
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the editable. Useful for composition.
- Type
{ root?: string; area?: string; label?: string; preview?: string; input?: string; control?: string; submitTrigger?: string; cancelTrigger?: string; editTrigger?: string }
invalid?boolean
Whether the input's value is invalid.
maxLength?number
The maximum number of characters allowed in the editable.
name?string
The name attribute of the editable component. Used for form submission.
placeholder?string | { edit: string; preview: string; }
The placeholder text for the editable.
- Type
string | { edit: string; preview: string; }
readOnly?boolean
Whether the editable is read-only.
required?boolean
Whether the editable is required.
selectOnFocus?boolean
Whether to select the text in the input when it is focused.
- Default
true
submitMode?"enter" | "blur" | "both" | "none"
The action that triggers submit in the edit mode:
- "enter" - Trigger submit when the enter key is pressed
- "blur" - Trigger submit when the editable is blurred
- "none" - No action will trigger submit. You need to use the submit button
- "both" - Pressing Enter and blurring the input will trigger submit
- Type
"enter" | "blur" | "both" | "none"- Default
"both"
translations?object
The translations for the editable.
- Type
{ edit?: string; submit?: string; cancel?: string; input?: string }
@edit-change(details: EditChangeDetails) → void
Function to call when the edit mode changes.
- Type
(details: EditChangeDetails) → void- Parameters
details– { edit: boolean }- Returns
void
@value-change(details: ValueChangeDetails) → void
Function to call when the value changes.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
@focus-outside(event: FocusOutsideEvent) → void
Function called when the focus is moved outside the component.
- Type
(event: FocusOutsideEvent) → void- Parameters
event– FocusOutsideEvent- Returns
void
@interact-outside(event: InteractOutsideEvent) → void
Function called when an interaction happens outside the component.
- Type
(event: InteractOutsideEvent) → void- Parameters
event– InteractOutsideEvent- Returns
void
@pointer-down-outside(event: PointerDownOutsideEvent) → void
Function called when the pointer is pressed down outside the component.
- Type
(event: PointerDownOutsideEvent) → void- Parameters
event– PointerDownOutsideEvent- Returns
void
@value-commit(details: ValueChangeDetails) → void
Function to call when the value is committed.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
@value-revert(details: ValueChangeDetails) → void
Function to call when the value is reverted.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
EditableContext
cancelVoidFunction
Function to exit edit mode, and discard any changes.
clearValueVoidFunction
Function to clear the value of the editable.
editVoidFunction
Function to enter edit mode.
editingboolean
Whether the editable is in edit mode.
emptyboolean
Whether the editable value is empty.
setValue(value: string) → void
Function to set the value of the editable.
- Parameters
value– string- Returns
void
submitVoidFunction
Function to exit edit mode, and submit any changes.
valuestring
The current value of the editable.
valueTextstring
The current value of the editable, or the placeholder if the value is empty.











