Overview
HuxOtpInput is a customizable OTP (One-Time Password) input component with consistent styling and extensive customization options. It provides a clean, modern OTP input with multiple digit fields, automatic focus management, paste support, and validation while automatically adapting to light and dark themes.Basic Usage
Simple OTP Input
OTP Input with Helper Text
OTP Input with Validation
OTP Input with Different Length
Properties
Core Properties
length- Number of OTP digits (default: 6)label- Optional field label text displayed above the inputhelperText- Helper text displayed below the inputerrorText- Error text displayed below the input, overrides helperTextonChanged- Callback triggered when the input value changesonCompleted- Callback triggered when all OTP digits are filled
Validation Properties
validator- Form validation function that returns error text or nullerrorText- Custom error message (overrides validator output)
Behavior Properties
enabled- Whether the input is interactive (default: true)obscureText- Whether to hide the digits (for security, default: false)autofocus- Whether to automatically focus the first field (default: false)width- Custom width (optional, defaults to full width)
Features
Automatic Focus Management
The OTP input automatically moves focus to the next field when a digit is entered, providing a smooth user experience.Keyboard Navigation
- Backspace: Moves to the previous field when the current field is empty
- Arrow Keys: Navigate between fields using left and right arrow keys
- Paste Support: Paste multi-digit codes to fill all fields at once
Paste Support
Users can paste a code from their clipboard, and the component will automatically distribute the digits across all fields.Styling & Dimensions
Fixed Dimensions
- Height: 40px (consistent across all digit fields)
- Border Radius: 8px (rounded corners)
- Font Size: 18px with medium weight (500)
- Spacing: 8px between digit fields
Padding & Spacing
- Vertical Padding: 12px (top and bottom inside each field)
- Label Gap: 6px (space between label and input)
- Helper Text Gap: 6px (space between input and helper/error text)
Color System
Border Colors
- Default:
HuxTokens.borderPrimary(context) - Focused:
HuxTokens.primary(context)with 50% opacity - Error:
HuxTokens.borderSecondary(context) - Focused Error:
HuxTokens.textDestructive(context)with 2px width - Disabled:
HuxTokens.borderSecondary(context)
Background Colors
- Enabled:
HuxTokens.surfacePrimary(context) - Disabled:
HuxTokens.surfaceSecondary(context)
Text Colors
- Input Text:
HuxTokens.textPrimary(context)with 18px font size - Label Text:
HuxTokens.textSecondary(context)with medium weight - Helper Text:
HuxTokens.textSecondary(context) - Error Text:
HuxTokens.textDestructive(context)
States
Enabled State
- Fully interactive with normal styling
- Responds to user input and focus
- Automatic focus management between fields
Focused State
- Border color changes to primary color with 50% opacity
- Current field is highlighted
Error State
- Error text displayed below the input
- Border color changes to destructive color when focused
- Validation errors shown in real-time
Disabled State
- Input fields are non-interactive
- Reduced opacity styling
- Disabled border and background colors