Input
Input is a text field: a one-line input, a password field or a multi-line textarea, in a bordered box that can also hold a prefix, a suffix, a clear button, a spinner and a character count. It sits on one line with a Button of the same size.
Demos
Basic
type="textarea" renders a multi-line field.
Size
tiny, small, medium (default) and large, the same heights as Button.
Round
round gives a text field a pill shape.
Prefix and suffix
prefix and suffix take any content: an icon, a currency, a unit.
Password
type="password" with showPasswordOn adds an eye button: click toggles the password, mousedown shows it only while the button is held.
Clearable
clearable adds a clear button that shows while the field has a value and is hovered or focused. It empties the field, calls onClear and keeps the focus in the field.
Autosize
autosize lets a textarea grow with its text: true starts at one row, { minRows, maxRows } bounds it and scrolls past maxRows. Without it, rows sets the height (default 3) and the textarea can be resized vertically.
Count
showCount shows the length, against maxLength when set. A textarea shows it under the text.
Status
status colors the border for validation: success, warning or error. Pair error with aria-invalid and a message the field points at with aria-describedby.
Loading
loading shows a spinner at the end. loading={false} keeps the spinner’s room, so the text doesn’t shift when loading starts.
Disabled and read-only
disabled blocks the field; readOnly keeps it focusable and selectable but not editable. Neither shows the clear button.
Controlled
Pass value and onUpdateValue to own the value. null means empty.
Native props and ref
Native attributes and events (id, name, autoComplete, role, aria-*, onKeyDown, …) go to the native input or textarea, and so does ref, so you can call focus() or select() on it. inputProps takes more of them; its type replaces the native type of a text field, e.g. email or search.
Input group
InputGroup joins Inputs, Buttons and InputGroupLabels into one row with shared borders.
Accessibility
Give every field a visible <label htmlFor> or an aria-label; id goes to the native element. The clear button is left out of the tab order (Select All and Delete do the same from the keyboard); the password toggle is a toggle button with aria-pressed, reachable by Tab when showPasswordOn="click". Their labels come from the ConfigProvider locale (Input.clear, Input.showPassword).
Props
Input
| Name | Type | Default | Description | Version |
|---|---|---|---|---|
type | text | password | textarea | text | The kind of field. | Unreleased |
value | string | null | undefined | Value when controlled; null means empty. | Unreleased |
defaultValue | string | null | null | Initial value when uncontrolled. | Unreleased |
onUpdateValue | (value: string) => void | undefined | Called with the new value on every edit and on clear. Native onChange and onInput still get the event. | Unreleased |
size | tiny | small | medium | large | medium | Height, type size and padding, matching Button. | Unreleased |
placeholder | string | undefined | Native placeholder. | Unreleased |
disabled | boolean | false | Disables the field. | Unreleased |
readOnly | boolean | false | Focusable and selectable, not editable. | Unreleased |
clearable | boolean | false | Adds a clear button while there is a value. | Unreleased |
onClear | (event) => void | undefined | Called after the clear button empties the field. | Unreleased |
status | success | warning | error | undefined | Validation status; colors the border. | Unreleased |
round | boolean | false | Pill shape. Ignored by textarea. | Unreleased |
prefix | ReactNode | undefined | Content before the text. | Unreleased |
suffix | ReactNode | undefined | Content after the text. | Unreleased |
loading | boolean | undefined | Shows a spinner at the end; false keeps its room. | Unreleased |
showPasswordOn | click | mousedown | undefined | With type="password", adds a toggle that reveals the password. | Unreleased |
maxLength | number | undefined | Native maximum length, also shown by the count. | Unreleased |
showCount | boolean | false | Shows the length, and maxLength when set. | Unreleased |
rows | number | 3 | Rows of a textarea without autosize. | Unreleased |
autosize | boolean | { minRows?, maxRows? } | false | Grows a textarea with its text, between the given rows. | Unreleased |
autoFocus | boolean | false | Native autofocus. | Unreleased |
inputProps | InputNativeProps | undefined | More attributes for the native element. Top-level props win; its type replaces a text field’s native type. | Unreleased |
ref | Ref<HTMLInputElement | HTMLTextAreaElement> | undefined | The native input or textarea. | Unreleased |
wrapperRef | Ref<HTMLDivElement> | undefined | The bordered box, e.g. to anchor a popup to. | Unreleased |
className and style go to the bordered box. Every other native attribute and event, including onFocus, onBlur, onKeyDown, role and aria-*, goes to the native input or textarea. For a pair of values, use two Inputs.
InputGroup
InputGroup takes native div attributes and a ref. Give a group of related fields an aria-label or role="group" when it needs a name.
InputGroupLabel
| Name | Type | Default | Description | Version |
|---|---|---|---|---|
size | tiny | small | medium | large | medium | Match it to the Inputs in the group. | Unreleased |
InputGroupLabel also takes native span attributes and a ref.