as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support

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 most basic 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 minimal example:


import React from 'react';
import {SafeAreaView, StyleSheet, TextInput} from 'react-native';

const TextInputExample = () => {
  const [text, onChangeText] = React.useState('Useless Text');
  const [number, onChangeNumber] = React.useState('');

  return (
    <SafeAreaView>
      <TextInput
        style={styles.input}
        onChangeText={onChangeText}
        value={text}
      />
      <TextInput
        style={styles.input}
        onChangeText={onChangeNumber}
        value={number}
        placeholder="useless placeholder"
        keyboardType="numeric"
      />
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
});

export default TextInputExample;

Two methods exposed via the native element are .focus() and .blur() that will focus or blur the TextInput programmatically.

Note that some props are only available with multiline={true/false}. Additionally, border styles that apply to only one side of the element (e.g., borderBottomColor, borderLeftWidth, etc.) will not be applied if multiline=true. To achieve the same effect, you can wrap your TextInput in a View:


import React from 'react';
import {View, TextInput} from 'react-native';

const MultilineTextInputExample = () => {
  const [value, onChangeText] = React.useState('Useless Multiline Placeholder');

  // If you type something in the text box that is a color, the background will change to that
  // color.
  return (
    <View
      style={{
        backgroundColor: value,
        borderBottomColor: '#000000',
        borderBottomWidth: 1,
      }}>
      <TextInput
        editable
        multiline
        numberOfLines={4}
        maxLength={40}
        onChangeText={text => onChangeText(text)}
        value={value}
        style={{padding: 10}}
      />
    </View>
  );
};

export default MultilineTextInputExample;

TextInput has by default a border at the bottom of its view. This border has its padding set by the background image provided by the system, and it cannot be changed. Solutions to avoid this are to either not set height explicitly, in which case the system will take care of displaying the border in the correct position, or to not display the border by setting underlineColorKepler to transparent.


Reference

Props

View Props

Inherits View Props.


aria-labelledby

Identifies the element that labels the element it is applied to. The value of aria-labelledby should match the nativeID of the related element:

<View>
  <Text nativeID="formLabel">Label for Input Field</Text>
  <TextInput aria-label="input" aria-labelledby="formLabel" />
</View>
Type
string

autoCapitalize

Tells TextInput to automatically capitalize certain characters.

  • characters: all characters.
  • words: first letter of each word.
  • sentences: first letter of each sentence (default).
  • none: don't auto capitalize anything.
Type
enum('none', 'sentences', 'words', 'characters')

autoFocus

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

Type
bool

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
bool

auxOptions

An optional set of key:value pairs, that provide additional context to a TV-based keyboard.

For example:

To include a title in your keyboard:

auxOptions="title:Search for Videos"

To set wifi special keyboard options:

auxOptions="wifi:true"

To show validation error message using wifi keyboard:

auxOptions="title:Enter Wireless Password,wifi:true"

Type Required
string No

defaultValue

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

Type
string

editable

If false, text is not editable. The default value is true.

Type
bool

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
bool

enterKeyHint

Determines what text should be shown to the return key. Has precedence over the returnKeyType prop.

The following values work across platforms:

  • enter
  • done
  • next
  • search
  • send
Type
enum('enter', 'done', 'next', 'search', 'send')

inputMode

Works like the inputmode attribute in HTML, it determines which keyboard to open, e.g. numeric and has precedence over keyboardType.

Support the following values:

  • none
  • text
  • decimal
  • numeric
  • tel
  • search
  • email
  • url
Type
enum('decimal', 'email', 'none', 'numeric', 'search', 'tel', 'text', 'url')

keyboardType

Determines which keyboard to open, e.g.numeric.

See screenshots of all the types here.

  • default
  • number-pad
  • decimal-pad
  • numeric
  • email-address
  • phone-pad
  • url
  • pin
Type
enum('default', 'number-pad', 'decimal-pad', 'numeric', 'email-address', 'phone-pad', 'url', 'pin')

maxLength

