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

ElementDescription
LabelText identifying the field. Always rendered for accessibility, optionally hidden visually.
DescriptionHelper text between the label and input explaining what to enter.
Control slotA custom, native, or third-party control that does not already render a field shell.
Status messageInline validation feedback showing error, warning, or success with a message.
Optional/Required indicatorBadge next to the label showing whether the field is optional or required.
Label tooltipInfo icon at the end of the label with a tooltip explaining the field.

Best practices #

GuidancePractices
DoWrap custom controls, native inputs, or third-party widgets that need labeling, helper text, optional/required indicators, or validation status.
DoAlways provide a label for accessibility, even if visually hidden with isLabelHidden.
DoUse inputID and descriptionID to connect the label and description to the inner control with htmlFor and aria-describedby.
Don'tNest Field around styled inputs such as TextInput, Typeahead, Select, DateInput, or TextArea; those components already render their own Field shell.
Don'tUse 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'tSet both isOptional and isRequired on the same field.
Don'tHide the label without providing an alternative way for the user to understand the field purpose.

Examples #

Field — Required and optional

Open in Playground

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
Open in Playground

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
Open in Playground

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.
  1. Pass inputId to the control's id.
  2. Pass labelId to the control's aria-labelledby.
  3. Pass describedBy to the control's aria-describedby.

Field does not modify controls in its slot automatically.

Group labels #

  1. Set isGroupLabel on Field.
  2. Pass labelId to the group's aria-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.