SwipeUI

Text field

Labelled text entry on a soft filled surface: a primary ring and halo on focus, inset or floating labels, icons, clear with undo, a rolling counter and messages that rise in.

npx @swipeui/cli add text-field
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Names, emails, usernames, addresses and any single line of text in a form.
  • Fields that need a helper line, an error and a success message in the same place, such as checking a username is free.
  • Inputs with a leading icon, a prefix or suffix, or a clear button that can undo itself.
  • Multi-field forms where Return should move to the next field, and compact forms with inset or floating labels.

When not to use it

  • Several lines of text. Textarea grows with its content.
  • Passwords. Password field adds a reveal action and password manager hints.
  • Search. Search field adds a search glyph, Cancel and a Search key.
  • Numbers with bounds. Number field adds steppers; Money input handles currency exactly.
  • Picking from fixed options. Use Select, Combobox or Radio group.

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 text-field
  • Adds components/swipeui/ui/text-field.tsx and 12 shared helpers.
  • Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/sign-up.tsx
import { TextField } from '@/components/swipeui/ui/text-field';

<TextField
  label="Email"
  placeholder="name@company.com"
  autoComplete="email"
  keyboardType="email-address"
  clearButton="while-editing"
/>;

Examples

A floating label with an icon and a counter that appears near the limit:

<TextField
  label="Display name"
  labelPlacement="floating"
  leadingIcon={({ color, size }) => <UserIcon color={color} size={size} />}
  counter="near-limit"
  maxLength={30}
/>

Checking a username as it's typed. The spinner shows while validating, a check draws on when valid, and a new error shakes the field once with an error haptic:

<TextField
  label="Username"
  value={name}
  onValueChange={setName}
  status={checking ? 'validating' : available ? 'valid' : 'idle'}
  success={available ? 'Username available' : undefined}
  error={taken ? 'That username is taken' : undefined}
/>

Icons take a node, or a function given { color, size }. The colour is muted at rest, primary while focused, red while invalid and muted while disabled.

API reference

PropTypeDefaultDescription
label?string—

Visible label, or inherit an enclosing Field.

helper?string—

Instructions under the field; an error or success message replaces it.

error?string—

Validation message: a destructive ring, an alert glyph, one shake and an error haptic.

success?string—

Confirmation under the field, such as "Username available", in the success colour.

status?FieldStatus'idle'

validating shows a spinner and reports busy; valid draws a check on. An error implies invalid.

required?booleanfalse

Required; "Required" is spoken, and requiredIndicator marks the label. The app owns validation.

requiredIndicator?FieldRequiredIndicator'asterisk'

How a required label is marked: a muted asterisk, the word, or nothing.

optionalIndicator?booleanfalse

Show a muted "Optional" after the label.

disabled?booleanfalse

Disable editing and accessory actions.

disabledStyle?FieldDisabledStyle'muted'

muted lightens the fill and text without opacity; dim lowers the field to 50%.

appearance?FieldAppearance'filled'

The surface: filled (a soft fill), outline (a hairline), underline or ghost (no fill until focused).

size?FieldSize'md'

Height: sm 36pt, md 44pt, lg 52pt.

shape?FieldShape'preset'

preset follows your preset's control radius; pill is a capsule.

labelPlacement?FieldLabelPlacement'above'