Limits the maximum number of characters that can be entered. Use this instead of implementing the logic in JS to avoid flicker.

Type
number

numberOfLines

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

Type
number

onBlur

Callback that is called when the text input is blurred.

Note: If you are attempting to access the text value from nativeEvent keep in mind that the resulting value you get can be undefined which can cause unintended errors. If you are trying to find the last value of TextInput, you can use the onEndEditing event, which is fired upon completion of editing.

Type
function

onChange

Callback that is called when the text input's text changes.

Type
({nativeEvent: {eventCount, target, text}}) => void

onContentSizeChange

Callback that is called when the text input's content size changes.

Only called for multiline text inputs.

Type
({nativeEvent: {contentSize: {width, height} }}) => void

onEndEditing

Callback that is called when text input ends.

Type
function

onFocus

Callback that is called when the text input is focused.

Type
md ({nativeEvent: [LayoutEvent](layoutevent)}) => void

onKeyPress

Callback that is called when a key is pressed. This will be called with object where keyValue is 'Enter' or 'Backspace' for respective keys and the typed-in character otherwise including ' ' for space. Fires before onChange callbacks.

Type
({nativeEvent: {key: keyValue} }) => void

onLayout

Invoked on mount and on layout changes.

Type
({nativeEvent: [LayoutEvent](layoutevent)}) => void

onSubmitEditing

Callback that is called when the text input's submit button is pressed.

Type
({nativeEvent: {text, eventCount, target, submitAction}}) => void

Note the following differences in the React Native for Kepler implementation:

  • The onSubmitEditing event also contains submitAction. The value of submitAction is the action string(similar to returnKeyType) or any numeric value which is set by the user in auxOptions prop.
  • onSubmitEditing only works when returnKeyType is also set. To work around this, set returnKeyType.
  • onSubmitEditing will sometimes not fire on the first mount if autofocus is true. To work around this, set autofocus to false.

placeholder

The string that will be rendered before text input has been entered.

Type
string

placeholderTextColor

The text color of the placeholder string.

Type
color

readOnly

If true, text is not editable. The default value is false.

Type
bool

returnKeyType

Determines how the return key should look.

The following values work across platforms:

  • done
  • go
  • next
  • search
  • send
Type
enum('done', 'go', 'next', 'search', 'send')

rows

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

Type
number

secureTextEntry

If true, the text input obscures the text entered so that sensitive text like passwords stay secure. The default value is false. Does not work with multiline={true}.

Type
bool

selectionColor

The highlight and cursor color of the text input.

Type
color

selection

The start and end of the text input's selection. Set start and end to the same value to position the cursor.

Type
object: {start: number,end: number}

selectTextOnFocus

If true, all text will automatically be selected on focus.

Type
bool

showSoftInputOnFocus

When false, it will prevent the soft keyboard from showing when the field is focused. The default value is true.

Type
bool

Note: On Kepler, when autoFocus is set to true, showSoftInputOnFocus will not prevent soft keyboard from opening on first mount, regardless of its value. As a workaround, remove autoFocus or set autoFocus to false.


style

Note that not all Text styles are supported, an incomplete list of what is not supported includes:

  • borderLeftWidth
  • borderTopWidth
  • borderRightWidth
  • borderBottomWidth
  • borderTopLeftRadius
  • borderTopRightRadius
  • borderBottomRightRadius
  • borderBottomLeftRadius

see Issue#7070 for more detail.

Styles

Type
Text

textAlign

Align the input text to the left, center, or right sides of the input field.

Possible values for textAlign are:

  • left
  • center
  • right
Type
enum('left', 'center', 'right')

underlineColorKepler

The color of the TextInput underline.

Type
color

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 setting the same value, either set editable={false}, or set/update maxLength to prevent unwanted edits without flicker.

Type
string

Methods

isFocused()

isFocused(): boolean;

Returns true if the input is currently focused; false otherwise.

clear()

clear();

Removes all text from the TextInput.


Last updated: Sep 30, 2025