Skip to content

Field

Connect a form control to its label, description, and error message.

Demos

Use a name your team can recognize.

Usage

vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'

const items = [
  { value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>

<template>
  <Accordion :items="items" />
</template>

Required, invalid, and disabled fields

Field provides the label, description, validation message, and shared state for its control. Set invalid after your validation runs. The preview lets you inspect each state.

We use this address for project updates.
Enter a valid email address.
vue
<AppLayout :viewport="false" scroll="page">
  <template #header>Workspace</template>
  <template #left><ProjectNavigation /></template>
  <ProjectList />
  <template #footer>2 projects</template>
</AppLayout>

Other controls

The same field structure works with selects and checkboxes. Give a checkbox its own action label; use the Field label to describe the setting.

Choose who can open this project.
Email me about project updates
You can change this later.
vue
<AppLayout :layout="{ header: 'full', footer: 'content' }">
  <template #left><ProjectNavigation /></template>
  <ProjectList />
  <template #right><ProjectDetails /></template>
</AppLayout>

Installation

Complete the shared installation. Copy Field.vue and index.ts into app/components/ui/field/.

API

Props

PropTypeDefaultDescription
asstring"div"Root element tag.
idstringgeneratedControl id.
namestring—Field name provided to child inputs.
labelstring—Visible label.
descriptionstring—Help text.
errorstring—Error text. Also marks field invalid.
errorMatchboolean | FieldErrorMatch"invalid"Controls when native validation errors are shown.
requiredbooleanfalseRequired state provided to child inputs.
disabledbooleanfalseDisabled state provided to child inputs.
invalidbooleanfalseInvalid state.
dirtybooleaninput stateOverrides dirty state.
touchedbooleaninput stateOverrides touched state.
filledbooleaninput stateOverrides filled state.
focusedbooleaninput stateOverrides focused state.
uiFieldUi—Classes for root, label, control, description, error.

Slots

SlotScoped propsDescription
defaultid, fieldName, required, disabled, invalid, valid, dirty, touched, filled, focused, describedBy, controlPropsControl slot.
label—Custom label content.
description—Custom description content.
error—Custom error content.