Editable
An inline text component that switches between display and edit modes for in-place editing.
Anatomy
<script>
import {
Editable,
EditableArea,
EditablePreview,
EditableInput,
EditableTextarea,
EditableControl,
EditableEditTrigger,
EditableSubmitTrigger,
EditableCancelTrigger,
EditableLabel,
} from "@saas-ui/svelte/components/editable";
</script>
<Editable.Root defaultValue="Click to edit">
<Editable.Label>Name</Editable.Label>
<Editable.Area>
<Editable.Input />
<Editable.Preview />
</Editable.Area>
<Editable.Control>
<Editable.EditTrigger>Edit</Editable.EditTrigger>
<Editable.CancelTrigger>Cancel</Editable.CancelTrigger>
<Editable.SubmitTrigger>Save</Editable.SubmitTrigger>
</Editable.Control>
</Editable.Root>Examples
Basic Accessibility
<Editable.Root defaultValue="Click to edit">
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root> Colours Accessibility
colour prop to change the colour scheme.
<VStack gap={4}>
{#each colours as colour}
<HStack gap={4} align="center">
<Text size="xs" class="w-16">{colour}</Text>
<Editable.Root
defaultValue="Click to edit"
{colour}
class="w-full"
>
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root>
</HStack>
{/each}
</VStack> Controlled Accessibility
<Editable.Root
value={name}
onValueChange={(e) => (name = e.value)}
placeholder="Click to edit"
>
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root> Disabled Accessibility
disabled prop to disable the editable component.
<Editable.Root disabled defaultValue="Click to edit">
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root> Invalid Accessibility
invalid prop to show an invalid state.
<Editable.Root invalid defaultValue="Click to edit">
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root> Textarea Accessibility
Editable.Textarea for multi-line editing.
<Editable.Root defaultValue="Click to edit" autoResize class="w-full">
<Editable.Area>
<Editable.Preview class="min-h-14 items-start" />
<Editable.Textarea class="min-h-14" />
</Editable.Area>
</Editable.Root> With Controls Accessibility
Editable.Control.
<Editable.Root defaultValue="Click to edit">
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
<Editable.Control>
<Editable.EditTrigger icon aria-label="Edit">
<Icon as={PencilSimple} size="xs" weight="bold" />
</Editable.EditTrigger>
<Editable.CancelTrigger icon aria-label="Cancel">
<Icon as={X} size="xs" weight="bold" />
</Editable.CancelTrigger>
<Editable.SubmitTrigger icon aria-label="Submit">
<Icon as={Check} size="xs" weight="bold" />
</Editable.SubmitTrigger>
</Editable.Control>
</Editable.Root> With Double Click Accessibility
activationMode="dblclick" to require a double-click to enter edit mode.
<Editable.Root
defaultValue="Double click to edit"
activationMode="dblclick"
>
<Editable.Area>
<Editable.Preview />
<Editable.Input />
</Editable.Area>
</Editable.Root>Props
Editable.Root
The root container component for the editable.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the editable. |
activationMode | "focus" | "dblclick" | "click" | "none" | "focus" | The activation mode for entering edit mode. |
autoResize | boolean | false | Whether to auto-resize the input to fit content. |
defaultValue | string | - | The initial value when uncontrolled. |
value | string | - | The controlled value. |
onValueChange | (details: { value: string }) => void | - | Called when the value changes. |
onValueCommit | (details: { value: string }) => void | - | Called when the value is committed (submitted). |
onValueRevert | (details: { value: string }) => void | - | Called when the value is reverted (cancelled). |
onEditChange | (details: { edit: boolean }) => void | - | Called when edit mode changes. |
placeholder | string | { edit: string; preview: string } | - | Placeholder text when empty. |
maxLength | number | - | Maximum number of characters allowed. |
selectOnFocus | boolean | true | Whether to select text on focus. |
submitMode | "enter" | "blur" | "none" | "both" | "both" | How to submit the value. |
disabled | boolean | false | Whether the editable is disabled. |
readOnly | boolean | false | Whether the editable is read-only. |
required | boolean | false | Whether the editable is required. |
invalid | boolean | false | Whether the editable is invalid. |
size | "xs" | "sm" | "md" | "lg" | "md" | The size of the editable. |
colour | ColourName | "gray" | The colour theme for focus states. |
class | string | - | Additional CSS classes. |
style | string | - | Additional inline styles. |
name | string | - | The name attribute for form submission. |
form | string | - | The form ID for form association. |
Editable.Area
Container for the preview and input elements.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the area. |
class | string | - | Additional CSS classes. |
Editable.Preview
Displays the current value when not in edit mode.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes. |
Editable.Input
Single-line text input for editing the value.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes. |
style | string | - | Additional inline styles. |
Editable.Textarea
Multi-line text input for editing the value.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes. |
style | string | - | Additional inline styles. |
rows | number | 2 | Number of rows for the textarea. |
Editable.Label
Label element for the editable input.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The label content. |
class | string | - | Additional CSS classes. |
Editable.Control
Container for edit, cancel, and submit trigger buttons.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the control. |
class | string | - | Additional CSS classes. |
Editable.EditTrigger
Button to enter edit mode.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the trigger. |
class | string | - | Additional CSS classes. |
variant | ButtonVariants['variant'] | "ghost" | Button variant. |
size | ButtonVariants['size'] | "xs" | Button size. |
colour | ColourName | "gray" | Button colour. |
icon | boolean | false | Whether this is an icon-only button. |
style | string | - | Additional inline styles. |
Editable.CancelTrigger
Button to cancel editing and revert changes.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the trigger. |
class | string | - | Additional CSS classes. |
variant | ButtonVariants['variant'] | "outline" | Button variant. |
size | ButtonVariants['size'] | "xs" | Button size. |
colour | ColourName | "gray" | Button colour. |
icon | boolean | false | Whether this is an icon-only button. |
style | string | - | Additional inline styles. |
Editable.SubmitTrigger
Button to submit and commit the edited value.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to render inside the trigger. |
class | string | - | Additional CSS classes. |
variant | ButtonVariants['variant'] | "outline" | Button variant. |
size | ButtonVariants['size'] | "xs" | Button size. |
colour | ColourName | "gray" | Button colour. |
icon | boolean | false | Whether this is an icon-only button. |
style | string | - | Additional inline styles. |