TextInput

A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, such as auto-correction, auto-capitalization, placeholder text, and different keyboard types, such as a numeric keypad.

The simplest use case is to plop down a TextInput and subscribe to the onChangeText events to read the user input. There are also other events, such as onSubmitEditing and onFocus that can be subscribed to. A simple example:

autoFocus

If true, focuses the input on componentDidMount. The default value is false.

Type

Required

bool

No

defaultValue

Provides an initial value that will change when the user starts typing. Useful for simple use-cases where you don't want to deal with listening to events and updating the value prop to keep the controlled state in sync.

selectionColor

style

value

The value to show for the text input. TextInput is a controlled component, which means the native value will be forced to match this value prop if provided. For most uses this works great, but in some cases this may cause flickering - one common cause is preventing edits by keeping value the same. In addition to simply setting the same value, either set editable={false}, or set/update maxLength to prevent unwanted edits without flicker.

Type

Required

string

No

numberOfLines

Sets the number of lines for a TextInput. Use it with multiline set to true to be able to fill the lines.

Type

Required

Platform

number

No

Android

underlineColorAndroid

The color of the textInput underline.

Type

Required

Platform

string

No

Android

blurOnSubmit

If true, the text field will blur when submitted. The default value is true for single-line fields and false for multiline fields. Note that for multiline fields, setting blurOnSubmit to true means that pressing return will blur the field and trigger the onSubmitEditing event instead of inserting a newline into the field.

Type

Required

Platform

bool

No

iOS

clearButtonMode

When the clear button should appear on the right side of the text view

Type

Required

Platform

enum('never', 'while-editing', 'unless-editing', 'always')

No

iOS

clearTextOnFocus

If true, clears the text field automatically when editing begins

Type

Required

Platform

bool

No

iOS

enablesReturnKeyAutomatically

If true, the keyboard disables the return key when there is no text and automatically enables it when there is text. The default value is false.

Type

Required

Platform

bool

No

iOS

keyboardAppearance

Determines the color of the keyboard.

Type

Required

Platform

enum('default', 'light', 'dark')

No

iOS

onKeyPress

Callback that is called when a key is pressed. Pressed key value is passed as an argument to the callback handler. Fires before onChange callbacks.