Text Input
The Text Input component supports single-line text entry with theming, validation states, icons, labels, password visibility toggling, and accessibility features for flexible input handling.
Usage
Default
const [value, setValue] = useState("");
<TextInput
value={value}
onChange={(nextValue) => setValue(nextValue)}
placeholder="Enter text..."
/>With Label
const [value, setValue] = useState("");
<TextInput
label="Username"
labelPosition="top"
value={value}
onChange={(nextValue) => setValue(nextValue)}
placeholder="Enter your username"
/>With Icon
const [value, setValue] = useState("");
<TextInput
icon={FaUser}
value={value}
onChange={(nextValue) => setValue(nextValue)}
placeholder="Username"
/>Password Input
const [value, setValue] = useState("");
<TextInput
password
icon={FaLock}
value={value}
onChange={(nextValue) => setValue(nextValue)}
placeholder="Enter password"
/>Validation States
<TextInput state="success" defaultValue="Valid value" />
<TextInput state="warning" defaultValue="Needs review" />
<TextInput state="error" defaultValue="Invalid value" />Outlined Input
const [value, setValue] = useState("");
<TextInput
outline
label="Email"
icon={FaEnvelope}
value={value}
onChange={(nextValue) => setValue(nextValue)}
placeholder="Enter your email"
/>With Accessible Description
<TextInput
label="Display Name"
ariaDescription="Use between 3 and 20 characters."
placeholder="Choose a display name"
maxLength={20}
/>Props
| Type | Description | |
|---|---|---|
| aria-activedescendant | string | Identifies the current autocomplete suggestion in custom combobox patterns. |
| aria-controls | string | Identifies the element controlled by this input. |
| aria-describedby | string | References one or more elements that describe the input. |
| aria-description | string | Provides a short hint to assistive technologies. |
| aria-disabled | boolean | Indicates whether the element is disabled to assistive technologies. |
| aria-expanded | boolean | Indicates whether the input controls an expandable popup. |
| aria-haspopup | boolean | "dialog" | "grid" | "listbox" | "menu" | "tree" | "true" | "false" | Indicates whether a popup such as a listbox, grid, or dialog is available. |
| aria-invalid | boolean | "true" | "false" | "grammar" | "spelling" | Indicates whether the input has an invalid value. |
| aria-label | string | Explicit accessible label for the outer field region if needed. |
| aria-labelledby | string | References one or more elements that label the input. |
| aria-readonly | boolean | Indicates whether the input is read-only to assistive technologies. |
| aria-required | boolean | Indicates whether user input is required. |
| autocomplete | boolean | Controls whether autocomplete is enabled. Pass true for "on" or false for "off". |
| className | string | Additional CSS class names for custom styling. |
| data-testid | string | Optional test ID for testing frameworks. |
| icon | ComponentType<{ className?: string; "aria-hidden"?: boolean; }> | Optional icon component displayed beside the input. |
| label | string | Optional visible label/title for the input. |
| labelPosition | LabelPositionType | Position of the label. "top" | "left" | "right" | "bottom" |
| maxLength | number | Maximum length of the input. |
| onChange | ((value: string, event: React.ChangeEvent<HTMLInputElement>) => void) | Called when the input value changes. Returns both the current value and the original change event. |
| outline | boolean | If true, the input is outlined instead of filled. |
| password | boolean | If true, the input behaves as a password field and shows a visibility toggle. |
| readOnly | boolean | If true, the input is rendered in read-only mode. |
| role | React.AriaRole | Declares the role when this input is used in advanced patterns such as searchbox, combobox, or spinbutton. |
| rounding | RoundingType | Rounding of the component. "none" | "small" | "medium" | "large" | "full" |
| shadow | ShadowType | Shadow of the component. "none" | "light" | "medium" | "strong" | "intense" |
| srOnlyText | ReactNode | Optional content rendered for assistive technologies only. Useful for dynamic status or extra context. |
| state | StateType | State of the input. "success" | "error" | "warning" | "disabled" | "" |
| theme | ThemeType | Theme used for styling. "primary" | "secondary" | "tertiary" | "quaternary" | "clear" |