Input Limited
A customizable input field with character limit and validation support.
Introduction
The LimitedInput
component provides a feature-rich input field with built-in character counting, limit enforcement, and visual progress indicators. It’s perfect for form fields where character count matters, such as usernames, bios, comments, and more.
Examples
Simple Limited Input
Simple Limited Input
0/20
Validated Limited Input
Validated Limited Input
Please enter at least 5 characters.
0/30
Input must be at least 5 characters long.
Installation
Quickly add the component using:
File Structure
Props
Prop | Type | Default |
---|---|---|
label | string | "Input Label" |
id | string | "limited-input" |
value | string | - |
onChange | (value: string) => void | - |
characterLimit | number | 50 |
required | boolean | false |
helperText | string | - |
error | string | - |
placeholder | string | - |
progressBarProps | { className?: string; style?: React.CSSProperties } | - |
countStyle | React.CSSProperties | - |
Advanced Usage
Custom Progress Bar Styling
You can customize the progress bar appearance:
Conditional Validation
Implement custom validation logic:
Form Integration
Accessibility
The LimitedInput
component includes several accessibility features:
- Properly associates labels with inputs using
htmlFor
- Indicates required fields both visually and with
aria-required
- Provides visual feedback on character limits
- Ensures error messages are accessible to screen readers
Conclusion
The LimitedInput
component provides a user-friendly way to implement character-limited input fields in your application. With built-in validation support, visual progress indicators, and customization options, it’s a versatile solution for a wide range of form scenarios.