Input
Through mouse or keyboard input content, it is the most basic form field wrapper.
When To Use
- A user input in a form field is needed.
- A search input is required.
Examples
-
Basic usage ·
basic -
Three sizes of Input ·
size -
Variants ·
variant -
Compact Style ·
compact-style -
Search box ·
search-input -
Search box with loading ·
search-input-loading -
TextArea ·
textarea -
Autosizing the height to fit the content ·
autosize-textarea -
OTP ·
otp -
Format Tooltip Input ·
tooltip -
prefix and suffix ·
presuffix -
Password box ·
password-input -
With clear icon ·
allowClear -
With character counting ·
show-count -
Custom count logic ·
advance-count -
Status ·
status -
Focus ·
focus -
Custom semantic dom styling ·
style-class
API
Common props ref:Common props
Input
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| The label text displayed after (on the right side of) the input field, please use Space.Compact instead | ReactNode | - | × | ||
| The label text displayed before (on the left side of) the input field, please use Space.Compact instead | ReactNode | - | × | ||
| allowClear | Whether to show a clear icon to remove input content | boolean | { clearIcon: ReactNode, disabled?: boolean } | - | disabled: 6.4.0 | 5.15.0 |
Whether has border style, please use variant instead | boolean | true | 4.5.0 | × | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 5.4.0 | 5.7.0 |
| count | Character count config | CountConfig | - | 5.10.0 | × |
| defaultValue | The initial input content | string | - | × | |
| disabled | Whether the input is disabled | boolean | false | - | × |
| id | The ID for input | string | - | × | |
| maxLength | The maximum number of characters in Input | number | - | × | |
| prefix | The prefix icon for the Input | ReactNode | - | × | |
| showCount | Whether to show character count | boolean | { formatter: (info: { value: string, count: number, maxLength?: number }) => ReactNode } | false | 4.18.0 info.value: 4.23.0 | × |
| status | Set validation status | 'error' | 'warning' | - | 4.19.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 5.4.0 | 5.7.0 |
| size | The size of the input box. Note: in the context of a form, the medium size is used | large | medium | small | - | × | |
| suffix | The suffix icon for the Input | ReactNode | - | × | |
| type | The type of input, see: MDN( use Input.TextArea instead of type="textarea") | string | text | × | |
| value | The input content value | string | - | × | |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 | 5.19.0 |
| onChange | Callback when user input | function(e) | - | × | |
| onPressEnter | The callback function that is triggered when Enter key is pressed | function(e) | - | × | |
| onClear | Callback when click the clear button | () => void | - | 5.20.0 | × |
When
Inputis used in aForm.Itemcontext, if theForm.Itemhas theidprops defined thenvalue,defaultValue, andidprops ofInputare automatically set.
The rest of the props of Input are exactly the same as the original input.
CountConfig
interface CountConfig {
// Max character count. Different from the native `maxLength`, it will be marked warning but not truncated
max?: number;
// Custom character count, for example, the standard emoji length is greater than 1, you can customize the counting strategy to change it to 1
strategy?: (value: string) => number;
// Same as `showCount`
show?: boolean | ((args: { value: string; count: number; maxLength?: number }) => ReactNode);
// Custom clipping logic when the number of characters exceeds `count.max`, no clipping when not configured
exceedFormatter?: (value: string, config: { max: number }) => string;
}
Input.TextArea
Same as Input, and more:
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| autoSize | Height auto size feature, can be set to true | false or an object { minRows: 2, maxRows: 6 } | boolean | object | false | × | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 5.4.0 | 5.15.0 |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 5.4.0 | 5.15.0 |
The rest of the props of Input.TextArea are the same as the original textarea.
Input.Search
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 6.0.0 | 6.0.0 |
| enterButton | false displays the default button color, true uses the primary color, or you can provide a custom button. Conflicts with addonAfter. | ReactNode | false | × | |
| loading | Search box with loading | boolean | false | × | |
| onSearch | The callback function triggered when you click on the search-icon, the clear-icon or press the Enter key | function(value, event, { source: "input" | "clear" }) | - | × | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 6.0.0 | 6.0.0 |
| searchIcon | Customize the search icon | ReactNode | - | 6.4.0 | 6.4.0 |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 | 6.6.0 |
Supports all props of Input.
Input.Password
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| classNames | Semantic DOM class | Record<SemanticDOM, string> | - | 5.4.0 | 6.4.0 |
| iconRender | Custom toggle button | (visible) => ReactNode | (visible) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />) | 4.3.0 | 6.4.0 |
| styles | Semantic DOM style | Record<SemanticDOM, CSSProperties> | - | 5.4.0 | 6.4.0 |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 | 6.6.0 |
| visibilityToggle | Whether show toggle button or control password visible | boolean | VisibilityToggle | true | × |
Input.OTP
Added in 5.16.0.
Notes for developers
When the
maskprop is string, we recommend receiving a single character or a single emoji. If multiple characters or multiple emoji are passed, a warning will be thrown.
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| autoComplete | The autocomplete attribute for input elements, e.g. one-time-code for OTP autofill | string | - | 6.3.0 | × |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 6.0.0 | 6.0.0 |
| defaultValue | Default value | string | - | × | |
| disabled | Whether the input is disabled | boolean | false | × | |
| formatter | Format display, blank fields will be filled with | (value: string) => string | - | × | |
| separator | render the separator after the input box of the specified index | ReactNode |((i: number) => ReactNode) | - | 5.24.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 6.0.0 | 6.0.0 |
| mask | Custom display, the original value will not be modified | boolean | string | false | 5.17.0 | × |
| length | The number of input elements | number | 6 | × | |
| status | Set validation status | 'error' | 'warning' | - | × | |
| size | The size of the input box | small | medium | large | medium | × | |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | underlined: 5.24.0 | 6.6.0 |
| value | The input content value | string | - | × | |
| onChange | Trigger when all the fields are filled | (value: string) => void | - | × | |
| onInput | Trigger when the input value changes | (value: string[]) => void | - | 5.22.0 | × |
VisibilityToggle
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| tabIndex | Set the tabIndex of the toggle button | number | 0 | 6.5.0 |
| visible | Whether the password is show or hide | boolean | false | 4.24.0 |
| onVisibleChange | Callback executed when visibility of the password is changed | (visible) => void | - | 4.24.0 |
Input Methods
| Name | Description | Parameters | Version |
|---|---|---|---|
| blur | Remove focus | - | |
| focus | Get focus | (option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' }) | option - 4.10.0 |
Semantic DOM
Input
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with relative positioning, inline-block display, width, min-width, padding, colors, fonts, line-height, border-radius, transitions and other input container basic styles | — |
prefix | Prefix wrapper element with layout and styling for prefix content | — |
input | Input element with core interactive styles and text input related styling | — |
suffix | Suffix wrapper element with layout and styling for suffix content | — |
clear | Clear button element with layout, visibility, and interaction styles for clearing content | 6.4.0 |
count | Character count element with font and color styles for count display | — |
Semantic description source: vendor/components/input/demo/_semantic_input.tsx
Input.TextArea
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with textarea wrapper styles, border, border radius, transition animation and state control | — |
textarea | Textarea element with font, line height, padding, color, background, border, text input and multi-line text display styles | — |
clear | Clear button element with layout, visibility, and interaction styles for clearing content | 6.4.0 |
count | Count element with character count display position, font, color and numeric statistics styles | — |
Semantic description source: vendor/components/input/demo/_semantic_textarea.tsx
Input.Search
| Semantic node | Native description | Version |
|---|---|---|
root | root element | — |
prefix | prefix element | — |
input | input element | — |
suffix | suffix element | — |
clear | clear button element | 6.4.0 |
count | count element | — |
button.root | button root element | — |
button.icon | button icon element | — |
button.content | button content element | — |
Semantic description source: vendor/components/input/demo/_semantic_search.tsx
Input.Password
| Semantic node | Native description | Version |
|---|---|---|
root | root element | — |
prefix | prefix element | — |
input | input element | — |
suffix | suffix element | — |
clear | clear button element | 6.4.0 |
count | count element | — |
Semantic description source: vendor/components/input/demo/_semantic_password.tsx
Input.OTP
| Semantic node | Native description | Version |
|---|---|---|
root | Root element, set inline flex layout, alignment, column gap and wrapper styles | — |
input | Input element, set text center, padding and number input styles | — |
separator | Separator element, set separator display styles between OTP input boxes | — |
Semantic description source: vendor/components/input/demo/_semantic_otp.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
Native ComponentToken declares no directly extractable own fields. Shared tokens and inheritance are defined by the declarations below.
Declaration source: vendor/components/input/style/token.ts
import { mergeToken } from '../../theme/internal';
import type { AliasToken, FullToken } from '../../theme/internal';
export interface SharedComponentToken {
/**
* @desc 输入框横向内边距
* @descEN Horizontal padding of input
*/
paddingInline: number;
/**
* @desc 小号输入框横向内边距
* @descEN Horizontal padding of small input
*/
paddingInlineSM: number;
/**
* @desc 大号输入框横向内边距
* @descEN Horizontal padding of large input
*/
paddingInlineLG: number;
/**
* @desc 输入框纵向内边距
* @descEN Vertical padding of input
*/
paddingBlock: number;
/**
* @desc 小号输入框纵向内边距
* @descEN Vertical padding of small input
*/
paddingBlockSM: number;
/**
* @desc 大号输入框纵向内边距
* @descEN Vertical padding of large input
*/
paddingBlockLG: number;
/**
* @desc 前/后置标签背景色
* @descEN Background color of addon
*/
addonBg: string;
/**
* @desc 悬浮态边框色
* @descEN Hover border color
*/
hoverBorderColor: string;
/**
* @desc 激活态边框色
* @descEN Active border color
*/
activeBorderColor: string;
/**
* @desc 激活态阴影
* @descEN Box-shadow when active
*/
activeShadow: string;
/**
* @desc 错误状态时激活态阴影
* @descEN Box-shadow when active in error status
*/
errorActiveShadow: string;
/**
* @desc 警告状态时激活态阴影
* @descEN Box-shadow when active in warning status
*/
warningActiveShadow: string;
/**
* @desc 输入框hover状态时背景颜色
* @descEN Background color when the input box hovers
*/
hoverBg: string;
/**
* @desc 输入框激活状态时背景颜色
* @descEN Background color when the input box is activated
*/
activeBg: string;
/**
* @desc 字体大小
* @descEN Font size
*/
inputFontSize: number;
/**
* @desc 大号字体大小
* @descEN Font size of large
*/
inputFontSizeLG: number;
/**
* @desc 小号字体大小
* @descEN Font size of small
*/
inputFontSizeSM: number;
}
export interface ComponentToken extends SharedComponentToken {}
export interface SharedInputToken {
inputAffixPadding: number;
}
export interface InputToken extends FullToken<'Input'>, SharedInputToken {}
FAQ
Why Input loses focus when change prefix/suffix/showCount
When Input dynamic add or remove prefix/suffix/showCount will make React recreate the dom structure and new input will be not focused. You can set an empty <span /> element to keep the dom structure:
const suffix = condition ? <Icon type="smile" /> : <span />;
<Input suffix={suffix} />;
Why TextArea in control can make value exceed maxLength?
When in control, component should show as what it set to avoid submit value not align with store value in Form.
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/input/Group.tsxvendor/components/input/Input.tsxvendor/components/input/OTP/OTPInput.tsxvendor/components/input/OTP/index.tsxvendor/components/input/Password.tsxvendor/components/input/Search.tsxvendor/components/input/TextArea.tsxvendor/components/input/index.tsxvendor/components/input/style/token.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.