This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).
TextInput
A Jetpack Compose TextInput component for text input.
Expo UI TextInput matches the official Jetpack Compose TextField API and supports single-line and multiline text input with various keyboard types.
Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Basic text input
import { useState } from 'react'; import { Host, TextInput } from '@expo/ui/jetpack-compose'; export default function BasicTextInputExample() { const [value, setValue] = useState('Hello, world!'); return ( <Host matchContents> <TextInput defaultValue={value} onChangeText={setValue} autocorrection={false} /> </Host> ); }
Multiline text input
import { useState } from 'react'; import { Host, TextInput } from '@expo/ui/jetpack-compose'; export default function MultilineTextInputExample() { const [value, setValue] = useState(''); return ( <Host matchContents> <TextInput defaultValue={value} onChangeText={setValue} multiline={true} numberOfLines={4} /> </Host> ); }
Numeric keyboard
import { useState } from 'react'; import { Host, TextInput } from '@expo/ui/jetpack-compose'; export default function NumericTextInputExample() { const [value, setValue] = useState(''); return ( <Host matchContents> <TextInput defaultValue={value} onChangeText={setValue} keyboardType="numeric" /> </Host> ); }
API
import { TextInput } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<TextInputProps>
Renders a TextInput component.
string • Default: noneOptions to request software keyboard to capitalize the text. Applies to languages which has upper-case and lower-case letters.
Available options:
characters: Capitalize all characters.none: Do not auto-capitalize text.sentences: Capitalize the first character of each sentence.unspecified: Capitalization behavior is not specified.words: Capitalize the first character of every word.
Acceptable values are: 'characters' | 'none' | 'sentences' | 'unspecified' | 'words'
stringInitial value that the TextInput displays when being mounted. As the TextInput is an uncontrolled component, change the key prop if you need to change the text value.
string • Default: defaultDetermines which keyboard to open. For example, 'numeric'.
Available options:
- default
- numeric
- email-address
- phone-pad
- decimal-pad
- ascii-capable
- url
- password
- password-numeric
Acceptable values are: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'ascii-capable' | 'url' | 'decimal-pad'
booleanIf true, the text input can be multiple lines. While the content will wrap, there's no keyboard button to insert a new line.
number • Default: undefined, which means unlimited lines.The number of lines to display when multiline is set to true.
If the number of lines in the view is above this number, the view scrolls.
(value: string) => voidA callback triggered when user types in text into the TextInput.
Ref<TextInputRef>Can be used for imperatively setting text on the TextInput component.
Types
| Property | Type | Description |
|---|---|---|
| setText | (newText: string) => Promise<void> | - |