React Native for Web is a comprehensive compatibility library that enables React Native components and APIs to run seamlessly on web browsers using React DOM.
—
Text display and input components with advanced typography, accessibility, and internationalization support. These components provide comprehensive text handling capabilities for React Native Web applications.
A component for displaying text with advanced typography features, accessibility support, and user interaction capabilities.
const Text: React.ComponentType<TextProps>;Props:
style - Text styling including typography, colors, and layout propertiesnumberOfLines - Maximum number of lines to display (1 = single line with ellipsis, >1 = multi-line with ellipsis)onPress - Callback when text is pressed (makes text interactive)selectable - Whether text can be selected by user (true/false)accessible - Whether component is accessible to screen readersaccessibilityLabel - Screen reader labelaccessibilityRole - Semantic role: 'button' | 'header' | 'heading' | 'label' | 'link' | 'listitem' | 'none' | 'text'href - Makes text render as a link (anchor element)hrefAttrs - Link attributes: {download?: boolean, rel?: string, target?: string}dir - Text direction: 'auto' | 'ltr' | 'rtl'lang - Language code for proper text rendering and accessibilitychildren - Text content (string or nested Text components)Styling Props:
color - Text colorfontFamily - Font family namefontSize - Font size (number or string with units)fontWeight - Font weight: 'normal' | 'bold' | '100' to '900'fontStyle - Font style: 'normal' | 'italic'letterSpacing - Letter spacinglineHeight - Line heighttextAlign - Text alignment: 'left' | 'right' | 'center' | 'justify' | 'start' | 'end'textDecorationLine - Text decoration: 'none' | 'underline' | 'line-through' | 'underline line-through'textTransform - Text transform: 'none' | 'capitalize' | 'uppercase' | 'lowercase'userSelect - Text selection: 'none' | 'text' | 'auto'Usage:
import { Text } from "react-native-web";
// Basic text
<Text style={{ fontSize: 16, color: '#333' }}>
Hello World
</Text>
// Interactive text
<Text
onPress={() => alert('Pressed!')}
style={{ color: 'blue', textDecorationLine: 'underline' }}
>
Click me
</Text>
// Single line with ellipsis
<Text numberOfLines={1} style={{ width: 200 }}>
This is a very long text that will be truncated with ellipsis
</Text>
// Multi-line with ellipsis
<Text numberOfLines={3} style={{ width: 200 }}>
This is a longer text that will be displayed on multiple lines
but truncated after 3 lines with ellipsis
</Text>
// Link text
<Text
href="https://example.com"
hrefAttrs={{ target: '_blank', rel: 'noopener' }}
style={{ color: 'blue' }}
>
External Link
</Text>
// Nested text with different styles
<Text style={{ fontSize: 16 }}>
Welcome to{' '}
<Text style={{ fontWeight: 'bold', color: 'blue' }}>
React Native Web
</Text>
</Text>
// Accessible text
<Text
accessibilityRole="heading"
accessibilityLabel="Page title"
style={{ fontSize: 24, fontWeight: 'bold' }}
>
Dashboard
</Text>A text input component for collecting user input with comprehensive keyboard handling, validation, and accessibility features.
const TextInput: React.ComponentType<TextInputProps>;Props:
value - Current text value (controlled component)defaultValue - Initial text value (uncontrolled component)placeholder - Placeholder text when input is emptyplaceholderTextColor - Color of placeholder textmultiline - Enable multi-line input (renders as textarea)numberOfLines - Number of lines for multiline input (deprecated, use rows)rows - Number of rows for textareamaxLength - Maximum number of characters allowededitable - Whether input is editable (deprecated, use readOnly)readOnly - Whether input is read-onlysecureTextEntry - Hide text for password inputautoFocus - Automatically focus input when mountedclearTextOnFocus - Clear text when input receives focusselectTextOnFocus - Select all text when input receives focusblurOnSubmit - Blur input when submit is pressed (default: true for single-line, false for multi-line)Keyboard and Input Props:
keyboardType - Virtual keyboard type (deprecated, use inputMode)inputMode - Input mode: 'text' | 'numeric' | 'decimal' | 'email' | 'tel' | 'url' | 'search' | 'none'enterKeyHint - Enter key appearance: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'returnKeyType - Return key type (deprecated, use enterKeyHint)autoCapitalize - Auto-capitalization: 'none' | 'sentences' | 'words' | 'characters'autoComplete - Browser autocomplete behaviorautoCorrect - Enable auto-correctionspellCheck - Enable spell checkingcaretHidden - Hide text cursorSelection and Events:
selection - Text selection: {start: number, end?: number}selectionColor - Color of text selectiononChangeText - Text change callback: (text: string) => voidonChange - Raw change event callbackonFocus - Focus event callbackonBlur - Blur event callbackonSubmitEditing - Submit/enter key callbackonKeyPress - Key press callbackonSelectionChange - Selection change callbackonContentSizeChange - Content size change callback (multiline only)Methods:
focus() - Focus the inputblur() - Blur the inputclear() - Clear the input textisFocused() - Check if input is focusedUsage:
import { TextInput, View } from "react-native-web";
function LoginForm() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const passwordRef = useRef();
return (
<View style={{ padding: 20 }}>
<TextInput
value={email}
onChangeText={setEmail}
placeholder="Enter email"
inputMode="email"
autoCapitalize="none"
autoComplete="email"
enterKeyHint="next"
onSubmitEditing={() => passwordRef.current?.focus()}
style={{
borderWidth: 1,
borderColor: '#ccc',
padding: 10,
borderRadius: 5,
marginBottom: 10
}}
/>
<TextInput
ref={passwordRef}
value={password}
onChangeText={setPassword}
placeholder="Enter password"
secureTextEntry={true}
autoComplete="current-password"
enterKeyHint="done"
onSubmitEditing={() => console.log('Login')}
style={{
borderWidth: 1,
borderColor: '#ccc',
padding: 10,
borderRadius: 5
}}
/>
</View>
);
}
// Multi-line input
<TextInput
multiline={true}
rows={4}
placeholder="Enter your message..."
onChangeText={(text) => console.log(text)}
style={{
borderWidth: 1,
borderColor: '#ccc',
padding: 10,
textAlignVertical: 'top'
}}
/>
// Controlled selection
function TextEditor() {
const [text, setText] = useState('Hello World');
const [selection, setSelection] = useState({start: 0, end: 5});
return (
<TextInput
value={text}
onChangeText={setText}
selection={selection}
onSelectionChange={(event) => {
setSelection(event.nativeEvent.selection);
}}
style={{ borderWidth: 1, padding: 10 }}
/>
);
}
// Number input
<TextInput
inputMode="numeric"
placeholder="Enter amount"
keyboardType="number-pad" // fallback for older browsers
onChangeText={(text) => {
// Only allow numbers
const numericText = text.replace(/[^0-9]/g, '');
setAmount(numericText);
}}
/>
// Search input
<TextInput
inputMode="search"
placeholder="Search..."
enterKeyHint="search"
onSubmitEditing={(event) => {
performSearch(event.nativeEvent.text);
}}
style={{
borderRadius: 20,
backgroundColor: '#f0f0f0',
padding: 10
}}
/>interface TextStyle extends ViewStyle {
color?: ColorValue;
fontFamily?: string;
fontSize?: number | string;
fontWeight?: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
fontStyle?: 'normal' | 'italic';
letterSpacing?: number | string;
lineHeight?: number | string;
textAlign?: 'left' | 'right' | 'center' | 'justify' | 'start' | 'end';
textDecorationLine?: 'none' | 'underline' | 'line-through' | 'underline line-through';
textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed';
textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase';
userSelect?: 'none' | 'text' | 'auto';
// ... other text style properties
}
interface TextProps extends ViewProps {
style?: TextStyle;
numberOfLines?: number;
onPress?: (event: PressEvent) => void;
selectable?: boolean;
accessibilityRole?: 'button' | 'header' | 'heading' | 'label' | 'link' | 'listitem' | 'none' | 'text';
dir?: 'auto' | 'ltr' | 'rtl';
children?: React.ReactNode;
}
interface TextInputStyle extends TextStyle {
caretColor?: ColorValue;
resize?: 'none' | 'vertical' | 'horizontal' | 'both';
}
interface TextInputProps extends ViewProps {
style?: TextInputStyle;
value?: string;
defaultValue?: string;
placeholder?: string;
placeholderTextColor?: ColorValue;
multiline?: boolean;
rows?: number;
maxLength?: number;
readOnly?: boolean;
secureTextEntry?: boolean;
autoFocus?: boolean;
clearTextOnFocus?: boolean;
selectTextOnFocus?: boolean;
blurOnSubmit?: boolean;
// Input mode and keyboard
inputMode?: 'text' | 'numeric' | 'decimal' | 'email' | 'tel' | 'url' | 'search' | 'none';
enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
autoComplete?: string;
autoCorrect?: boolean;
spellCheck?: boolean;
caretHidden?: boolean;
// Selection
selection?: {start: number; end?: number};
selectionColor?: ColorValue;
// Events
onChangeText?: (text: string) => void;
onChange?: (event: ChangeEvent) => void;
onFocus?: (event: FocusEvent) => void;
onBlur?: (event: BlurEvent) => void;
onSubmitEditing?: (event: SubmitEvent) => void;
onKeyPress?: (event: KeyPressEvent) => void;
onSelectionChange?: (event: SelectionChangeEvent) => void;
onContentSizeChange?: (event: ContentSizeChangeEvent) => void;
// Deprecated
editable?: boolean; // use readOnly instead
keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'number-pad' | 'search' | 'url' | 'web-search'; // use inputMode instead
numberOfLines?: number; // use rows instead
returnKeyType?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'; // use enterKeyHint instead
}Install with Tessl CLI
npx tessl i tessl/npm-react-native-web