Skip to main content

TextInput

A text field. It renders an <input type="text">, or a <textarea> with multiline.

import { useState } from 'react'
import { TextInput } from 'react-native'

export function EmailField() {
const [email, setEmail] = useState('')
return (
<TextInput
value={email}
onChangeText={setEmail}
placeholder="you@example.com"
keyboardType="email-address"
autoComplete="email"
autoCapitalize="none"
/>
)
}

The field has no border, no padding, and no background, as on iOS. Its text direction follows the text you type.

Multiline​

With multiline, the field grows with its text. numberOfLines is the minimum number of rows. A height in the style fixes the size.

Enter​

FieldEnter does
Single-lineCalls onSubmitEditing, then blurs the field. The browser's default stays, so a field inside a <form> submits the form.
MultilineAdds a new line. With submitBehavior set to submit or blurAndSubmit, it calls onSubmitEditing instead. Shift+Enter always adds a new line.

submitBehavior and blurOnSubmit work as on native.

Props​

PropOn the web
value, defaultValue, onChangeText, onChangeAs on native. A value with no handler stays fixed, with no React warning.
placeholder, maxLength, autoFocusAs on native.
secureTextEntrytype="password".
keyboardTypeBecomes inputmode, so a phone shows the matching keyboard. The input type stays text, so the browser adds no validation.
returnKeyTypeBecomes enterkeyhint, the label of the Enter key on a phone keyboard.
inputMode, enterKeyHintWin over keyboardType and returnKeyType when you set them.
showSoftInputOnFocusfalse is inputmode="none", so a phone shows no keyboard.
autoComplete, textContentTypeThe HTML autocomplete tokens. The React Native-only values map, for example name-given to given-name and sms-otp to one-time-code. textContentType applies when autoComplete isn't set.
autoCapitalize, autoCorrect, spellCheckThe matching HTML attributes.
editable, readOnlyeditable={false} is readonly, not disabled, so the field stays focusable and its text selectable.
placeholderTextColorThe color of the placeholder.
selectionColor, cursorColor, caretHiddenThe background of selected text and the color of the caret. caretHidden makes the caret transparent.
selection, onSelectionChangeAs on native. onSelectionChange also fires when the caret moves.
selectTextOnFocus, clearTextOnFocus, contextMenuHiddenAs on native.
textAlignAs on native.
onFocus, onBlur, onEndEditing, onKeyPress, onSubmitEditing, onContentSizeChangenativeEvent is the DOM event, with text, eventCount, key, selection, or contentSize added. nativeEvent.target is the element. onEndEditing fires on blur.
onLayout, accessibility props, nativeID, testIDAs on View.

These native-only props are accepted and ignored: clearButtonMode, keyboardAppearance, textAlignVertical, underlineColorAndroid, passwordRules, dataDetectorTypes, and the other iOS and Android props.

Ref​

The ref is the <input> or <textarea> element, with clear(), isFocused(), getNativeRef(), and setNativeProps({ text, style }) added. It also has the measure methods of View.

TextInput.State has currentlyFocusedInput(), focusTextInput(element), and blurTextInput(element).