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 { cloneVNode, defineComponent, h } from "vue"
import { CheckIcon, PencilIcon, XIcon } from "lucide-vue-next"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import {
Editable, EditableArea, EditableCancelTrigger, EditableContext,
EditableControl, EditableEditTrigger, EditableInput, EditablePreview,
EditableSubmitTrigger,
} from "@/components/ui/editable"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
// What a component hands its default slot (React's render-prop argument).
type SlotProps<T> = T extends new (...args: any) => {
$slots: { default?: (props: infer P) => any }
}
? P
: never
const EditableButtons = defineComponent(
(_props: {}) => {
return () => {
return h(EditableContext as never, {}, { default: (editable: SlotProps<typeof EditableContext>) =>
editable.editing ? (
[h(EditableCancelTrigger as never, { "aria-label": "Cancel" }, { render: ({ props }: { props: Record<string, unknown> }) => cloneVNode(h(Button as never, { size: "icon-sm", variant: "ghost" }, h(XIcon as never, { "aria-hidden": "true" })), props) }), h(EditableSubmitTrigger as never, { "aria-label": "Save" }, { render: ({ props }: { props: Record<string, unknown> }) => cloneVNode(h(Button as never, { size: "icon-sm", variant: "ghost" }, h(CheckIcon as never, { "aria-hidden": "true" })), props) })]
) : (
h(EditableEditTrigger as never, { "aria-label": "Edit" }, { render: ({ props }: { props: Record<string, unknown> }) => cloneVNode(h(Button as never, { size: "icon-sm", variant: "ghost" }, h(PencilIcon as never, { "aria-hidden": "true" })), props) })
) })
}
},
{ name: "EditableButtons", inheritAttrs: false }
)
</script>
<template>
<Card class="w-full max-w-sm">
<CardHeader
description="Click the field or the edit button to change a value."
title="Edit user"
/>
<CardContent>
<FieldGroup>
<Field>
<FieldLabel id="editable-default-name-label">Name</FieldLabel>
<Editable aria-labelledby="editable-default-name-label" defaultValue="Vinicius Vicentini">
<EditableArea>
<EditableInput><template #render="{ props }"><Input v-bind="props" /></template></EditableInput>
<EditablePreview />
</EditableArea>
<EditableControl><EditableButtons /></EditableControl>
</Editable>
</Field>
<Field>
<FieldLabel id="editable-default-username-label">Username</FieldLabel>
<Editable aria-labelledby="editable-default-username-label" defaultValue="@vinihvc">
<EditableArea>
<EditableInput><template #render="{ props }"><Input v-bind="props" /></template></EditableInput>
<EditablePreview />
</EditableArea>
<EditableControl><EditableButtons /></EditableControl>
</Editable>
</Field>
</FieldGroup>
</CardContent>
</Card>
</template>
Accessibility
The text is a button in the tab order whenever editing is allowed and activationMode isn't none, and the field is a real input. Give the FieldLabel an id and pass the same id to Editable as aria-labelledby, as the demos do: the input takes its name from the label, and the text reads the label before the value, such as "Name, Vinicius Vicentini". With no label at all, the input is called "editable input". Enter, Space or F2 on the text opens the field in every mode but none, where an EditableEditTrigger is the only way in.
- Enter
- On the text, opens the field, unless
activationModeisnone. In the field, saves the edit and shows the text again, unlesssubmitModeisblurornone. - Space
- On the text, opens the field, unless
activationModeisnone. - F2
- On the text, opens the field, as Space does.
- EscEscape
- Puts the old text back and shows the text again, without closing a dialog the editable sits in.
- Tab
- Moves focus onto the text, which opens the field when
activationModeisfocus, the default, and skips it whenactivationModeisnone. 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, Space or F2 on the text opens it from the keyboard, and each field also has an edit button, an EditableEditTrigger, that shows the 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. Enter, Space or F2 on the text opens it from the keyboard, and 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, every way out, from Enter and Escape to the buttons and a click outside, only asks through @edit-change, and the edit ends when you set edit to false: saved, or put back after Escape or the cancel button. Set it to false from anywhere else, such as a keyboard shortcut, and the typed text is kept.
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, the text still takes focus, and Enter, Space or F2 opens it, so the keyboard has a way in without a button. An EditableEditTrigger still shows people that the value can change, as the Activation click and Dblclick demos show.
Can I submit an Editable value with a form?
Yes. Give Editable a name, and the component 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 as render 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 you pass to EditableInput as render, 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?
Yes, once you name it. Give the FieldLabel an id and pass it to Editable as aria-labelledby, as the demos do, and the input takes its name from the label, while the text, a button, reads the label and then the value. With no label at all, the input is called "editable input".
The text is in the tab order unless activationMode is none, and in every other mode Enter, Space or F2 opens it. In the field, Enter saves and Escape cancels, and with none an EditableEditTrigger is the way in, as the Activation none demo shows.
API Reference
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 value. Pair with onValueChange to control it. Two-way with v-model.
defaultValue?string
The value it starts with, when you don't control value.
activationMode?ActivationMode
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.
- Default
"focus"
disabled?boolean
Whether it's disabled.
finalFocusEl?() → HTMLElement | null
The element to receive focus when the editable is closed.
- Type
() → HTMLElement | null- Returns
HTMLElement | null
form?string
The id of the form it submits with, when it isn't inside one.
ids?object
Element ids. label names the input and the preview from a label of your own.
- Type
{ area?: string; control?: string; input?: string; label?: string; preview?: string; root?: string }
invalid?boolean
Whether it's invalid.
maxLength?number
The maximum number of characters allowed in the editable.
name?string
The name it submits with its form.
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 a value is required to submit its form.
selectOnFocus?boolean
Whether to select the text in the input when it is focused.
- Default
true
submitMode?SubmitMode
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.
- Default
"both"
translations?object
The translations for the editable.
- Type
{ cancel?: string; edit?: string; input?: string; submit?: string }
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
@edit-change(details: { edit: boolean }) → void
Function to call when the edit mode changes.
- Type
(details: { edit: boolean }) → void- Parameters
details– { edit: boolean }- Returns
void
@value-change(details: { value: string }) → void
Called when the value changes.
- Type
(details: { value: string }) → void- Parameters
details– { value: string }- Returns
void
@value-commit(details: { value: string }) → void
Called when an interaction ends with a new value: the pointer is released, or a key sets it.
- Type
(details: { value: string }) → void- Parameters
details– { value: string }- Returns
void
@value-revert(details: { value: string }) → void
Function to call when the value is reverted.
- Type
(details: { value: string }) → void- Parameters
details– { value: string }- Returns
void
EditableArea
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
EditableInput
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
EditablePreview
size?"sm" | "md" | "lg"
The size.
- Type
"sm" | "md" | "lg"- Default
"md"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-size?string
Mirrors size.
EditableControl
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.