above, inset (small, inside at the top), floating (rests centred like a hint and rises on focus or once there's a value) or hidden (spoken only).

focusRing?FieldFocusRing'halo'

The focus indicator: a primary ring with a soft halo, the ring alone, or none.

messageMorph?FieldMessageMorph'fade'

How a changed message arrives: rises in, letter by letter, or at once.

reserveMessageSpace?booleanfalse

Keep one line of room under the field so forms don't move as messages appear.

value?string—

Controlled text.

defaultValue?string''

Initial uncontrolled text.

onValueChange?((value: string) => void)—

Reports changed text, including clearing and undo.

onChangeText?((value: string) => void)—

Native-compatible text callback, in addition to onValueChange.

displayValue?ReactNode—

Decorative rendering for an unfocused value; the native text remains the accessible/editable source.

prefix?ReactNode—

Decorative prefix or an accessible accessory, drawn first.

suffix?ReactNode—

Accessible trailing accessory, drawn last.

leadingIcon?ButtonIcon—

A leading icon: a node, or a function given the state colour and size. It turns primary while focused.

trailingIcon?ButtonIcon—

A trailing icon: a node, or a function given the state colour and size.

clearable?booleanfalse

1.x switch: true means clearButton="always".

clearButton?TextFieldClearButton'never' (or 'always' with `clearable`)

When a "Clear text" button shows.

undoClear?booleantrue

After clearing, the button becomes "Undo clear" for a moment. Phones have no ⌘Z.

undoClearWindow?number4000

How long undo stays, in milliseconds.

counter?TextFieldCounterfalse

A rolling character counter under the field, using maxLength; amber near the limit, red at it.

tintCaret?booleantrue

Caret and selection in the primary colour.

iconTint?"focus" | "none"'focus'

The leading icon turns primary while focused (focus) or stays muted (none).

shakeOnError?booleantrue

Shake once for each new error. Reduce Motion keeps it still.

messages?Partial<FieldMessages>FIELD_MESSAGES (English)

Built-in strings, for translation.

nextRef?RefObject<_TextInputInstance | null>—

Ref focused when Return is pressed; otherwise a single-line field dismisses.

haptics?boolean | FieldHapticstrue (clear, error and limit)

All feedback, or each part: { clear, error, valid, limit, focus }.

motion?MotionOverridethe app feel

Ring, label and message motion.

className?string—

Classes on the outer field.

controlClassName?string—

Classes on the field surface.

inputClassName?string—

Classes on the editable text.

style?StyleProp<ViewStyle>—

Outer field style.

inputStyle?____TextStyleProp_Internal—

Native editable text style.

Native TextInput props such as autoComplete, keyboardType and maxLength pass through, and the ref is the native input.

Composition and behavior

  • appearance picks the surface. filled is a soft fill that reads on backgrounds and cards in every preset; outline is a hairline; underline grows a bar from the centre on focus; ghost has no fill until focused. Corners follow your preset's control radius; shape="pill" makes a capsule.
  • Focusing shows a primary ring and a soft halo just outside it, drawn as a border so it looks the same on iOS, Android and the web. Leave 4 points around the field so a clipping parent doesn't cut the halo.
  • labelPlacement inset draws a small label inside the field. floating rests the label on the field's centre, like a hint, and raises it on focus or once there's a value, so autofill raises it too.
  • clearButton shows a Clear text button while-editing, unless-editing or always. After a clear, it becomes Undo clear for 4 seconds (undoClear, undoClearWindow); phones have no ⌘Z.
  • counter rolls a count under the field using maxLength. It turns amber at 90% and red at the limit, plays a warning haptic there, and announces when 10% remains.
  • Messages under the field rise in while the row's height springs. An error replaces the helper and success text, rings the field in red and shakes it once.
  • Return moves to nextRef; otherwise a single-line field closes the keyboard. On an enclosing Field, the look, label and messages come from the Field.
  • For the 1.x look, pass appearance="outline" disabledStyle="dim". Every 1.x prop still works.

Text field settings

PropDoesDefault
appearancefilled, outline, underline or ghostfilled
size / shapesm, md, lg; preset or pillmd, preset
labelPlacementabove, inset, floating or hiddenabove
leadingIcon / trailingIconA node, or a function given { color, size }none
iconTintThe leading icon turns primary while focusedfocus
clearButtonnever, while-editing, unless-editing or alwaysnever
undoClear / undoClearWindowUndo after clearing, and for how long (ms)true, 4000
countertrue, near-limit (from 80%) or falsefalse
statusidle, validating, valid or invalididle
helper / error / successMessages under the fieldnone
required / requiredIndicatorRequired, marked by asterisk, word or nonefalse, asterisk
optionalIndicator"Optional" after the labelfalse
focusRinghalo, ring or nonehalo
shakeOnErrorOne shake per new errortrue
tintCaretCaret and selection in the primary colourtrue
messageMorphfade, characters or nonefade
reserveMessageSpaceKeep a line for messages so forms don't movefalse
disabledStylemuted (no opacity) or dim (50%)muted
hapticsAll, or { clear, error, valid, limit, focus }clear, error, limit
messagesBuilt-in strings, for translationEnglish
motionA local motion feel or overridethe app's feel

Behavior and gestures

  • Tapping the field focuses it: a primary ring fades in with a soft halo, and the leading icon turns primary (iconTint).
  • appearance switches the surface: filled (default), outline, underline (a bar grows from the centre) or ghost (no fill until focused).
  • labelPlacement inset draws a small label inside the field; floating rests the label on the text line and raises it as you focus or once there's a value, including autofill.
  • clearButton shows Clear text never, while editing, unless editing or always (clearable is the 1.x switch for always). After clearing, Undo clear restores the text for undoClearWindow milliseconds (undoClear).
  • counter rolls a count under the field using maxLength: always, or from 80% with near-limit. It turns amber at 90% and red at the limit, with a warning haptic.
  • status validating shows a spinner; valid draws a check on. success shows a green message; error shows a red one, rings the field in red, shakes it once (shakeOnError) and plays an error haptic.
  • Return moves focus to nextRef if you pass one; otherwise a single-line field closes the keyboard.
  • haptics switches feedback for clear, error, valid, limit and focus separately; false turns all of it off.

Accessibility

  • The visible label is the field's name, linked to the input; inset and floating labels are drawn inside but spoken only through the input.
  • Helper, error and success text are read as the field's hint; new errors are announced without moving focus. "Required" is spoken; the asterisk isn't.
  • Clear text and Undo clear are separate 44pt buttons, and clearing announces that undo is available.
  • Validating reports busy; reaching valid is announced once unless a success message already says so.
  • The counter is hidden from screen readers; the field announces when 10% remains and when the limit is reached.
  • Text grows with Dynamic Type; fields use minimum heights only, and RTL mirrors icons, accessories and the floating label's origin.

Motion

  • Uses the toggle, morph, layout, number, press and ambient motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • The ring and halo fade in on the toggle role; the halo settles from 98% to full size.
  • The floating label travels and shrinks on the morph role; messages rise in on morph and the row height springs on layout.
  • Counter digits roll on the number role; the validating spinner turns on the ambient role.
  • Accessories press in on the press role, and a new error shakes the field once on its timing.
  • Reduce Motion: the ring cross-fades, the label moves at once and fades in place, the shake and halo scale go, and the spinner holds still.

Performance

  • A native TextInput underneath; the ring, halo, label and message row animate in their own leaves on the UI thread.
  • Works controlled with value and onValueChange, or uncontrolled with defaultValue.

Notes for AI

  • Always pass label (or accessibilityLabel when the label is hidden); use helper for instructions, error for validation and success for confirmation.
  • Chain fields with nextRef for faster form entry.
  • Pick one appearance per form; set it once on each field or on an enclosing Field.
  • Use clearButton="while-editing" for search-like fields and keep undoClear on.
  • Translate built-in strings with messages.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items