Field
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>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
Custom control
Choose how strict the review should be.
Recommended range: 60–80.
The default slot supplies association IDs. Detached status avoids overlapping a slider.
Standalone label and status
Compose the label and status independently.
This custom control uses a detached status message.
Compose FieldLabel and FieldStatus separately and connect the control id and aria-describedby yourself.
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.