Skip to content

Field

A form control with its label, hint and error, wired together for screen readers.

Base UI0.8 kB gzipSource Registry JSON

Field playground

Lowercase and dashes.

Props

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/field.json

The CLI writes components/ikada/field.tsx and merges the ikada theme into your CSS. It also installs the components it is built from: Label. Or take it from the package: import { Field } from "@sproutboat/ikada";

Usage

import { Field } from "@/components/ikada/field";

<Field label="Project name" description="Lowercase and dashes.">
  <Input defaultValue="robin" />
</Field>

Examples

With a hint

The label and the hint are wired to the control, so screen readers read both.

Lowercase and dashes.

Required

The asterisk is for sighted users; set required on the control for validation.

Error

A message makes the field invalid and is announced.
robin.sproutboat.app is already taken.

Disabled

Fixed once the sprout exists.

Props

FieldProps
PropTypeDescription
classNamestringClasses merged onto the root element, after ikada's own.
labelrequiredReactNodeVisible label, linked to the control inside.
descriptionReactNodeMuted help text under the control, linked as its description.
errorReactNodeWhen set the field is invalid and the message is announced.
requiredbooleanAdds an asterisk to the label. Set `required` on the control too for validation.
childrenrequiredReactNodeOne control: Input, Select, Checkbox... Base UI wires id and aria.
styleCSSProperties | ((state: FieldRootState) => CSSProperties)Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, FieldRootState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also takes every prop of Omit<ComponentProps<typeof BaseField.Root>, "className" | "children">.

Source: src/components/field.tsx