Input
A customizable text input component with floating label, error handling, and icon support.
Input
The Input component is a customizable text input field with a floating label animation, error handling, and support for right icons. It enhances the standard React Native TextInput with additional features and styling to create a cohesive and user-friendly form experience.
Features
- Floating Label: Label animates from placeholder to top position when focused or filled
- Error Handling: Displays error messages with distinct styling
- Password Support: Toggle visibility option for password fields
- Right Icon: Optional icon on the right side with customizable press behavior
- Multiline Support: Can be used for both single-line and multiline text input
- Customizable Styling: Control for input and container appearance
- Dark Mode Support: Automatic light/dark mode styles
Import
Props
Core Props
Prop | Type | Default | Description |
---|---|---|---|
value | string | — | The current value of the input |
onChangeText | (text: string) => void | — | Function called when the text changes |
label | string | — | Text label for the input field |
error | string | — | Error message to display below the input |
Additional Props
Prop | Type | Default | Description |
---|---|---|---|
isPassword | boolean | false | If true, treats the input as a password field with visibility toggle |
rightIcon | IconName | — | Icon to display on the right side of the input |
onRightIconPress | () => void | — | Function called when the right icon is pressed |
isMultiline | boolean | false | If true, enables multiline input mode |
className | string | '' | Additional Tailwind classes for the input |
containerClassName | string | '' | Additional Tailwind classes for the container |
...TextInputProps | — | — | All standard React Native TextInput props are supported |
Usage Examples
Basic Input
Password Input
Input with Error
Input with Right Icon
Multiline Input
Custom Styled Input
Form Example
Best Practices
Clear Labels
Use descriptive labels that clearly indicate what information is required:
Contextual Keyboard Types
Set the appropriate keyboard type for different input fields:
Immediate Validation Feedback
Provide immediate feedback on input validation:
Implementation Details
The Input component uses React Native's TextInput
, View
, and Animated
components to create a polished input experience. The floating label is implemented using an animated value that transitions based on focus state and input value.
For password inputs, the component automatically adds a toggle icon to show/hide the password text.
The component uses the useThemeColors
hook to apply appropriate color schemes for both light and dark modes.
Notes
- The floating label animation occurs when the input is focused or has a value
- The input border color changes based on focus state and error state
- For password fields, a visibility toggle icon is automatically added
- The component supports all standard TextInput props like
placeholder
,keyboardType
, etc. - The input height adjusts automatically when in multiline mode
- Clicking on the label will focus the input field