Field
A label, a control, help text and an error message, wired together for screen readers. Validation stays with your app or form library.Basic
Preview
Code
Installation
Package
CLI (copy source)
pnpm
pnpm add @advui/corenpm
npm install @advui/coreUsage
import { Field, Input } from '@advui/core'
<Field label="Email" description="We never share it." error={errors.email?.message} required>
<Input value={email} onChangeText={setEmail} />
</Field>Examples
With help text
Preview
Code
3–20 letters or numbers. Others see it on your profile.
Required and optional
Preview
Code
Error message
Type a valid email or a longer password: the app sets `error`, Field shows it.Preview
Code
Enter an email like you@example.org.
At least 8 characters.Too short.
Disabled
Preview
Code
You can add notes once the order ships.
Horizontal
Preview
Code
Shown on your profile.
Team
Control in a layout
The Input gets the label and help text; the Button is left alone.Preview
Code
Paste the code from your email, or send a new one.
Elements as label, help and error
Preview
Code
Starts with sk_. Keep it secret.This key was revoked. Create a new one in Settings.
In a Form
Preview
Code
API reference
Field
A View that takes every view prop (`padding`, `width`, `backgroundColor`, `theme`, media props, `testID`…). It tells the control inside it, at any depth, its id, state and descriptions through context, and never clones its children. Every core form control reads it: Input, Textarea, Select, Checkbox, Checkbox Group, Switch, Radio Group, Password, Number and OTP Input, the date and time pickers, Combobox, Autocomplete, Multi Select, File Upload, Rich Text Editor and Markdown Editor.| Prop | Type | Default | Description |
|---|---|---|---|
children required | ReactNode | — | The control, or a layout with one control in it (an Input next to a Button). |
label | ReactNode | — | Visible label, linked to the control. Without one, give the control an `aria-label`. |
description | ReactNode | — | Help text under the control. Stays visible when there is an error. |
error | ReactNode | — | Error message under the help text. It marks the control invalid; `undefined`, `null`, `false` and `""` mean no error. |
required | boolean | false | Required marker on the label and `aria-required` on the control. |
optional | boolean | false | Adds "(optional)" to the label. `required` wins when both are set. |
optionalText | string | '(optional)' | The text `optional` adds, e.g. for another language. |
requiredText | string | 'required' | Read after the label on iOS and Android when `required` is set ("Email, required"): they have no required state. |
disabled | boolean | false | Dims the label and disables the control. Also on while the surrounding Form is `disabled`. |
orientation | 'vertical' | 'horizontal' | 'vertical' | `horizontal` puts the label beside the control, in a third of the width, with the help and error text under the control. |
gap | SpaceTokens | number | '2' | Space between the label, control and messages. |
fullWidth | boolean | false | Fills the container's width, e.g. in a horizontal Form. |
id | string | — | The control's id, which the label targets. Defaults to the `id` of a single child, or a generated one. |
useFieldControl
For your own controls: `const props = useFieldControl(ownProps)` fills in what the surrounding Field decides, so a Field wires your control like a core one. Outside a Field it returns the props unchanged, except `disabled`, which is `true` inside a disabled Form.| Prop | Type | Default | Description |
|---|---|---|---|
id | string | — | The id the label targets. The control’s own `id` wins. |
invalid | boolean | — | `true` when the field has an error, or the control is `invalid` itself. |
disabled | boolean | — | `true` when the field, the surrounding Form or the control is disabled. A disabled Form disables the control even without a Field. |
aria-required | boolean | — | `true` when the field is `required`. |
aria-describedby | string | — | Web: the ids of the error and help text, after the control’s own. |
aria-label | string | — | Native: the text of the label. The control’s own wins. |
accessibilityHint | string | — | Native: the text of the error and help text. |
Accessibility
- The label targets the control (
htmlFor↔id), so clicking it focuses the control. A Radio Group or Checkbox Group is named witharia-labelledbyinstead. - Help and error text are linked with
aria-describedbyon web (error first). On native, the text of the label names the control, the help and error text become its hint, and the visible label is hidden from screen readers so it is not read twice. - An error sets
aria-invalidon the control; the message is text, not just a red border. requiredsetsaria-requiredon the control, so screen readers say "required"; the asterisk itself is hidden from them. iOS and Android have no required state, so there the control’s name ends inrequiredText("Email, required"). "(optional)" is part of the label.- A disabled field disables its control, so it leaves the Tab order and is announced as dimmed.
Responsive behavior
orientation is a plain prop, not a style, so the markup never depends on the screen size. Use vertical (the default) on narrow screens.
Platform notes
iOS
The text of the label names the control, and the help and error text become the VoiceOver hint. iOS has no required or invalid state for screen readers, so put it in the error text.
Android
The text of the label names the control, and the help and error text become the TalkBack hint. Android has no required or invalid state for screen readers, so put it in the error text.