vael-ui v0.5.7

Forms & inputs

Layout

Editable

Text that turns into an input when you click it, and saves on Enter or blur. Use it to rename something in place.

Validating a form? vael-form wires this up with a schema

Install

import { Editable } from 'vael-ui'

Playground

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Editable } from 'vael-ui'

const value = ref('')
</script>

<template>
  <Editable placeholder="Type here…" v-model="value" />
</template>

Props

NameTypeDefaultDescription
placeholderstring'Click to edit'Shown in the preview when the text is empty, and in the input.
activationMode'focus' | 'click' | 'dblclick''click'What opens the input: a click, a double click, or focus arriving.
submitMode'enter' | 'blur' | 'none' | 'both''both'What saves the edit: Enter, leaving the input, either, or only submit(). Leaving the input otherwise cancels.
selectOnFocusbooleantrueSelects the text when the input opens, so typing replaces it.
maxlengthnumberNative maxlength on the input.
disabledbooleanfalseBlocks editing.
size'sm' | 'md' | 'lg''md'Control size, as on Input.
motionEditableMotiontrueHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }) and its states ({ states: { editing: { root: { scale: '1.01' } } } }). false skips the swap transition; use the exposed previewEl and inputEl for your own.
uiPartial<Record<'root' | 'preview' | 'edit' | 'input' | 'actions', UiPartValue>>Class and style overrides for each part.
modelValuestring''The text. Updates when an edit is submitted, not on every keystroke.
editingbooleanfalseWhether the input is showing. Bind it to open or close the edit from outside.

Events

NameTypeDescription
submit(value: string)Fires with the saved text.
update:modelValue(value: string)Fires when modelValue changes (v-model).
update:editing(value: boolean)Fires when editing changes (v-model:editing).
cancel()Fires when an edit is dropped.

Slots

NameTypeDescription
preview{ value: string; }The resting text.
edit{ value: string; update: (value: string) => void; submit: () => void; cancel: () => void; size: "sm" | "md" | "lg"; }The control while editing, in place of the Input: a Textarea, a Select, a date picker. Bind value and call update with each change; Enter, Escape and focus leaving still work. A key your control handles itself with preventDefault() (@keydown.enter.prevent="save") is left to it.
actions{ submit: () => void; cancel: () => void; }Buttons beside the control, such as save and cancel.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
previewElHTMLButtonElement | nullThe resting text's button; null while editing.
inputElHTMLInputElement | nullThe native input; null until editing.
start() => voidOpens the input.
submit() => voidSaves the draft and closes.
cancel() => voidDrops the draft and closes.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Editable: its appearance and states.

<Editable
  :motion="{ states: { editing: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootprevieweditinputactionsSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
stateseditingdisabledfocusSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

KeyAction
EnterOpens the input from the preview.
SpaceOpens the input from the preview when activationMode is 'click'.
EnterSaves the edit when submitMode is 'enter' or 'both'.
EscapeDrops the edit and closes the input.
TabSaves or drops the edit as focus leaves, following submitMode.
  • The preview is a native button. With aria-label or aria-labelledby the label is its name and its text its description ("Notes, button, Pressure low"); without one, its text is its name.
  • Opening moves focus into the input and selects its text when selectOnFocus is on. Closing with Enter or Escape moves focus back to the preview; leaving with Tab keeps focus where it went.
  • In a Textarea passed to #edit, Enter adds a new line and Cmd or Ctrl with Enter saves. Focus moving to #actions or a picker panel inside the edit does not count as leaving.
  • aria-label and aria-labelledby name the preview and the built-in input; other attributes go to the wrapper. A control you pass in #edit needs its own label.