Editable
A component that allows users to edit text in place.
Anatomy
<Editable.Root>
<Editable.Label />
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
<Editable.Control>
<Editable.EditTrigger />
<Editable.SubmitTrigger />
<Editable.CancelTrigger />
</Editable.Control>
</Editable.Root>
Examples
Controlled
Use value and onValueChange to control the value.
Root Provider
Use RootProvider with the useEditable hook to access the state and methods from outside the component.
Context
Read the state with Editable.Context or the useEditableContext hook, for example to show keyboard hints while
editing.
Controls
Build custom controls to toggle edit and read mode. A render prop exposes the internal state.
Textarea
Use asChild on Editable.Input to render a textarea for multi-line editing.
Field
Wrap the editable in Field to wire up the label, helper text, error text, and their ARIA attributes.
Guides
Auto-resizing
Set autoResize to grow the editable with its content.
<Editable.Root placeholder="Placeholder" autoResize>
{/*...*/}
</Editable.Root>
Max Length
Use maxLength to cap the number of characters.
<Editable.Root placeholder="Placeholder" autoResize maxLength={10}>
{/*...*/}
</Editable.Root>
Double Click
By default, edit mode starts when the preview is focused (by pointer or keyboard). Set activationMode="dblclick" to
start it on double-click instead.
<Editable.Root placeholder="Placeholder" activationMode="dblclick">
{/*...*/}
</Editable.Root>
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
activationMode | 'focus' | ActivationModeThe 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 |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
autoResize | booleanWhether the editable should auto-resize to fit the content. | |
defaultEdit | booleanWhether the editable is in edit mode by default. | |
defaultValue | stringThe initial value of the editable when rendered. Use when you don't need to control the value of the editable. | |
disabled | booleanWhether the editable is disabled. | |
edit | booleanWhether the editable is in edit mode. | |
finalFocusEl | () => HTMLElement | nullThe element to receive focus when the editable is closed. | |
form | stringThe associate form of the underlying input. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the editable. Useful for composition. | |
invalid | booleanWhether the input's value is invalid. | |
maxLength | numberThe maximum number of characters allowed in the editable | |
name | stringThe name attribute of the editable component. Used for form submission. | |
onEditChange | (details: EditChangeDetails) => voidFunction to call when the edit mode changes. | |
onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
onValueChange | (details: ValueChangeDetails) => voidFunction to call when the value changes. | |
onValueCommit | (details: ValueChangeDetails) => voidFunction to call when the value is committed. | |
onValueRevert | (details: ValueChangeDetails) => voidFunction to call when the value is reverted. | |
placeholder | string | { edit: string; preview: string }The placeholder text for the editable. | |
readOnly | booleanWhether the editable is read-only. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
required | booleanWhether the editable is required. | |
selectOnFocus | true | booleanWhether to select the text in the input when it is focused. |
submitMode | 'both' | SubmitModeThe 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 |
translations | IntlTranslationsThe translations for the editable. | |
value | stringThe controlled value of the editable. |
| Attribute | Description |
|---|---|
[data-editable-root] | <uid> |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
Area
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EditableAreaState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-editable-area] | <uid> |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
[data-placeholder-shown] | Present when placeholder is shown |
CancelTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
EditTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Input
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EditableInputState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-editable-input] | <uid> |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
[data-autoresize] |
Label
Defines the <label> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EditableLabelState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-editable-label] | <uid> |
[data-focus] | Present when focused |
[data-invalid] | Present when invalid |
[data-required] | Present when required |
Preview
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EditablePreviewState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-editable-preview] | <uid> |
[data-placeholder-shown] | Present when placeholder is shown |
[data-readonly] | Present when read-only |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-autoresize] |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseEditableReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
SubmitTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Context
API
| Property | Type |
|---|---|
editing | booleanWhether the editable is in edit mode |
empty | booleanWhether the editable value is empty |
value | stringThe current value of the editable |
valueText | stringThe current value of the editable, or the placeholder if the value is empty |
setValue | (value: string) => voidFunction to set the value of the editable |
clearValue | VoidFunctionFunction to clear the value of the editable |
edit | VoidFunctionFunction to enter edit mode |
cancel | VoidFunctionFunction to exit edit mode, and discard any changes |
submit | VoidFunctionFunction to exit edit mode, and submit any changes |
getRootState | () => RootStateReturns the state of the root |
Accessibility
Keyboard Support
| Key | Description |
|---|---|
Enter | Saves the edited content and exits edit mode. |
Escape | Discards the changes and exits edit mode. |