Skip to Content

Field

Wires a label, control, description and error together with the right accessibility attributes.

Receipts are sent here.

import { Field, FieldControl, FieldDescription, FieldLabel } from "@dapplelight/signet-ui/components/field"

export function Demo() {
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Billing email</FieldLabel>
      <FieldControl type="email" placeholder="[email protected]" />
      <FieldDescription>Receipts are sent here.</FieldDescription>
    </Field>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  Field,
  FieldControl,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@dapplelight/signet-ui/components/field"

const errors = [{ message: "Enter a full email address" }]

<Field errors={errors}>
  <FieldLabel>Email</FieldLabel>
  <FieldControl type="email" />
  <FieldDescription>We send receipts here.</FieldDescription>
  <FieldError />
</Field>

Examples

Error

Receipts are sent here.

Enter a full email address
import { useState } from "react"
import { Field, FieldControl, FieldDescription, FieldError, FieldLabel } from "@dapplelight/signet-ui/components/field"

export function Demo() {
  const [email, setEmail] = useState("billing@acme")
  return (
    <Field
      className="w-full max-w-sm"
      errors={email.includes(".") ? [] : [{ message: "Enter a full email address" }]}
    >
      <FieldLabel>Billing email</FieldLabel>
      <FieldControl type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
      <FieldDescription>Receipts are sent here.</FieldDescription>
      <FieldError />
    </Field>
  )
}

Required

import { Field, FieldControl, FieldError, FieldLabel } from "@dapplelight/signet-ui/components/field"

export function Demo() {
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel>Company name</FieldLabel>
      <FieldControl required placeholder="Acme Finance" />
      <FieldError match="valueMissing">Company name is required.</FieldError>
    </Field>
  )
}

Disabled

Set when the workspace was created.

import { Field, FieldControl, FieldDescription, FieldLabel } from "@dapplelight/signet-ui/components/field"

export function Demo() {
  return (
    <Field className="w-full max-w-sm" disabled>
      <FieldLabel>Workspace ID</FieldLabel>
      <FieldControl defaultValue="ws_4f9a2c" />
      <FieldDescription>Set when the workspace was created.</FieldDescription>
    </Field>
  )
}

API Reference

Built on UI SDK's field. Every part takes that primitive's props plus className.

Field

PropTypeDefaultDescription
errorsreadonly (string | { message?: string } | null | undefined)[]noneValidation errors, such as a TanStack Form field's state.meta.errors. Any message marks the field invalid.
invalidbooleanfrom errorsForce the invalid state.
disabledbooleanfalseDisable the field and dim it.

FieldControl

Renders Signet's Input unless render is given. Takes input props.

FieldError

PropTypeDefaultDescription
childrenReactNodefirst of errorsMessage to show whenever the field is invalid.
matchvalidity flagnoneShow only for one browser validity flag, such as valueMissing.

FieldLabel, FieldDescription

Text parts; they take className and the primitive's props.