Field
The shared field language: a label, a filled surface with a focus ring and halo, and a message row that springs open for helper, error, success and counter text.
npx @swipeui/cli add fieldWhen to use it
- Giving any custom control, such as a date picker, slider or rating, a proper label, helper, error and success message.
- Building your own input on the same filled surface, focus ring and halo as SwipeUI's fields with FieldSurface.
- A picker that opens a sheet or menu: FieldTrigger draws the value, a muted placeholder and a chevron that turns while open.
- Setting the look of several fields at once: appearance, size, shape and label placement flow from Field to the control inside.
When not to use it
- Text inputs alone; Text field already includes a Field.
- Grouping several controls under one heading. Use List section or a heading.
- Section titles that aren't attached to a control.
- Buttons. A trigger that runs an action rather than opening a choice is a Button.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add field- Adds
components/swipeui/ui/field.tsx,components/swipeui/ui/field-context.ts,components/swipeui/ui/field-styles.ts,components/swipeui/ui/field-surface.tsx,components/swipeui/ui/field-message.tsx,components/swipeui/ui/field-glyphs.tsx,components/swipeui/ui/field-action.tsx,components/swipeui/ui/field-trigger.tsx,components/swipeui/ui/use-field-focus.tsand 10 shared helpers. - Installs class-variance-authority, react-native-reanimated, react-native-svg, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Field } from '@/components/swipeui/ui/field';
<Field label="Email" helper="Use your work address">
<EmailInput />
</Field>;Examples
A picker trigger: the value sits at the start, the placeholder is muted, and while open the ring shows and the chevron turns.
import { Field, FieldTrigger } from '@/components/swipeui/ui/field';
<Field label="Country" helper="Where you pay tax">
<FieldTrigger
value={country}
placeholder="Choose a country"
open={open}
onPress={() => setOpen(true)}
/>
</Field>;Your own control on the same surface, focus ring and halo:
import { FieldSurface } from '@/components/swipeui/ui/field';
function PinBox({ focused, digits }: { focused: boolean; digits: string }) {
return (
<FieldSurface focused={focused} size="lg">
<Text className="font-mono text-title-3">{digits.padEnd(4, '•')}</Text>
</FieldSurface>
);
}API reference
| Prop | Type | Default | Description |
|---|---|---|---|
label | | — | The visible and spoken name. Placeholders never replace a label. An empty string hides it visually. |
helper? | | — | Additional instructions, replaced by an error or success message. |
error? | | — | Validation message. New messages are announced, shake the control once and play an error haptic. |
success? | | — | Confirmation, such as "Username available". Replaces the helper; an error replaces it. |
status? | | | Validation state the control shows: a spinner while |
required? | | | Whether a value is required. |
requiredIndicator? | | | How a required field is marked: a red asterisk, the word, or nothing. "Required" is always spoken. |
optionalIndicator? | | | Show a muted "Optional" after the label. |
disabled? | | | Disables the enclosed control through context. |
disabledStyle? | | |
|
appearance? | | | Surface look passed to the control. |
size? | | | Control size passed to the control. |
shape? | | | Control shape passed to the control. |
labelPlacement? | | | Where the label sits. |
align? | | | Where the label and message sit across the row. Compact controls that centre themselves (Number field, OTP input) centre these too. |
focusRing? | | | Focus indicator passed to the control. |
messageMorph? | | | How a changed message arrives. |
reserveMessageSpace? | | | Keep one line of room under the control even when there's no message. |
count? | | — | A character count shown at the end of the message row. Text field sets this from its |
messages? | | | Built-in strings, for translation. |
motion? | | | Motion for the message row, ring and label. |
id? | | — | Stable control identifier; generated when omitted. |
children | | — | One editable control and optional accessory content. |
className? | | — | Classes merged over the field layout. |
labelClassName? | | — | Classes merged over the label. |
style? | | — | Native style escape hatch. |
testID? | | — | Root test identifier; parts append -label, -message, -description and -counter. |
Composition and behavior
- label names the control; placeholders never replace it. An empty label hides it visually and keeps the spoken name.
- helper, error and success share one row under the control. Its height springs as messages come and go, and a new message rises in. Errors carry an alert glyph; success carries a check that draws on.
- appearance, size, shape, labelPlacement and focusRing pass down to the control, so a Text field or Field trigger inside picks them up.
- disabled passes down too.
disabledStyle="muted"lightens the control without opacity;dimlowers the whole field to 50% once. - required speaks "Required" in the hint and marks the label with a quiet asterisk or the word (requiredIndicator). optionalIndicator adds "Optional".
- Build your own controls with
FieldSurface,FieldAction(a 44pt accessory that keeps focus in the input),FieldGlyphandFieldMessage, all exported fromfield.useField()gives you the label, hint, state and look.
Field settings
| Prop | Does | Default |
|---|---|---|
| helper / error / success | Messages under the control | none |
| status | idle, validating, valid or invalid | idle |
| required / requiredIndicator | Required, marked by asterisk, word or none | false, asterisk |
| optionalIndicator | "Optional" after the label | false |
| appearance | filled, outline, underline or ghost, for the control | the control's (filled) |
| size / shape | sm, md, lg; preset or pill, for the control | the control's |
| labelPlacement | above, inset, floating or hidden | above |
| align | Label and message at the start, center or end, to match a centred control | start |
| focusRing | halo, ring or none, for the control | halo |
| messageMorph | fade, characters or none | fade |
| reserveMessageSpace | Keep a line for messages so forms don't move | false |
| count | A counter at the end of the message row | none |
| disabled / disabledStyle | Off, drawn muted or dim | false, muted |
| messages | Built-in strings, for translation | English |
| motion | A local motion feel or override | the app's feel |
Behavior and gestures
- Field doesn't respond to touch; it labels and describes the control inside it, and passes the look down through context.
- When an error appears it replaces the helper (and success) line: the row springs to its new height, the text rises in with an alert glyph, the control shakes once and an error haptic plays.
- Success messages show in the success colour with a check that draws on.
- The message row's height springs as messages arrive and leave; reserveMessageSpace keeps one line so the form never moves.
- A counter at the end of the row rolls its digits; it turns amber near the limit and red at it.
- Setting disabled turns off the control inside; disabledStyle muted (the default) lightens it without opacity, dim lowers it to 50% once.
- FieldSurface shows a primary ring and a soft halo while focused and a destructive ring while invalid; focusRing switches the halo or the whole ring off.
Accessibility
- The label is linked to the control so screen readers read them together; placeholders never replace it.
- Helper, error and success text become the control's hint. "Required" is spoken; the asterisk is drawn but hidden.
- New errors and success messages are announced politely without moving focus; on iOS they're announced explicitly once.
- The counter is hidden from screen readers; text fields announce when 10% remains and when the limit is reached.
- Nested fields stay separate, so inner controls never steal an outer label.
- An empty label hides it visually while keeping the spoken name.
- The halo, ring and glyphs are decorative; FieldTrigger is named "<label>, <value>" and reports expanded.
Motion
- Uses the
toggle,morph,layout,numberandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The ring and halo fade in on the toggle role, and the halo settles from 98% to full size; under Reduce Motion they cross-fade quickly with no scale.
- Messages rise 4pt as they fade in on the morph role and fade out on its exit timing; the row height springs on the layout role.
- Counter digits roll on the number role; the success check draws on along its stroke.
- A new error shakes the control once on the press timing; Reduce Motion keeps it still and the haptic and ring stay.
- The trigger chevron turns half a turn while open; under Reduce Motion it simply points the other way.
Performance
- A small context provider; each animated part (ring, halo, underline, message row) is its own leaf, so typing never re-renders the label.
- The message row measures one plain inner view and springs a single shared value.
Notes for AI
- Wrap exactly one editable control per Field. Custom controls call useField() for the label, description, state and look, and draw on FieldSurface.
- Use Text field for text; use FieldTrigger for anything that opens a picker.
- Pass appearance, size, shape and labelPlacement on Field to set the look for the control inside; the default is filled.
- Every built-in string is in messages, for translation.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.