Skip to content

TextField

A text field component powered by Jetpack Compose’s OutlinedTextField with Material 3 styling.

import { TextField } from '@mgcrea/react-native-jetpack-compose';
const [name, setName] = useState('');
<TextField
label="Name"
value={name}
onChange={setName}
placeholder="Enter your name"
/>
PropTypeDefaultDescription
valuestring''Current text value
labelstring-Floating label text
placeholderstring-Placeholder text when empty
disabledbooleanfalseDisable the field
editablebooleantrueWhether text can be edited
multilinebooleanfalseEnable multiline input
maxLengthnumber-Maximum character count
secureTextEntrybooleanfalseHide text for passwords
errorbooleanfalseShow error state styling
helperTextstring-Helper or error text below field
keyboardTypeKeyboardType'default'Keyboard type to show
returnKeyTypeReturnKeyType'done'IME action button type
autoCapitalizeAutoCapitalize'sentences'Auto-capitalization behavior
autoCorrectbooleantrueEnable auto-correct
leadingIconstring-Leading Material Icon name
trailingIconstring-Trailing Material Icon name
showCounterbooleantrueShow character counter with maxLength
styleViewStyle-Container style
EventTypeDescription
onChange(text: string) => voidCalled when text changes
onFocus() => voidCalled when field gains focus
onBlur() => voidCalled when field loses focus
onSubmitEditing() => voidCalled when IME action pressed
onTrailingIconPress() => voidCalled when trailing icon tapped
<TextField keyboardType="default" /> // Standard keyboard
<TextField keyboardType="email" /> // Email keyboard with @
<TextField keyboardType="number" /> // Numeric keyboard
<TextField keyboardType="phone" /> // Phone dial pad
<TextField keyboardType="decimal" /> // Numbers with decimal
<TextField keyboardType="url" /> // URL keyboard with /
<TextField returnKeyType="done" /> // Done button
<TextField returnKeyType="go" /> // Go button
<TextField returnKeyType="next" /> // Next button
<TextField returnKeyType="search" /> // Search button
<TextField returnKeyType="send" /> // Send button
const [email, setEmail] = useState('');
<TextField
label="Email"
value={email}
onChange={setEmail}
placeholder="you@example.com"
keyboardType="email"
autoCapitalize="none"
autoCorrect={false}
leadingIcon="Email"
/>
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
<TextField
label="Password"
value={password}
onChange={setPassword}
secureTextEntry={!showPassword}
trailingIcon={showPassword ? "VisibilityOff" : "Visibility"}
onTrailingIconPress={() => setShowPassword(!showPassword)}
/>
const [search, setSearch] = useState('');
<TextField
label="Search"
value={search}
onChange={setSearch}
placeholder="Search..."
leadingIcon="Search"
trailingIcon={search ? "Clear" : undefined}
onTrailingIconPress={() => setSearch('')}
returnKeyType="search"
onSubmitEditing={() => performSearch(search)}
/>
const [email, setEmail] = useState('');
const [error, setError] = useState(false);
const validateEmail = (text: string) => {
setEmail(text);
setError(text.length > 0 && !text.includes('@'));
};
<TextField
label="Email"
value={email}
onChange={validateEmail}
error={error}
helperText={error ? 'Please enter a valid email address' : 'We will never share your email'}
keyboardType="email"
/>
const [bio, setBio] = useState('');
<TextField
label="Bio"
value={bio}
onChange={setBio}
placeholder="Tell us about yourself"
multiline
maxLength={200}
showCounter
/>
const [message, setMessage] = useState('');
<TextField
label="Message"
value={message}
onChange={setMessage}
placeholder="Enter your message..."
multiline
style={{ minHeight: 120 }}
/>
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
<TextField
label="First Name"
value={firstName}
onChange={setFirstName}
returnKeyType="next"
onSubmitEditing={() => {
// Focus next field (implement with refs)
}}
/>
<TextField
label="Last Name"
value={lastName}
onChange={setLastName}
returnKeyType="done"
onSubmitEditing={() => {
// Submit form
}}
/>

The leadingIcon and trailingIcon props accept Material Icon names. Common icons include:

  • Search, Clear, Close
  • Email, Phone, Person
  • Visibility, VisibilityOff
  • Lock, Key
  • Edit, Delete
  • Check, Error, Warning

See the Material Icons catalog for the full list.