Overview
The TextField component is a fully-featured input field with support for labels, error states, helper text, and left/right icons. Built with TypeScript and React forwardRef for maximum flexibility and accessibility. Source:src/shared/ui/TextField/TextField.tsx
Basic Usage
Props
The TextField component extends all standard HTML input attributes and includes these additional props:Label text displayed above the input field.Provides context and improves accessibility by describing the input’s purpose.
When
true, applies error styling to the input field and displays the helper text in error state.Use this to indicate validation errors or other input problems.Helper or error message displayed below the input field.Typically used to provide guidance or display validation errors when
error is true.A Lucide React icon component to display on the left side of the input.Useful for search fields, username inputs, or other contextual indicators.
A Lucide React icon component to display on the right side of the input.Commonly used for password visibility toggles, clear buttons, or validation indicators.
Additional CSS class names for custom styling.
Inline styles to apply to the text field container.
Basic Input
Simple input field without additional features:With Label
Add a label for better accessibility and user guidance:With Icons
Left Icon
Display an icon on the left side of the input:Right Icon
Display an icon on the right side of the input:Error State
Display validation errors with error styling and helper text:Real-World Examples
Search Field
Login Form
Validated Input with Real-time Feedback
Bid Amount Input
TypeScript Types
Accessibility
- Uses semantic HTML with
<label>and<input>elements - Labels are properly associated with inputs via
htmlFor - Error states are indicated with
aria-invalidandaria-describedby - Forwards refs for focus management and advanced accessibility features
- Helper text provides additional context for screen readers
Best Practices
Always provide labels
Always provide labels
Labels improve accessibility and help users understand what information is expected. Even if you want a minimal design, provide a label for screen readers.
Use appropriate input types
Use appropriate input types
Set the correct
type attribute (email, password, tel, number, etc.) to provide better mobile keyboard experiences and browser validation.Provide helpful error messages
Provide helpful error messages
Error messages should be specific and actionable. Instead of “Invalid input”, use “Email must contain an @ symbol” or “Password must be at least 8 characters”.
Icon selection
Icon selection
Choose icons that clearly represent the input’s purpose. Common patterns:
- Search: Search icon (left)
- Email: Mail icon (left or right)
- Password: Lock icon (left), Eye icon for visibility toggle (right)
- Username: User icon (left)
- Validation: Check or X icon (right)
Known Limitations
The current implementation has hardcoded placeholder text and IDs in some instances (see
TextField.tsx:30-32). These are overridden by props, but you may want to refine the component for production use.Related Components
Button
Commonly used with TextField in forms
Typography
For consistent label and helper text styling