Forms

FormField

Wrap any form control with labels, descriptions, hints, error messages, and help text. Provides context to child components for automatic error handling and sizing.

Playground

Experiment with different props in real-time.

Required

Your work email

We'll send a confirmation

Basic Usage

Wrap a form control with a label.

<script lang="ts">
  import { FormField, Input } from 'sv5ui';
</script>

<FormField label="Email">
  <Input placeholder="you@example.com" />
</FormField>

Description

Add context below the label.

Must be at least 8 characters

<FormField label="Password" description="Must be at least 8 characters">
  <Input type="password" placeholder="Enter password" />
</FormField>

Hint

Display a hint next to the label (right side).

Required
Optional
<FormField label="Username" hint="Required">
  <Input placeholder="johndoe" />
</FormField>

<FormField label="Bio" hint="Optional">
  <Textarea placeholder="Tell us about yourself..." />
</FormField>

Help Text

Display help text below the control.

Include the full URL with https://

<FormField label="Website" help="Include the full URL with https://">
  <Input placeholder="https://example.com" leadingIcon="lucide:globe" />
</FormField>

Error

Error message replaces help text and auto-highlights the child control.

Please enter a valid email address

Password is too short

<!-- String error message -->
<FormField label="Email" error="Please enter a valid email address">
  <Input placeholder="you@example.com" />
</FormField>

<!-- Boolean error (no message) -->
<FormField label="Name" error={true}>
  <Input placeholder="Your name" />
</FormField>

<!-- Error replaces help text -->
<FormField label="Password" help="Must be 8+ chars" error="Password is too short">
  <Input type="password" />
</FormField>

Required

Adds a red asterisk to the label.

We'll never share your email
<FormField label="Full Name" required>
  <Input placeholder="John Doe" />
</FormField>

<FormField label="Email" required hint="We'll never share your email">
  <Input type="email" placeholder="you@example.com" />
</FormField>

Sizes

Controls label and text size. Also propagates to child components.

<FormField label="Extra Small" size="xs">
  <Input placeholder="XS input" />
</FormField>

<FormField label="Small" size="sm">
  <Input placeholder="SM input" />
</FormField>

<FormField label="Medium" size="md">
  <Input placeholder="MD input" />
</FormField>

<FormField label="Large" size="lg">
  <Input placeholder="LG input" />
</FormField>

Horizontal

Side-by-side label and control layout.

<FormField label="Name" orientation="horizontal">
  <Input placeholder="John Doe" />
</FormField>

<FormField label="Email" orientation="horizontal" required>
  <Input type="email" placeholder="you@example.com" />
</FormField>

<FormField label="Role" orientation="horizontal">
  <Select items={roles} placeholder="Select role" />
</FormField>

With Input

Find anything in your workspace

USD
<FormField label="Search" description="Find anything in your workspace">
  <Input icon="lucide:search" placeholder="Search..." />
</FormField>

<FormField label="Amount" hint="USD">
  <Input type="number" leadingIcon="lucide:dollar-sign" placeholder="0.00" />
</FormField>

With Textarea

Describe your issue in detail

Markdown supported

<FormField label="Message" description="Describe your issue in detail" help="Markdown supported">
  <Textarea placeholder="Type your message..." autoresize />
</FormField>

With Select & SelectMenu

Choose your preferred framework

<FormField label="Country" required>
  <Select items={countries} placeholder="Select a country" />
</FormField>

<FormField label="Framework" description="Choose your preferred framework">
  <SelectMenu items={frameworks} placeholder="Search frameworks..." />
</FormField>

With CheckboxGroup

<FormField label="Preferences">
  <CheckboxGroup items={[
    { value: 'email', label: 'Email notifications' },
    { value: 'sms', label: 'SMS notifications' },
    { value: 'push', label: 'Push notifications' }
  ]} />
</FormField>

With Switch

Toggle dark theme

<FormField label="Dark Mode" description="Toggle dark theme">
  <Switch />
</FormField>

Complete Form

A real-world registration form combining multiple form components.

We'll never share it

Must be at least 8 characters

Optional
<form class="space-y-6">
  <FormField label="Full Name" required>
    <Input placeholder="John Doe" />
  </FormField>

  <FormField label="Email" required hint="We'll never share it">
    <Input type="email" placeholder="you@example.com" leadingIcon="lucide:mail" />
  </FormField>

  <FormField label="Password" required description="Must be at least 8 characters">
    <Input type="password" placeholder="Enter password" />
  </FormField>

  <FormField label="Role">
    <Select items={roles} placeholder="Select role" />
  </FormField>

  <FormField label="Bio" hint="Optional">
    <Textarea placeholder="Tell us about yourself..." autoresize />
  </FormField>

  <FormField label="Notifications">
    <Switch label="Receive email updates" />
  </FormField>

  <Button type="submit" label="Create Account" block />
</form>

UI Slots

Use the ui prop to override classes on internal elements.

SlotDescription
rootOutermost wrapper
wrapperContains label section and description
labelWrapperFlex container for label and hint
labelLabel text element
descriptionDescription text below label
hintHint text next to label
containerContains form control + error/help
errorError message text
helpHelp text below control

Snippets

SnippetDescription
childrenForm control content (receives error state)
labelSlotCustom label rendering
hintSlotCustom hint rendering
descriptionSlotCustom description rendering
helpSlotCustom help text rendering
errorSlotCustom error rendering

Props

PropTypeDefault
labelstring-
descriptionstring-
hintstring-
helpstring-
errorstring | boolean-
namestring-
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
orientation'vertical' | 'horizontal''vertical'
requiredbooleanfalse
refHTMLElement | nullnull
classstring-
uiRecord<Slot, Class>-