Skip to content

Form Components

Form Components provide consistent, accessible input elements for user data collection across the app.

When to Use:

  • Building forms (login, contact edit, settings)
  • Collecting user input
  • Implementing filters and search

Props:

interface TextInputProps {
value: string;
onChangeText: (text: string) => void;
placeholder?: string;
label?: string;
error?: string;
secureTextEntry?: boolean;
multiline?: boolean;
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad';
}

Usage:

<TextInput
label="Email"
value={email}
onChangeText={setEmail}
placeholder="Enter your email"
keyboardType="email-address"
error={emailError}
/>

Props:

interface SelectProps {
label?: string;
value: string;
options: SelectOption[];
onSelect: (value: string) => void;
}
interface SelectOption {
label: string;
value: string;
}

Usage:

<Select
label="Status"
value={status}
options={[
{ label: 'Open', value: 'open' },
{ label: 'Resolved', value: 'resolved' },
]}
onSelect={setStatus}
/>

Props:

interface CheckboxProps {
checked: boolean;
onChange: (checked: boolean) => void;
label?: string;
}

Usage:

<Checkbox
checked={isPrivate}
onChange={setIsPrivate}
label="Send as private note"
/>

Form components support validation:

  • Show error state on invalid input
  • Display error message below field
  • Clear error on user interaction
  • Label association with input
  • Error announcements for screen readers
  • Focus management for keyboard navigation
import { render, fireEvent } from '@testing-library/react-native';
import { TextInput } from './TextInput';
describe('TextInput', () => {
it('should call onChangeText when text changes', () => {
const onChangeText = jest.fn();
const { getByPlaceholderText } = render(
<TextInput
value=""
onChangeText={onChangeText}
placeholder="Enter text"
/>
);
fireEvent.changeText(getByPlaceholderText('Enter text'), 'Hello');
expect(onChangeText).toHaveBeenCalledWith('Hello');
});
});