useInlineEdit

InlineEdit
stable

Headless edit-in-place state machine managing four states — IDLE, EDITING, VALIDATING, ERROR — and four transitions: edit, confirm, cancel, setValue. Input-agnostic: it owns the draft string and the async validation pipeline; components wire their native input to the returned draft ref.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

When both rules and validate are provided, rules are evaluated first sequentially; validate is only reached if all rules pass. Stale async validations are cancelled via an internal token counter — calling cancel() mid-flight safely discards the in-flight Promise.

Interfaces consommées

IUseInlineEditOptions

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

modelValue
requis
Ref<string | number> | ComputedRef<string | number>
The current committed value (the v-model source). Snapshotted into draft when edit() is called.
options
MaybeRefOrGetter<IUseInlineEditOptions>
{}
Optional configuration: trim, validate, rules, onConfirm, onCancel, onError callbacks.
options.trim
boolean
true
Trims whitespace from the draft before validation and confirmation.
options.validate
TInlineEditValidator
Async validation callback. Receives the normalised draft value and must return true (valid) or an error string.
options.rules
TInlineEditRule[]
Array of rule functions evaluated sequentially before validate. Each rule returns true or an error string.
options.onConfirm
(value: string) => void
Called with the confirmed value when all validations pass. Wire to emit("update:modelValue", value) in the SFC.
options.onCancel
() => void
Called when the user cancels editing without confirming.
options.onError
(message: string) => void
Called when validation fails, with the error message string.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

isEditing
True while the component is in editing mode.
draft
The mutable editing buffer. Bind to the native input value and update via setValue on oninput.
error
Current validation error message, or null when there is no error.
isPending
True while an async validator is running.
normalisedDraft
The trimmed version of draft (when trim is true). Used as the validated and committed value.
isDraftEmpty
True when the normalised draft is an empty string.
edit
Enters edit mode, snapshotting modelValue into draft. No-op if already editing.
confirm
Runs rules then validate sequentially. On success, calls onConfirm and exits edit mode. Returns true on success, false on validation failure.
cancel
Discards the draft, resets all state, and calls onCancel.
setValue
Updates draft and clears any stale error. Called from the oninput handler.

Usage

Exemples

Extraits de code prêts à coller.

Basic inline edit field

vue

With async server validation

ts