Forms & inputs
Layout
Field
A wrapper that connects a label, help text and an error message to a form control. Use it to label a control without wiring its id and ARIA attributes yourself.
Validating a form? vael-form wires this up with a schemaInstall
import { Field } from 'vael-ui'Playground
top
undefined
start
Usage
<script setup lang="ts">
import { Field, Input } from 'vael-ui'
</script>
<template>
<Field label="Email">
<Input placeholder="[email protected]" />
</Field>
</template>Motion New
Field: its parts' appearance and states.
<Field
:motion="{ states: { invalid: { root: { scale: 1.04 } } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | rootlabelcontroldescriptionerror | Sets 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. |
states | invaliddisabledfocus | Sets 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) => animation | Animates 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 | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
It has no keyboard interaction of its own.
- The
<label>points at the control withfor. Controls without a native input, such as Select, Slider and Rating, usearia-labelledbyinstead. Without alabel, nothing is linked, so name the control yourself. - The description and the error are linked to the control with
aria-describedby, so screen readers read the error with the control. It isn’t an alert, so a failed submit with several errors doesn’t interrupt with each one. - While
erroris set, the control getsaria-invalid="true".requiredsetsaria-requiredonly, and the asterisk isn’t part of the accessible name. Putrequiredon the control itself to have a plain form submit check it too. - Controls in
#prependand#appendaren’t named by the label: give each one anaria-label.