Components

Field

Groups a control with its label, description and error, and wires up the ARIA between them.

Usage

import { Field, FieldDescription, FieldError, FieldLabel } from 'nyctoui/field'

<Field>
  <FieldLabel>Team name</FieldLabel>
  <Input />
  <FieldDescription>Shown in the sidebar.</FieldDescription>
  <FieldError />
</Field>

The label and description are linked to the input for you, so it needs no id or aria-label.

Good for

  • Each field of a sign-up or checkout form, with its label, hint and error.
  • A settings form in an admin panel, such as workspace name and URL.
  • A custom control, like a segmented control or a color picker, that still needs a label and an error.
  • An address form with native validation on required fields.

Examples

Invalid

Set invalid to mark the field from your own validation. FieldError match shows the message whenever the field is invalid.

Native validation

Give match a validity state to show a message for one kind of problem. Here the field checks itself when it loses focus.

Disabled

Disabling the field disables its control and dims the label.

Best practices

Do
  • Give every field a FieldLabel, even when the design hides it.
  • Use FieldDescription for format hints, like “At least 8 characters”, before people type.
  • Write errors that say how to fix the problem: “Email needs an @”, not just a red border.
  • Show errors after people leave the field or submit, not on every keystroke.
Don’t
  • Use the placeholder as the label. It disappears as soon as people type.
  • Mark every field as required. Mark the optional ones, or the required ones, whichever is fewer.
  • Use a field’s error for a message about the whole form, such as a failed save. Put that above the form.

API reference

Field

Wraps ui-sdk’s Field and accepts its props. Errors show once a submit finds the control invalid, or at once with invalid.

PropTypeDefault
invalid
Marks the field invalid, regardless of native validity.
boolean—
disabled
Disables the control and dims the label.
booleanfalse
name
The name the control submits under, when it sets none of its own.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FieldLabel

A <label> linked to the field’s control.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FieldDescription

Help text linked to the control with aria-describedby.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

FieldError

Shown when the field is invalid.

PropTypeDefault
match
true shows the message whenever the field is invalid; a validity state shows it for that problem only.
boolean | keyof ValidityState—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—