Editable
A component that allows users to edit text in place.
A component that allows users to edit text in place.
To set up the editable correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-part
attribute to help identify them in the DOM.
Learn how to use the Editable
component in your project. Let’s take a look at
the most basic example:
import { Editable } from '@ark-ui/react'
const Basic = () => (
<Editable.Root placeholder="Placeholder" activationMode="dblclick">
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
</Editable.Root>
)
import { Editable } from '@ark-ui/solid'
const Basic = () => (
<Editable.Root placeholder="Placeholder" activationMode="dblclick">
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
</Editable.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Editable } from '@ark-ui/vue'
const value = ref('Chakra')
</script>
<template>
<Editable.Root placeholder="Placeholder" activationMode="dblclick">
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
</Editable.Root>
</template>
In some cases, you might need to use custom controls to toggle the edit and read mode. We use the render prop pattern to provide access to the internal state of the component.
import { Editable } from '@ark-ui/react'
const CustomControls = () => (
<Editable.Root placeholder="enter a value" defaultValue="Chakra">
{(api) => (
<>
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
<Editable.Control>
{api.isEditing ? (
<>
<Editable.SubmitTrigger>Save</Editable.SubmitTrigger>
<Editable.CancelTrigger>Cancel</Editable.CancelTrigger>
</>
) : (
<Editable.EditTrigger>Edit</Editable.EditTrigger>
)}
</Editable.Control>
</>
)}
</Editable.Root>
)
import { Editable } from '@ark-ui/solid'
const CustomControls = () => (
<Editable.Root placeholder="enter a value" value="Chakra">
{(api) => (
<>
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
<Editable.Control>
{api().isEditing ? (
<>
<Editable.SubmitTrigger>Save</Editable.SubmitTrigger>
<Editable.CancelTrigger>Canvel</Editable.CancelTrigger>
</>
) : (
<Editable.EditTrigger>Edit</Editable.EditTrigger>
)}
</Editable.Control>
</>
)}
</Editable.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Editable } from '@ark-ui/vue'
const value = ref('Chakra')
</script>
<template>
<Editable.Root placeholder="enter a value" v-model="value" v-slot="{ isEditing }">
<Editable.Label>Label</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
<Editable.Control v-if="isEditing">
<Editable.SubmitTrigger>Save</Editable.SubmitTrigger>
<Editable.CancelTrigger>Cancel</Editable.CancelTrigger>
</Editable.Control>
<Editable.Control v-else>
<Editable.EditTrigger>Edit</Editable.EditTrigger>
</Editable.Control>
</Editable.Root>
</template>
To auto-grow the editable as the content changes, set the autoResize
prop to
true
.
<Editable.Root placeholder="Placeholder" autoResize>
{/*...*/}
</Editable.Root>
It is a common pattern to set a maximum of the editable as it auto-grows. To
achieve this, set the maxWidth
prop to the desired value.
<Editable.Root placeholder="Placeholder" autoResize maxWidth="320px">
{/*...*/}
</Editable.Root>
The editable supports two modes of activating the “edit” state:
To change the mode to double-click, pass the prop activationMode="dblclick"
.
<Editable.Root placeholder="Placeholder" activationMode="dblclick">
{/*...*/}
</Editable.Root>
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
activationMode The activation mode for the preview element. - "focus" - Enter edit mode when the preview element is focused - "dblclick" - Enter edit mode when the preview element is double-clicked - "none" - No interaction with the preview element will trigger edit mode. | ActivationMode | "focus" |
asChild Render as a different element type. | boolean | |
autoResize Whether the editable should auto-resize to fit the content. | boolean | |
defaultValue The initial value of the editable. | string | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
disabled Whether the editable is disabled | boolean | |
finalFocusEl The element that should receive focus when the editable is closed. By default, it will focus on the trigger element. | () => HTMLElement | null | |
form The associate form of the underlying input. | string | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | string | |
ids The ids of the elements in the editable. Useful for composition. | Partial<{
root: string
area: string
label: string
preview: string
input: string
controls: string
submitTrigger: string
cancelTrigger: string
editTrigger: string
}> | |
invalid Whether the input's value is invalid. | boolean | |
maxLength The maximum number of characters allowed in the editable | number | |
name The name attribute of the editable component. Used for form submission. | string | |
onEdit The callback that is called when in the edit mode. | () => void | |
onFocusOutside Function called when the focus is moved outside the component | (event: FocusOutsideEvent) => void | |
onInteractOutside Function called when an interaction happens outside the component | (event: InteractOutsideEvent) => void | |
onPointerDownOutside Function called when the pointer is pressed down outside the component | (event: PointerDownOutsideEvent) => void | |
onValueChange The callback that is called when the editable's value is changed | (details: ValueChangeDetails) => void | |
onValueCommit The callback that is called when the editable's value is submitted. | (details: ValueChangeDetails) => void | |
onValueRevert The callback that is called when the esc key is pressed or the cancel button is clicked | (details: ValueChangeDetails) => void | |
placeholder The placeholder value to show when the `value` is empty | string | { edit: string; preview: string } | |
readOnly Whether the editable is readonly | boolean | |
selectOnFocus Whether to select the text in the input when it is focused. | boolean | |
startWithEditView Whether to start with the edit mode active. | boolean | |
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 | SubmitMode | "enter" |
translations Specifies the localized strings that identifies the accessibility elements and their states | IntlTranslations | |
value The value of the editable in both edit and preview mode | string |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Previous
DialogNext
Environment