Input

Through mouse or keyboard input content, it is the most basic form field wrapper.
Importimport{ Input }from"antd";

When To Use

  • A user input in a form field is needed.
  • A search input is required.

Examples

Basic usage example.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Variants of Input.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.13.0
https://
Zhejiang

Use Space.Compact create compact style, See the Space.Compact documentation for more.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code




Search loading when onSearch.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

autoSize prop for a textarea type of Input makes the height to automatically adjust based on the content. An option object can be provided to autoSize to specify the minimum and maximum number of lines the textarea will automatically adjust.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

You can use the Input in conjunction with Tooltip component to create a Numeric Input, which can provide a good experience for extra-long content display.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Input type of password.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
0 / 200 / 1000 / 100

Show character counting.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Add status to Input with status, which could be error or warning.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code




There are three sizes of an Input box: large (40px), default (32px) and small (24px).

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
http://.com
http://
.com
http://.com
cascader

Using pre & post tabs example.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
https://

Example of creating a search box by grouping a standard input with a search button.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code


For multi-line input.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
With formatter (Upcase)
With Disabled
With Length (8)
With variant
With custom display character

One time password input.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.16.0


RMB

RMB

Add a prefix or suffix icons inside input.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code


Input box with the remove icon, click the icon to delete everything.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Exceed Max
12 / 10
Emoji count as length 1
3
Not exceed max
6 / 6

It is necessary to customize the counting ability in some scenarios (such as emoji length is counted as 1), which can be achieved through the count attribute. Use count.max attribute exceeds the limit of the native maxLength.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
>= 5.10.0

Focus with additional option.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

Input

PropertyDescriptionTypeDefaultVersion
addonAfterThe label text displayed after (on the right side of) the input fieldReactNode-
addonBeforeThe label text displayed before (on the left side of) the input fieldReactNode-
allowClearIf allow to remove input content with clear iconboolean | { clearIcon: ReactNode }false
borderedWhether has border style, please use variant insteadbooleantrue4.5.0
classNamesSemantic DOM classRecord<SemanticDOM, string>-5.4.0
countCharacter count configCountConfig-5.10.0
defaultValueThe initial input contentstring-
disabledWhether the input is disabledbooleanfalse
idThe ID for inputstring-
maxLengthThe maximum number of characters in Inputnumber-
prefixThe prefix icon for the InputReactNode-
showCountWhether to show character countboolean | { formatter: (info: { value: string, count: number, maxLength?: number }) => ReactNode }false4.18.0 info.value: 4.23.0
statusSet validation status'error' | 'warning'-4.19.0
stylesSemantic DOM styleRecord<SemanticDOM, CSSProperties>-5.4.0
sizeThe size of the input box. Note: in the context of a form, the middle size is usedlarge | middle | small-
suffixThe suffix icon for the InputReactNode-
typeThe type of input, see: MDN( use Input.TextArea instead of type="textarea")stringtext
valueThe input content valuestring-
variantVariants of Inputoutlined | borderless | filledoutlined5.13.0
onChangeCallback when user inputfunction(e)-
onPressEnterThe callback function that is triggered when Enter key is pressedfunction(e)-
onClearCallback when click the clear button() => void-5.20.0

When Input is used in a Form.Item context, if the Form.Item has the id props defined then value, defaultValue, and id props of Input are 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:

PropertyDescriptionTypeDefaultVersion
autoSizeHeight auto size feature, can be set to true | false or an object { minRows: 2, maxRows: 6 }boolean | objectfalse
classNamesSemantic DOM classRecord<SemanticDOM, string>-5.4.0
stylesSemantic DOM styleRecord<SemanticDOM, CSSProperties>-5.4.0

The rest of the props of Input.TextArea are the same as the original textarea.

Input.Search

PropertyDescriptionTypeDefault
enterButtonfalse displays the default button color, true uses the primary color, or you can provide a custom button. Conflicts with addonAfter.ReactNodefalse
loadingSearch box with loadingbooleanfalse
onSearchThe callback function triggered when you click on the search-icon, the clear-icon or press the Enter keyfunction(value, event, { source: "input" | "clear" })-

Supports all props of Input.

Input.Password

PropertyDescriptionTypeDefaultVersion
iconRenderCustom toggle button(visible) => ReactNode(visible) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />)4.3.0
visibilityToggleWhether show toggle button or control password visibleboolean | VisibilityToggletrue

Input.OTP

Added in 5.16.0.

Notes for developers

When the mask prop 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.

PropertyDescriptionTypeDefaultVersion
defaultValueDefault valuestring-
disabledWhether the input is disabledbooleanfalse
formatterFormat display, blank fields will be filled with (value: string) => string-
maskCustom display, the original value will not be modifiedboolean | stringfalse5.17.0
lengthThe number of input elementsnumber6
statusSet validation status'error' | 'warning'-
sizeThe size of the input boxsmall | middle | largemiddle
variantVariants of Inputoutlined | borderless | filledoutlined
valueThe input content valuestring-
onChangeTrigger when all the fields are filled(value: string) => void-
onInputTrigger when the input value changes(value: string[]) => void-5.22.0

VisibilityToggle

PropertyDescriptionTypeDefaultVersion
visibleWhether the password is show or hidebooleanfalse4.24.0
onVisibleChangeCallback executed when visibility of the password is changed(visible) => void-4.24.0

Input Methods

NameDescriptionParametersVersion
blurRemove focus-
focusGet focus(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' })option - 4.10.0

Semantic DOM

Input

17
  • input
    5.4.0
    input element
  • prefix
    5.4.0
    prefix element
  • suffix
    5.4.0
    suffix element
  • count
    5.4.0
    count element

Input.TextArea

17 / 100
  • textarea
    5.4.0
    textarea element
  • count
    5.4.0
    count element

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
activeBgBackground color when the input box is activatedstring#ffffff
activeBorderColorActive border colorstring#1677ff
activeShadowBox-shadow when activestring0 0 0 2px rgba(5,145,255,0.1)
addonBgBackground color of addonstringrgba(0,0,0,0.02)
errorActiveShadowBox-shadow when active in error statusstring0 0 0 2px rgba(255,38,5,0.06)
hoverBgBackground color when the input box hoversstring#ffffff
hoverBorderColorHover border colorstring#4096ff
inputFontSizeFont sizenumber14
inputFontSizeLGFont size of largenumber16
inputFontSizeSMFont size of smallnumber14
paddingBlockVertical padding of inputnumber4
paddingBlockLGVertical padding of large inputnumber7
paddingBlockSMVertical padding of small inputnumber0
paddingInlineHorizontal padding of inputnumber11
paddingInlineLGHorizontal padding of large inputnumber11
paddingInlineSMHorizontal padding of small inputnumber7
warningActiveShadowBox-shadow when active in warning statusstring0 0 0 2px rgba(255,215,5,0.1)

Global TokenHow to use?

FAQ

Why Input lose 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.