vael-ui v0.5.7

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 schema

Install

import { Field } from 'vael-ui'

Playground

Usage
<script setup lang="ts">
import { Field, Input } from 'vael-ui'
</script>

<template>
  <Field label="Email">
    <Input placeholder="[email protected]" />
  </Field>
</template>

Props

NameTypeDefaultDescription
labelstringLabel text, linked to the wrapped control.
descriptionstringHelp text below the control, linked via aria-describedby.
errorstringError message, linked to the control with aria-describedby.
requiredbooleanShows a required marker and sets aria-required on the wrapped control.
disabledbooleanDisables the wrapped control.
labelPlacement'top' | 'start' | 'end' | 'float' | 'inset''top''top' stacks above the control; 'float' overlays its edge, moving up on focus or fill; 'inset' sits inside it; 'start'/'end' sit before/after it on the same line. With 'start'/'end', add attached to join the label to the control as one box, and labelWidth to line up a column of fields.
attachedbooleanfalseDraws a start/end label as a muted cell that shares the control's border. It stays the real <label>. Controls without a bordered frame (Switch, Slider…) keep a plain side label. Has no effect with top, float or inset.
labelWidthstring | number'max-content'Width of a start/end label: a number is pixels, a string any CSS length ('8rem'). Give fields the same width to line up their controls, or set --ui-field-label-width once on a parent. An attached label truncates with an ellipsis when its text is wider.
labelAlign'start' | 'end''start'Aligns a start/end label's text. Use 'end' for right-aligned form labels that sit next to the control.
motionFieldMotionHow it moves: its parts' appearance ({ initial: { label: { opacity: 0, y: 4 } } }) and its states ({ states: { invalid: { control: { x: [0, -6, 6, 0] } } } }). false turns its own animation off.
uiPartial<Record<'root' | 'label' | 'control' | 'group' | 'prepend' | 'append' | 'description' | 'error', UiPartValue>>Class and style overrides for each part. Joined cells (an attached label, #prepend, #append) take their colors from --ui-field-cell-bg and --ui-field-cell-color.

Events

No events.

Slots

NameTypeDescription
defaultanyThe form control that the field labels and describes.
labelanyReplaces the label text, keeping the <label> element and its for wiring.
prependanyCell joined to the control's leading edge. Text and icons share one segment, and each control (a Select, a Button) gets its own, so $ plus a currency Select reads [ $ | USD ]. Put controls directly in the slot, not inside a wrapper element. The Field's label doesn't name them, so give each one an aria-label; the Field's disabled still applies. Next to a control without a frame (Switch, Slider…), the cell renders as plain text.
appendanyCell joined to the control's trailing edge; same rules as #prepend.
descriptionanyCustom description content; replaces the description text.
error{ error: string; }Custom error content; renders only while error is set.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Field: its parts' appearance and states.

<Field
  :motion="{ states: { invalid: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootlabelcontroldescriptionerrorSets 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.
statesinvaliddisabledfocusSets 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

It has no keyboard interaction of its own.

  • The <label> points at the control with for. Controls without a native input, such as Select, Slider and Rating, use aria-labelledby instead. Without a label, 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 error is set, the control gets aria-invalid="true". required sets aria-required only, and the asterisk isn’t part of the accessible name. Put required on the control itself to have a plain form submit check it too.
  • Controls in #prepend and #append aren’t named by the label: give each one an aria-label.