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:
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:
TextInput has a border at the bottom of its view by default. 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 underlineColorAndroid to transparent.
Note that on Android performing text selection in an input can change the app's activity windowSoftInputMode param to adjustResize. This may cause issues with components that have position: 'absolute' while the keyboard is active. To avoid this behavior either specify windowSoftInputMode in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html ) or control this param programmatically with native code.
Inherits View Props.
allowFontScalingโSpecifies whether fonts should scale to respect Text Size accessibility settings. The default is true.
autoCapitalizeโTells TextInput to automatically capitalize certain characters. This property is not supported by some keyboard types such as name-phone-pad.
characters: all characters.words: first letter of each word.sentences: first letter of each sentence (default).none: don't auto capitalize anything.autoCompleteโSpecifies autocomplete hints for the system, so it can provide autofill. On Android, the system will always attempt to offer autofill by using heuristics to identify the type of content. To disable autocomplete, set autoComplete to off.
The following values work across platforms:
additional-nameaddress-line1address-line2birthdate-day (iOS 17+)birthdate-full (iOS 17+)birthdate-month (iOS 17+)birthdate-year (iOS 17+)cc-csc (iOS 17+)cc-exp (iOS 17+)cc-exp-day (iOS 17+)cc-exp-month (iOS 17+)cc-exp-year (iOS 17+)cc-numbercountrycurrent-passwordemailfamily-namegiven-namehonorific-prefixhonorific-suffixnamenew-passwordoffone-time-codepostal-codestreet-addresstelusernameThe following values work on iOS only:
cc-family-name (iOS 17+)cc-given-name (iOS 17+)cc-middle-name (iOS 17+)cc-name (iOS 17+)cc-type (iOS 17+)nicknameorganizationorganization-titleurlThe following values work on Android only:
gendername-familyname-givenname-middlename-middle-initialname-prefixname-suffixpasswordpassword-newpostal-addresspostal-address-countrypostal-address-extendedpostal-address-extended-postal-codepostal-address-localitypostal-address-regionsms-otptel-country-codetel-devicetel-nationalusername-newautoCorrectโIf false, disables auto-correct. The default value is true.
autoFocusโIf true, focuses the input. The default value is false.
blurOnSubmitโ:::warning Deprecated
Note that submitBehavior now takes the place of blurOnSubmit and will override any behavior defined by blurOnSubmit. See submitBehavior.
:::
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.
caretHiddenโIf true, caret is hidden. The default value is false.
clearButtonMode When the clear button should appear on the right side of the text view. This property is supported only for single-line TextInput component. The default value is never.
clearTextOnFocus If true, clears the text field automatically when editing begins.
contextMenuHiddenโIf true, context menu is hidden. The default value is false.
dataDetectorTypes Determines the types of data converted to clickable URLs in the text input. Only valid if multiline={true} and editable={false}. By default no data types are detected.
You can provide one type or an array of many types.
Possible values for dataDetectorTypes are:
'phoneNumber''link''address''calendarEvent''none''all'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.
TypedisableKeyboardShortcuts If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled.
falsecursorColor When provided it will set the color of the cursor (or "caret") in the component. Unlike the behavior of selectionColor the cursor color will be set independently from the color of the text selection box.
disableFullscreenUI When false, if there is a small amount of space available around a text input (e.g. landscape orientation on a phone), the OS may choose to have the user edit the text inside of a full screen text input mode. When true, this feature is disabled and users will always edit the text directly inside of the text input. Defaults to false.
editableโIf false, text is not editable. The default value is true.
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.
enterKeyHintโDetermines what text should be shown to the return key. Has precedence over the returnKeyType prop.
The following values work across platforms:
donenextsearchsendgoAndroid Only
The following values work on Android only:
previousiOS Only
The following values work on iOS only:
enterimportantForAutofill Tells the operating system whether the individual fields in your app should be included in a view structure for autofill purposes on Android API Level 26+. Possible values are auto, no, noExcludeDescendants, yes, and yesExcludeDescendants. The default value is auto.
auto: Let the Android System use its heuristics to determine if the view is important for autofill.no: This view isn't important for autofill.noExcludeDescendants: This view and its children aren't important for autofill.yes: This view is important for autofill.yesExcludeDescendants: This view is important for autofill, but its children aren't important for autofill.inlineImageLeft If defined, the provided image resource will be rendered on the left. The image resource must be inside /android/app/src/main/res/drawable and referenced like
<TextInput
inlineImageLeft='search_icon'
/>
inlineImagePadding Padding between the inline image, if any, and the text input itself.
TypeinputAccessoryViewID An optional identifier which links a custom InputAccessoryView to this text input. The InputAccessoryView is rendered above the keyboard when this text input is focused.
TypeinputAccessoryViewButtonLabel An optional label that overrides the default InputAccessoryView button label.
By default, the default button label is not localized. Use this property to provide a localized version.
TypeinputModeโ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:
nonetextdecimalnumerictelsearchemailurlkeyboardAppearance Determines the color of the keyboard.
TypekeyboardTypeโDetermines which keyboard to open, e.g.numeric.
See screenshots of all the types here.
The following values work across platforms:
defaultnumber-paddecimal-padnumericemail-addressphone-padurliOS Only
The following values work on iOS only:
ascii-capablenumbers-and-punctuationname-phone-padtwitterweb-searchAndroid Only
The following values work on Android only:
visible-passwordlineBreakStrategyIOS Set line break strategy on iOS 14+. Possible values are none, standard, hangul-word and push-out.
'none', 'standard', 'hangul-word', 'push-out')'none'lineBreakModeIOS Set line break mode on iOS. Possible values are wordWrapping, char, clip, head, middle and tail.
'wordWrapping', 'char', 'clip', 'head', 'middle', 'tail')'wordWrapping'maxFontSizeMultiplierโSpecifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
null/undefined (default): inherit from the parent node or the global default (0)0: no max, ignore parent/global default>= 1: sets the maxFontSizeMultiplier of this node to this valuemaxLengthโLimits the maximum number of characters that can be entered. Use this instead of implementing the logic in JS to avoid flicker.
TypemultilineโIf true, the text input can be multiple lines. The default value is false.
It is important to note that this aligns the text to the top on iOS, and centers it on Android. Use with textAlignVertical set to top for the same behavior in both platforms.
numberOfLinesโnumberOfLines on iOS is only available on the New Architecture
Sets the maximum number of lines for a TextInput. Use it with multiline set to true to be able to fill the lines.
onBlurโCallback that is called when the text input is blurred.
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.
({nativeEvent: TargetEvent}) => voidonChangeโCallback that is called when the text input's text changes.
Type{nativeEvent: {eventCount, target, text}}) => voidonChangeTextโCallback that is called when the text input's text changes. Changed text is passed as a single string argument to the callback handler.
TypeonContentSizeChangeโCallback that is called when the text input's content size changes.
Only called for multiline text inputs.
Type{nativeEvent: {contentSize: {width, height} }}) => voidonEndEditingโCallback that is called when text input ends.
TypeonPressInโCallback that is called when a touch is engaged.
Type({nativeEvent: PressEvent}) => voidonPressOutโCallback that is called when a touch is released.
Type({nativeEvent: PressEvent}) => voidonFocusโCallback that is called when the text input is focused.
Type({nativeEvent: TargetEvent}) => voidonKeyPressโ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. Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.
{nativeEvent: {key: keyValue} }) => voidonLayoutโInvoked on mount and on layout changes.
Type({nativeEvent: LayoutEvent}) => voidonScrollโInvoked on content scroll. May also contain other properties from ScrollEvent but on Android contentSize is not provided for performance reasons.
{nativeEvent: {contentOffset: {x, y} }}) => voidonSelectionChangeโCallback that is called when the text input selection is changed.
Type{nativeEvent: {selection: {start, end} }}) => voidonSubmitEditingโCallback that is called when the text input's submit button is pressed.
Type{nativeEvent: {text, eventCount, target}}) => voidNote that on iOS this method isn't called when using keyboardType="phone-pad".
placeholderโThe string that will be rendered before text input has been entered.
TypeplaceholderTextColorโThe text color of the placeholder string.
TypereadOnlyโIf true, text is not editable. The default value is false.
returnKeyLabel Sets the return key to the label. Use it instead of returnKeyType.
returnKeyTypeโDetermines how the return key should look. On Android you can also use returnKeyLabel.
Cross platform
The following values work across platforms:
donegonextsearchsendAndroid Only
The following values work on Android only:
nonepreviousiOS Only
The following values work on iOS only:
defaultemergency-callgooglejoinrouteyahoorejectResponderTermination If true, allows TextInput to pass touch events to the parent component. This allows components such as SwipeableListView to be swipeable from the TextInput on iOS, as is the case on Android by default. If false, TextInput always asks to handle the input (except when disabled). The default value is true.
rows Sets the number of lines for a TextInput. Use it with multiline set to true to be able to fill the lines.
scrollEnabled If false, scrolling of the text view will be disabled. The default value is true. Only works with multiline={true}.
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}.
selectionโThe start and end of the text input's selection. Set start and end to the same value to position the cursor.
Type{start: number,end: number}selectionColorโThe highlight, selection handle and cursor color of the text input.
TypeselectionHandleColor Sets the color of the selection handle. Unlike selectionColor, it allows the selection handle color to be customized independently of the selection's color.
selectTextOnFocusโIf true, all text will automatically be selected on focus.
showSoftInputOnFocusโWhen false, it will prevent the soft keyboard from showing when the field is focused. The default value is true.
smartInsertDelete If false, the iOS system will not insert an extra space after a paste operation neither delete one or two spaces after a cut or delete operation.
truespellCheck If false, disables spell-check style (i.e. red underlines). The default value is inherited from autoCorrect.
submitBehaviorโWhen the return key is pressed,
For single line inputs:
'newline' defaults to 'blurAndSubmit'undefined defaults to 'blurAndSubmit'For multiline inputs:
'newline' adds a newlineundefined defaults to 'newline'For both single line and multiline inputs:
'submit' will only send a submit event and not blur the input'blurAndSubmit' will both blur the input and send a submit eventtextAlignโAlign the input text to the left, center, or right sides of the input field.
Possible values for textAlign are:
leftcenterrighttextContentType Give the keyboard and the system information about the expected semantic meaning for the content that users enter.
autoComplete, provides the same functionality and is available for all platforms. You can use Platform.select for differing platform behaviors.
Avoid using both textContentType and autoComplete. For backwards compatibility, textContentType takes precedence when both properties are set.
You can set textContentType to username or password to enable autofill of login details from the device keychain.
newPassword can be used to indicate a new password input the user may want to save in the keychain, and oneTimeCode can be used to indicate that a field can be autofilled by a code arriving in an SMS.
To disable autofill, set textContentType to none.
Possible values for textContentType are:
noneaddressCityaddressCityAndStateaddressStatebirthdate (iOS 17+)birthdateDay (iOS 17+)birthdateMonth (iOS 17+)birthdateYear (iOS 17+)countryNamecreditCardExpiration (iOS 17+)creditCardExpirationMonth (iOS 17+)creditCardExpirationYear (iOS 17+)creditCardFamilyName (iOS 17+)creditCardGivenName (iOS 17+)creditCardMiddleName (iOS 17+)creditCardName (iOS 17+)creditCardNumbercreditCardSecurityCode (iOS 17+)creditCardType (iOS 17+)emailAddressfamilyNamefullStreetAddressgivenNamejobTitlelocationmiddleNamenamenamePrefixnameSuffixnewPasswordnicknameoneTimeCodeorganizationNamepasswordpostalCodestreetAddressLine1streetAddressLine2sublocalitytelephoneNumberURLusernamepasswordRules When using textContentType as newPassword on iOS we can let the OS know the minimum requirements of the password so that it can generate one that will satisfy them. In order to create a valid string for PasswordRules take a look to the Apple Docs.
If passwords generation dialog doesn't appear please make sure that:
styleโNote that not all Text styles are supported, an incomplete list of what is not supported includes:
borderLeftWidthborderTopWidthborderRightWidthborderBottomWidthborderTopLeftRadiusborderTopRightRadiusborderBottomRightRadiusborderBottomLeftRadiustextBreakStrategy Set text break strategy on Android API Level 23+, possible values are simple, highQuality, balanced The default value is highQuality.
underlineColorAndroid The color of the TextInput underline.
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.
.focus()โfocus();
Makes the native input request focus.
.blur()โblur();
Makes the native input lose focus.
clear()โclear();
Removes all text from the TextInput.
isFocused()โisFocused(): boolean;
Returns true if the input is currently focused; false otherwise.
onKeyPreIme.secureTextEntry when keyboardType="email-address" or keyboardType="phone-pad".