Code Reference

TextInput

React Native · Reference cheat sheet

TextInput

React Native · Reference cheat sheet


📋 Overview

TextInput is the core text entry component. Controlled via value + onChangeText. Tune keyboard (keyboardType, autoCapitalize, secureTextEntry), and handle focus with refs. Pair with labels for accessibility.

🔧 Core concepts

PropRole
value / onChangeTextControlled text
defaultValueUncontrolled start
placeholderHint
secureTextEntryPassword
keyboardTypeemail/number/…
multiline / numberOfLinesText area
returnKeyType / onSubmitEditingKeyboard action
editableDisable

Use autoComplete / textContentType for password managers.

💡 Examples

import { useRef, useState } from "react";
import { TextInput, Pressable, Text, StyleSheet } from "react-native";

export function LoginFields() {
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const passwordRef = useRef<TextInput>(null);

  return (
    <>
      <Text nativeID="emailLabel">Email</Text>
      <TextInput
        style={styles.input}
        value={email}
        onChangeText={setEmail}
        keyboardType="email-address"
        autoCapitalize="none"
        autoComplete="email"
        accessibilityLabelledBy="emailLabel"
        returnKeyType="next"
        onSubmitEditing={() => passwordRef.current?.focus()}
      />
      <TextInput
        ref={passwordRef}
        style={styles.input}
        value={password}
        onChangeText={setPassword}
        secureTextEntry
        autoComplete="password"
        accessibilityLabel="Password"
      />
    </>
  );
}

const styles = StyleSheet.create({
  input: {
    borderWidth: 1,
    borderColor: "#ccc",
    borderRadius: 8,
    padding: 12,
    marginBottom: 12,
  },
});

⚠️ Pitfalls

  • Controlled input without updating value → can’t type.
  • Wrapping in a scroll view without keyboardShouldPersistTaps.
  • Tiny touch targets / missing labels.
  • Android underlineColorAndroid surprises—set transparent if needed.

On this page