Phi
Field
@dicehub/phiv1.0.0-beta.1

Field

A form field wrapper that composes a label, control, helper text, and error text.

<script setup>
import { Field } from "@dicehub/phi/components/field";
import { Input } from "@dicehub/phi/components/input";
</script>

<template>
  <Field
    id="email"
    label="Email"
    description="We'll never share your email"
  >
    <Input id="email" placeholder="[email protected]" type="email" />
  </Field>
</template>

Installation

Barrel

import { Field } from "@dicehub/phi";

Granular

import { Field } from "@dicehub/phi/components/field";

Examples

Error State

Use string or structured errors to mark the field invalid and render error text.

<script setup>
import { Field } from "@dicehub/phi/components/field";
import { Input } from "@dicehub/phi/components/input";
</script>

<template>
  <Field
    id="password"
    label="Password"
    :error="{ message: 'Password must be at least 8 characters', match: 'tooShort' }"
    required
  >
    <Input id="password" default-value="short" type="password" :minlength="8" />
  </Field>
</template>

Optional Field

Set required to false to show the optional marker and attach a label tooltip.

<script setup>
import { Field } from "@dicehub/phi/components/field";
import { Input } from "@dicehub/phi/components/input";
</script>

<template>
  <Field
    id="phone"
    label="Phone number"
    label-tooltip="Used only for account recovery"
    :required="false"
  >
    <Input id="phone" placeholder="+1 (555) 000-0000" type="tel" />
  </Field>
</template>

Hidden Label

Use hideLabel when another component owns the visible label but Field still owns helper or error text.

<script setup>
import { Field } from "@dicehub/phi/components/field";
import { Input } from "@dicehub/phi/components/input";
</script>

<template>
  <Field
    id="api-key"
    label="API key"
    hide-label
    description="The visible label can be owned by a parent layout."
  >
    <Input id="api-key" aria-label="API key" placeholder="sk_live_..." />
  </Field>
</template>

API Reference

Props

PropTypeDefaultDescription
idstring-Field id. Use the same id on the wrapped control.
labelstring-Label text. Use the label slot for richer content.
descriptionstring-Helper text shown when there is no error.
errorstring | { message: string; match?: FieldErrorMatch }-Validation error text.
requiredboolean-Marks the field required. `false` shows the optional marker.
labelTooltipstring-Tooltip text displayed beside the label.
controlFirstbooleanfalsePlaces checkbox or switch controls before the label.
hideLabelbooleanfalseSkips rendering the visible label.
disabledbooleanfalseMarks the field disabled.
invalidbooleanfalseMarks the field invalid even without an error message.
readOnlybooleanfalseMarks the field read-only.
class / classNamestring | object | array-Additional classes for the root.

Slots

SlotDescription
defaultWrapped form control.
labelCustom label content.
descriptionCustom helper text.
errorCustom error content.

Validation Error Types

Match
badInput
customError
patternMismatch
rangeOverflow
rangeUnderflow
stepMismatch
tooLong
tooShort
typeMismatch
valid
valueMissing