TextInput and Forms
Text entry, keyboard configuration, focus management, and simple form state patterns on mobile.
Busca en todas las páginas de la documentación
Text entry, keyboard configuration, focus management, and simple form state patterns on mobile.
Drive value from state and update with onChangeText (string, not a DOM event).
import { TextInput } from "react-native";
const [email, setEmail] = useState("");
return (
<TextInput
value={email}
onChangeText={setEmail}
autoCapitalize="none"
keyboardType="email-address"
/>
);secureTextEntry masks characters. Pair with a show/hide toggle via state.
<TextInput
value={password}
onChangeText={setPassword}
secureTextEntry={!visible}
textContentType="password"
/>Pick a keyboard that matches the data: email-address, numeric, phone-pad, url, and platform variants.
<TextInput keyboardType="number-pad" value={code} onChangeText={setCode} />Label the return key (next, done, send, go) so users know what happens next.
<TextInput returnKeyType="next" onSubmitEditing={() => passwordRef.current?.focus()} />Set multiline for notes. Control height with styles; textAlignVertical="top" helps on Android.
<TextInput
multiline
value={notes}
onChangeText={setNotes}
style={{ minHeight: 96, textAlignVertical: "top" }}
/>Disable aggressive auto-correct for emails, codes, and usernames.
<TextInput
autoCapitalize="none"
autoCorrect={false}
autoComplete="email"
value={email}
onChangeText={setEmail}
/>Hold refs to inputs and call .focus() from onSubmitEditing for multi-field forms.
const passwordRef = useRef<TextInput>(null);
// email field:
onSubmitEditing={() => passwordRef.current?.focus()}
// password:
<TextInput ref={passwordRef} />Submit when the user hits the keyboard action on the last field.
<TextInput
returnKeyType="go"
onSubmitEditing={onSubmit}
blurOnSubmit
value={query}
onChangeText={setQuery}
/>Theme placeholders and caret/selection colors for brand consistency.
<TextInput
placeholder="Search"
placeholderTextColor="#9ca3af"
selectionColor="#2563eb"
value={q}
onChangeText={setQ}
/>Disable editing without removing the field from layout - useful for review steps.
<TextInput value={accountId} editable={false} selectTextOnFocus />Cap input length and optionally show a live counter beside the field.
const max = 120;
<TextInput maxLength={max} value={bio} onChangeText={setBio} />
<Text>{bio.length}/{max}</Text>Boolean toggles use value and onValueChange on Switch.
import { Switch } from "react-native";
<Switch value={enabled} onValueChange={setEnabled} />Build a custom checkbox row when design systems do not use stock controls.
<Pressable
onPress={() => setChecked((v) => !v)}
accessibilityRole="checkbox"
accessibilityState={{ checked }}
>
<Text>{checked ? "☑" : "☐"} Agree to terms</Text>
</Pressable>Group related fields when they submit together; spread previous state on each change.
const [form, setForm] = useState({ name: "", email: "" });
const setField = (k: keyof typeof form, v: string) =>
setForm((f) => ({ ...f, [k]: v }));Dismiss the keyboard from a toolbar button or tap-outside handler.
import { Keyboard } from "react-native";
function onDone() {
Keyboard.dismiss();
onSubmit();
}Stack versions: React 19.2.3 · React Native 0.86.0 · Expo SDK 57
Revisado por Chris St. John·Última actualización: 18 jul 2026