Field
Alignment target:@astryxdesign/core v0.7.1 · Field
We will never share your email.
Usage #
Field provides structure around a control:
- A label.
- A description.
- Required or optional indicators.
- A status message.
TextInput includes Field. Pass field props directly to TextInput.
Vue
<script setup lang="ts">
import { Field } from '@astryx-vue/core/Field'
import { shallowRef, useId } from 'vue'
const volume = shallowRef(50)
const inputId = `volume-${useId()}`
</script>
<template>
<Field :input-id="inputId" label="Volume" description="Set playback volume.">
<template #default="field">
<input
:id="field.inputId" v-model.number="volume" type="range"
:aria-labelledby="field.labelId" :aria-describedby="field.describedBy"
>
</template>
</Field>
</template>Anatomy
| Element | Description |
|---|---|
| Label | Text identifying the field. Always rendered for accessibility, optionally hidden visually. |
| Description | Helper text between the label and input explaining what to enter. |
| Control slot | A custom, native, or third-party control that does not already render a field shell. |
| Status message | Inline validation feedback showing error, warning, or success with a message. |
| Optional/Required indicator | Badge next to the label showing whether the field is optional or required. |
| Label tooltip | Info icon at the end of the label with a tooltip explaining the field. |
Best practices #
| Guidance | Practices |
|---|---|
| Do | Wrap custom controls, native inputs, or third-party widgets that need labeling, helper text, optional/required indicators, or validation status. |
| Do | Always provide a label for accessibility, even if visually hidden with isLabelHidden. |
| Do | Use inputID and descriptionID to connect the label and description to the inner control with htmlFor and aria-describedby. |
| Don't | Nest Field around styled inputs such as TextInput, Typeahead, Select, DateInput, or TextArea; those components already render their own Field shell. |
| Don't | Use the attached status variant on non-bordered controls such as sliders, switches, or checkboxes; use detached so the message does not overlap the control. |
| Don't | Set both isOptional and isRequired on the same field. |
| Don't | Hide the label without providing an alternative way for the user to understand the field purpose. |
Examples #
Field — Required and optional
A required username next to an optional backup email.
Field — Validation states
Enter your work email
Please enter a valid email address
Choose a unique username
This username is reserved for administrators
Paste your API key
API key is valid and active
Error, warning, and success on email, username, and API key.
Field — Description
We'll send a confirmation link to this address
At least 8 characters with one uppercase letter
Helper text under the label for the email and password fields.
Association IDs #
The default slot provides:
inputId: the control ID.labelId: the label ID.descriptionId: the description ID.statusId: the status message ID.describedBy: the description and status message IDs.
- Pass
inputIdto the control'sid. - Pass
labelIdto the control'saria-labelledby. - Pass
describedByto the control'saria-describedby.
Field does not modify controls in its slot automatically.
Group labels #
- Set
isGroupLabelonField. - Pass
labelIdto the group'saria-labelledby.
If the label is hidden, provide visible context that explains the field's purpose.
Scope #
The application is responsible for:
- Validating control values.
- Submitting forms.
- Disabling controls.