Editable
Edit text in place, then save or cancel the change.
Demos
Size
Variant
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Editing behavior
Click the preview or Edit to begin. Submit commits the draft; Cancel restores the previous value. The preview, input, and action buttons share the selected size. Open Options and states to try activation mode, submit mode, multiline input, disabled, and read-only states.
Installation
Complete the shared installation. Copy Editable.vue and index.ts into app/components/ui/editable/. Also copy the required components: Button.
app/components/ui/editable/Editable.vue
<script setup lang="ts">
import { DateField as Primitive } from 'akaza-ui'
import { computed, nextTick, useAttrs, useTemplateRef } from 'vue'
import { cn, mergeRecipeSlots } from '../../../utils/ui'
import { calendarVariants } from '../calendar'
import uiConfig from '../ui.config'
import {
dateFieldVariants,
resolveDateFieldVariants,
type DateFieldProps,
type DateFieldSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<DateFieldProps>(), {
id: undefined,
name: undefined,
locale: undefined,
dir: undefined,
placeholder: undefined,
minValue: undefined,
maxValue: undefined,
isDateUnavailable: undefined,
required: undefined,
disabled: undefined,
readOnly: undefined,
invalid: undefined,
selectOnFocus: undefined,
autoAdvance: undefined,
showCalendar: true,
calendarLabel: undefined,
calendarSide: undefined,
calendarAlign: undefined,
calendarSideOffset: undefined,
calendarTeleport: 'body',
ariaLabel: undefined,
ariaLabelledby: undefined,
ariaDescribedby: undefined,
ui: undefined,
modelValue: undefined,
calendarOpen: undefined,
})
defineSlots<DateFieldSlots>()
const attrs = useAttrs()
const resolved = computed(() => resolveDateFieldVariants(props, uiConfig))
const styles = computed(() => dateFieldVariants(resolved.value))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
const flat = Object.fromEntries(
Object.entries(styles.value)
.filter(([part]) => !['calendar'].includes(part))
.map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
return {
...flat,
calendar: mergeRecipeSlots(calendarVariants({ size: resolved.value.size }), {
...props.ui?.calendar,
root: cn(styles.value.calendar(), props.ui?.calendar?.root),
}),
}
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, variant: _variant, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
async function onFieldClick(event: MouseEvent) {
const target = event.target as HTMLElement
if (
props.showCalendar &&
!props.disabled &&
!props.readOnly &&
target.closest('.akaza-date-field-segments')
) {
primitive.value?.openCalendar(event)
// Calendar initial focus belongs to its button; clicking a segment must keep typing focus.
await nextTick()
await nextTick()
target.focus({ preventScroll: true })
}
}
defineExpose({
get validationState() {
return primitive.value!.validationState
},
get clear() {
return primitive.value!.clear
},
get closeCalendar() {
return primitive.value!.closeCalendar
},
get focus() {
return primitive.value!.focus
},
get openCalendar() {
return primitive.value!.openCalendar
},
get setValue() {
return primitive.value!.setValue
},
get toggleCalendar() {
return primitive.value!.toggleCalendar
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
@click="onFieldClick"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof DateFieldSlots" v-bind="scope ?? {}"
/></template>
<template v-if="!$slots['calendar-trigger']" #calendar-trigger
><svg
class="size-4 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
aria-hidden="true"
>
<path
d="M8 2v4m8-4v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"
/></svg
></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | outline, soft, bare | outline |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | field/generated id | Visible control id. |
name | string | field name | Native form field name. |
placeholder | string | { preview?: string; edit?: string } | "Enter text..." | Shared or mode-specific placeholder. |
activationMode | "focus" | "click" | "dblclick" | "none" | "focus" | Preview event that starts editing. |
submitMode | "blur" | "enter" | "both" | "none" | "blur" | Events that submit the draft. |
startWithEditMode | boolean | false | Starts with the input visible and focused. |
selectOnFocus | boolean | false | Selects input text when editing starts. |
autoResize | boolean | false | Uses native field-sizing: content. |
multiline | boolean | false | Renders a textarea instead of an input. |
rows | number | 2 | Initial textarea rows. |
maxLength | number | — | Native maximum draft length. |
required | boolean | false | Requires a committed non-empty value. |
disabled | boolean | false | Disables all controls and form submission. |
readOnly | boolean | false | Keeps preview focusable but blocks editing. |
invalid | boolean | false | Controlled invalid state. |
dir | "ltr" | "rtl" | inherited | Text direction. |
ariaLabel | string | — | Accessible label when no Field label exists. |
ariaDescribedby | string | field ids | Accessible description ids. |
ui | EditableUi | — | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
preview | value, isEmpty, edit | Preview button content. |
edit | — | Edit button content. |
submit | — | Submit button content. |
cancel | — | Cancel button content. |
state | value, draft, isEditing, isEmpty, edit, submit, cancel | Optional state-driven custom UI. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | value | Fired after a draft is accepted. |
value-change | (value, details) | Fired before commit. details.cancel() prevents it. |
draft-change | (value, details) | Fired before draft input updates. Cancelable. |
state-change | (state, details) | Fired for edit, submit, and cancel. |
submit | (value, details) | Fired before submission completes. Cancelable. |
cancel | (committedValue, details) | Fired before draft cancellation. Cancelable. |
Keyboard
| Key | Behavior |
|---|---|
Enter | Submits when submitMode includes Enter. |
Ctrl+Enter / Cmd+Enter | Submits a multiline value. |
Escape | Cancels the draft and returns to preview mode. |
Tab | Uses native focus order; blur may submit depending on submitMode. |