ZUI

Search documentation

Find a page or a heading.

Field

The layout of a form, with labels, controls, descriptions and errors.

Installation

bash

The CLI writes components/ui/field.tsx, installs Text, Separator, Text children and Utils, and adds @rn-primitives/label.

Usage

tsx
tsx

API reference

Field

Takes every prop of React Native's View, plus:

It is a group. vertical stacks its children; horizontal sets them in a row, such as a Switch beside its label, aligned to the top when the row holds a FieldContent; responsive stacks them. invalid draws the label in the destructive colour, and disabled dims the label and the title; pass the control its own aria-invalid and disabled.

FieldLabel

Takes every prop of the @rn-primitives/label root, plus nativeID, the id the control names in aria-labelledby, which Android reads and iOS ignores; give the control the label's text as aria-label too. Its children are the label's text. Pressing it runs onPress; point it at the control's focus(). In a horizontal Field it takes the room the control leaves.

FieldContent

Takes every prop of React Native's View. In a horizontal Field it holds the label and the description beside the control.

FieldTitle, FieldDescription

Each takes every prop of Text. FieldTitle names content that is not a control, drawn as a label is. FieldDescription is the muted help text.

FieldError

Takes every prop of React Native's View, plus errors, an array of { message } from a form library. It draws its children in the destructive colour, or else the messages of errors, each once, as a list when there are several. With neither, it draws nothing. It carries the alert role, and a screen reader announces a text message when it appears or changes: TalkBack through a polite live region, VoiceOver through an announcement. Children other than a string are drawn but not announced.

FieldGroup

Takes every prop of React Native's View. It spaces its Fields apart, and a FieldGroup inside another more tightly.

FieldSet, FieldLegend

FieldSet takes every prop of React Native's View and is a group named by its FieldLegend. FieldLegend takes every prop of Text, plus variant, 'legend' (the default, at the base size) or 'label' (at a label's size). A FieldDescription right after the legend sits close under it.

FieldSeparator

Takes every prop of React Native's View. It draws a rule, with its children, such as a string, centred on it in the muted colour.

Differences from upstream

  • Upstream marks a field invalid or disabled with data-invalid and data-disabled attributes. React Native takes no data attributes, so the native Field takes invalid and disabled.
  • A web label names and focuses its control through htmlFor. React Native has no such link: name the control with aria-label, which iOS and Android both read, and with aria-labelledby, which only Android reads, and focus it from the label's onPress.
  • Upstream's responsive Field turns into a row on a wide container. A phone is narrower than that, so it stays stacked.
  • Upstream draws a FieldLabel that wraps a whole Field, such as a checkbox with its text, as a bordered choice card. The native FieldLabel draws no card.
  • Upstream tightens the gap above a FieldSet's description and a field's last description with selectors on their position. The native items tighten only the description right after a legend.
  • Upstream spaces a FieldSet holding a checkbox group or a radio group more tightly. The native FieldSet keeps its own gap.