vael-ui v0.5.7

Utilities

useFieldControl

Connects a custom form control to the nearest Field: its id, ARIA attributes, and focus and filled state. Use it when your own control sits inside a Field.

Connects a custom form control to the nearest <Field>. It returns the id and the ARIA values to bind (aria-describedby, aria-invalid, aria-required), and reports focus and filled state to Field. Field uses that state to move a floating label and set data-filled. Every built-in input (Input, Select, Checkbox, RadioGroup, …) uses it. Use it so a custom control works with Field the same way.

Install

import { useFieldControl } from 'vael-ui'

Examples

Parameters

NameTypeDescription
filledMaybeRefOrGetter<boolean>Tells the nearest Field whether the control has a value, including values your code sets through v-model.

Returns

NameTypeDescription
idstringThe id to bind on the control: Field's controlId when there is one, otherwise a new useId().
describedBy() => stringThe value for aria-describedby.
labelledBy() => stringThe value for aria-labelledby, on group controls such as RadioGroup that have no single native input.
invalid() => booleanWhether Field marks the control invalid. Combine it with the control's own invalid prop.
required() => booleanThe value for aria-required.
disabled() => booleanWhether Field disables the control. Combine it with the control's own disabled prop.
onFocus() => voidReports focus to Field. Call it from the control's native focus event.
onBlur() => voidReports blur to Field. Call it from the control's native blur event.