Skip to content

← All components

Actions and forms

Field

Label, hint, required, and error message composition.

Live example

Use a short, recognizable name.

Usage

Each example includes the complete adapter-specific parameter reference. Copy it as a starting point, then remove options your use case does not need.

React

tsx
import { Field } from "@cofob/design-system-react";

/**
 * Complete Field parameter reference.
 * @param label
 *   type: string | renderable content
 *   required
 *   example: "Accessible label"
 * @param htmlFor/forId
 *   type: string
 *   default: —
 *   example: "email"
 * @param hint/description
 *   type: string | renderable content
 *   default: —
 *   example: "We will only use this for updates."
 * @param error
 *   type: string | renderable content
 *   default: —
 *   example: "Enter a valid value."
 * @param required
 *   type: boolean
 *   default: false
 *   example: true
 * @param hintId/errorId
 *   type: string (React)
 *   default: —
 *   example: hintId="email-hint" errorId="email-error"
 * @param children
 *   type: ReactNode | Svelte Snippet | child HTML
 *   default: —
 *   example: children / snippet / child HTML
 * @param div attributes
 *   type: native element attributes
 *   default: —
 *   example: class / style / aria-* / data-*
 */
export function FieldExample() {
  return (
    <Field label="Email"><input /></Field>
  );
}

Svelte

svelte
<script lang="ts">
  import { Field } from "@cofob/design-system-svelte";

  // Complete Field parameter reference.
  // label
  //   type: string | renderable content
  //   required
  //   example: "Accessible label"
  // htmlFor/forId
  //   type: string
  //   default: —
  //   example: "email"
  // hint/description
  //   type: string | renderable content
  //   default: —
  //   example: "We will only use this for updates."
  // error
  //   type: string | renderable content
  //   default: —
  //   example: "Enter a valid value."
  // required
  //   type: boolean
  //   default: false
  //   example: true
  // children
  //   type: ReactNode | Svelte Snippet | child HTML
  //   default: —
  //   example: children / snippet / child HTML
  // div attributes
  //   type: native element attributes
  //   default: —
  //   example: class / style / aria-* / data-*
</script>

<Field label="Email" forId="email"><input id="email" /></Field>

HTML

html
<!--
  Complete Field parameter reference.
  label
    type: string | renderable content
    required
    example: "Accessible label"
  htmlFor/forId
    type: string
    default: —
    example: "email"
  hint/description
    type: string | renderable content
    default: —
    example: "We will only use this for updates."
  error
    type: string | renderable content
    default: —
    example: "Enter a valid value."
  required
    type: boolean
    default: false
    example: true
  children
    type: ReactNode | Svelte Snippet | child HTML
    default: —
    example: children / snippet / child HTML
  div attributes
    type: native element attributes
    default: —
    example: class / style / aria-* / data-*
-->
<label class="cf-field">Email <input class="cf-input" /></label>

Parameters

Adapter differences are explicit. Native element attributes are forwarded in React and Svelte and can be written directly in HTML.

ParameterTypeDefaultAdaptersExampleDescription
labelrequiredstring | renderable contentrequiredReact · Svelte · HTML"Accessible label"Visible or accessible name, depending on the component.
htmlFor/forIdstringReact · Svelte · HTML"email"Associates the field label with its form control.
hint/descriptionstring | renderable contentReact · Svelte · HTML"We will only use this for updates."Supporting text announced with the control.
errorstring | renderable contentReact · Svelte · HTML"Enter a valid value."Validation message and invalid visual/ARIA state.
requiredbooleanfalseReact · Svelte · HTMLtrueMarks the label and control as required.
hintId/errorIdstring (React)ReacthintId="email-hint" errorId="email-error"Overrides generated descriptive IDs in React.
childrenReactNode | Svelte Snippet | child HTMLReact · Svelte · HTMLchildren / snippet / child HTMLIdiomatic adapter composition content.
div attributesnative element attributesReact · Svelte · HTMLclass / style / aria-* / data-*Forwards native class/style, accessibility, event, and data attributes to the root element.