Skip to content
Forms Core Stable

FormField

.md

Wraps a control with a label, help/error text and id wiring, so a screen reader gets the full picture without manual aria plumbing

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { FormField } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { FormField } from "fancy-ui-svelte";
</script>

<!--
  A context-aware control (Input and friends, elsewhere in this library)
  reads its id and aria-describedby off FormField's context automatically.
  This plain <input> stands in for one and mirrors that wiring by hand —
  see the FormField README for the full, no-manual-wiring picture.
-->
<FormField id="signup-email" label="Email" description="We'll only use this to send your receipt.">
	{#snippet children()}
		<input
			id="signup-email"
			type="email"
			placeholder="you@example.com"
			aria-describedby="signup-email-description"
			class="border-input bg-background placeholder:text-muted-foreground focus-visible:ring-ring/50 focus-visible:border-ring w-full rounded-lg border px-3 py-[9px] text-[13px] outline-none focus-visible:ring-2"
		/>
	{/snippet}
</FormField>

Examples

Basic Usage

A labelled field with help text underneath.

With Error

error replaces the help text and marks the field invalid.

Validated

valid's decorative checkmark, plus a control drawing its own success look.

Disabled

disabled reaches the control through context.

Props

PropTypeDefaultDescription
label string-Label text — the common case. For custom label markup, render a Label in children instead
description string-Help text under the control, replaced by error while the field is invalid
error string-Error text. Setting it marks the field invalid and replaces the help text
valid booleanfalseDecorative checkmark next to the help text; error always wins if both are set
required booleanfalseMarks the field required: the label gets an asterisk, the control gets aria-required
disabled booleanfalseDisables the field: reaches the wrapped control through context
id string-Opts out of the generated id. description/error ids are suffixes of this same value
class string-Additional CSS classes, merged onto the root
ref HTMLDivElement | nullnullBindable reference to the root element

Slots

SlotDescription
children The control