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:
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 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 ofaria-labelledby should match the nativeID of the related element:
autoCapitalize
TellsTextInput 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.
autoFocus
Iftrue, focuses the input on componentDidMount or useEffect. The default value is false.
blurOnSubmit
Iftrue, 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.
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"
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.editable
Iffalse, text is not editable. The default value is true.
enablesReturnKeyAutomatically
Iftrue, 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 thereturnKeyType prop.
The following values work across platforms:
enterdonenextsearchsend
inputMode
Works like theinputmode attribute in HTML, it determines which keyboard to open, e.g. numeric and has precedence over keyboardType.
Support the following values:
nonetextdecimalnumerictelsearchemailurl
keyboardType
Determines which keyboard to open, e.g.numeric.
See screenshots of all the types here.
defaultnumber-paddecimal-padnumericemail-addressphone-padurlpin
maxLength
Limits the maximum number of characters that can be entered. Use this instead of implementing the logic in JS to avoid flicker.numberOfLines
Sets the number of lines for aTextInput. 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. Note: If you are attempting to access thetext 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.
onChange
Callback that is called when the text input’s text changes.onContentSizeChange
Callback that is called when the text input’s content size changes. Only called for multiline text inputs.onEndEditing
Callback that is called when text input ends.onFocus
Callback that is called when the text input is focused.onKeyPress
Callback that is called when a key is pressed. This will be called with object wherekeyValue is 'Enter' or 'Backspace' for respective keys and the typed-in character otherwise including ' ' for space. Fires before onChange callbacks.
onLayout
Invoked on mount and on layout changes.onSubmitEditing
Callback that is called when the text input’s submit button is pressed.- The
onSubmitEditingevent also containssubmitAction. The value of submitAction is the action string(similar to returnKeyType) or any numeric value which is set by the user inauxOptionsprop. onSubmitEditingonly works whenreturnKeyTypeis also set. To work around this, setreturnKeyType.onSubmitEditingwill sometimes not fire on the first mount ifautofocusistrue. To work around this, setautofocustofalse.
placeholder
The string that will be rendered before text input has been entered.placeholderTextColor
The text color of the placeholder string.readOnly
Iftrue, text is not editable. The default value is false.
returnKeyType
Determines how the return key should look. The following values work across platforms:donegonextsearchsend
rows
Sets the number of lines for aTextInput. Use it with multiline set to true to be able to fill the lines.
secureTextEntry
Iftrue, 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}.
selectionColor
The highlight and cursor color of the text input.selection
The start and end of the text input’s selection. Setstart and end to the same value to position the cursor.
selectTextOnFocus
Iftrue, all text will automatically be selected on focus.
showSoftInputOnFocus
Whenfalse, it will prevent the soft keyboard from showing when the field is focused. The default value is true.
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:borderLeftWidthborderTopWidthborderRightWidthborderBottomWidthborderTopLeftRadiusborderTopRightRadiusborderBottomRightRadiusborderBottomLeftRadius
textAlign
Align the input text to the left, center, or right sides of the input field. Possible values fortextAlign are:
leftcenterright
underlineColorKepler
The color of theTextInput 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.
Methods
isFocused()
true if the input is currently focused; false otherwise.
clear()
TextInput.
