Text Input
The TextInput component handles single-line user input, with options for a label, caption, prefix/suffix affixes, validation states, and an info tooltip.
Playground
Installation
import { TextInput } from "@harnessio/ui/components";
<TextInput label="Success Input" id="someinput" value="input with value" placeholder="Enter the value" theme="success"/>;Anatomy
TextInput composes a label, the input field, and a caption inside a control group.
- The
labelrenders above (or beside, whenorientation="horizontal") the input. By default it shows a required*marker;optionalremoves it.tooltipContentadds an info icon with a tooltip next to the label, andlabelSuffixadds a custom element on the right of the label. - The input accepts optional
prefixandsuffixcontent rendered inline before and after the text. - Below the input, a caption area shows the
errormessage (in thedangertheme), then thewarningmessage (in thewarningtheme), otherwise the plaincaption. - Every input gets an
id; if you don’t provide one it’s generated automatically and used to associate the label.
Best practices
Do
- Always provide a
label(or anaria-label) so the field’s purpose is clear. - Use
errorfor validation messages — it both shows the message and switches the field to thedangertheme, so you don’t need to setthemeyourself. - Use
captionfor persistent helper text and reserveerror/warningfor state-driven messages. - Add
optionalto fields that aren’t required so the required*marker reflects reality.
Don’t
- Don’t use
TextInputfor numeric or search entry — thetypeprop excludes'number'and'search'(among others); use the dedicated components instead. - Don’t set
theme="danger"on its own to signal an error without anerrormessage; pair them so users see what’s wrong.
Content
- Keep labels short and noun-based; put format hints in the
caption. - Write
errormessages as a clear, actionable statement of what to fix.
Accessibility
Labeling
- The
labelis associated with the input through a sharedid(auto-generated when omitted), so clicking the label focuses the field. - When there’s no visible label, provide an
aria-label. tooltipContentsurfaces supplementary help through an info button beside the label.
Focus & states
disabledremoves the field from the tab order;readOnlykeeps it focusable but non-editable.errorapplies thedangertheme and renders the message beneath the field so the validation state is both visible and adjacent to the input.
Properties
Prop | Required | Default | Type |
|---|---|---|---|
| label | false | string | |
| caption | false | string | |
| error | false | string | |
| warning | false | string | |
| optional | false | false | boolean |
| theme | false | 'default' | 'default' | 'success' | 'danger' | 'warning' |
| size | false | 'md' | 'md' | 'sm' |
| orientation | false | 'vertical' | 'vertical' | 'horizontal' |
| type | false | 'text' | string |
| prefix | false | ReactNode | |
| suffix | false | ReactNode | |
| value | false | string | |
| defaultValue | false | string | |
| onChange | false | React.ChangeEventHandler<HTMLInputElement> | |
| placeholder | false | string | |
| readOnly | false | false | boolean |
| disabled | false | false | boolean |
| id | false | string | |
| tooltipContent | false | Exclude<ReactNode, boolean | null | undefined> | |
| tooltipProps | false | IconWithTooltipProps | |
| labelSuffix | false | ReactNode | |
| className | false | string | |
| inputContainerClassName | false | string | |
| wrapperClassName | false | string |