logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
5.25.4
  • Components Overview
  • General
    • Button
    • FloatButton
      5.0.0
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
      5.10.0
    • Grid
    • Layout
    • Space
    • Splitter
      5.21.0
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
      5.5.0
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCode
      5.1.0
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
      5.0.0
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
      5.1.0
  • Other
    • Affix
    • App
      5.1.0
    • ConfigProvider
    • Util
      5.13.0
When To Use
Examples
Basic usage
Three sizes of Input
Variants
Pre / Post tab
Compact Style
Search box
Search box with loading
TextArea
Autosizing the height to fit the content
OTP
Format Tooltip Input
prefix and suffix
Password box
With clear icon
With character counting
Custom count logic
Status
Focus
API
Input
Input.TextArea
Input.Search
Input.Password
Input.OTP
Semantic DOM
Input
Input.TextArea
Design Token
FAQ
Why Input lose focus when change prefix/suffix/showCount
Why TextArea in control can make value exceed maxLength?

Input

Through mouse or keyboard input content, it is the most basic form field wrapper.
Importimport { Input } from "antd";
Sourcecomponents/input
Docs
Edit this pageChangelog
contributors
  • FormInputNumber

    Resources

    Ant Design X
    Ant Design Charts
    Ant Design Pro
    Pro Components
    Ant Design Mobile
    Ant Design Mini
    Ant Design Web3
    Ant Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Ant Design
    Medium
    Twitter
    yuque logoAnt Design in YuQue
    Ant Design in Zhihu
    Experience Cloud Blog
    seeconf logoSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTech logoMore Products

    yuque logoYuQue-Document Collaboration Platform
    AntV logoAntV-Data Visualization
    Egg logoEgg-Enterprise Node.js Framework
    Kitchen logoKitchen-Sketch Toolkit
    Galacean logoGalacean-Interactive Graphics Solution
    xtech logoAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Ant Design Community
    loading

    When To Use

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

    Examples

    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 | filled | underlinedoutlined5.13.0 | underlined: 5.24.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

    tsx
    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-
    separatorrender the separator after the input box of the specified indexReactNode |((i: number) => ReactNode)-5.24.0
    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 | filled | underlinedoutlinedunderlined: 5.24.0
    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

    Input.TextArea

    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:

    jsx
    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.

    Basic usage

    Basic usage example.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Variants

    Variants of Input, there are four variants: outlined filled borderless and underlined.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    5.13.0
    Compact Style

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

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Search box with loading

    Search loading when onSearch.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Autosizing the height to fit the content

    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
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Format Tooltip Input

    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
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Password box

    Input type of password.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    With character counting

    Show character counting.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Status

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

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Three sizes of Input

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

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Pre / Post tab

    Using pre & post tabs example.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Search box

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

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    TextArea

    For multi-line input.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    OTP

    One time password input.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    5.16.0
    prefix and suffix

    Add a prefix or suffix icons inside input.

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    With clear icon

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

    CodeSandbox Icon
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    Custom count logic

    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
    codeblock
    codepen icon
    External Link Icon
    expand codeexpand code
    >= 5.10.0
    Focus

    Focus with additional option.

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




    0 / 200 / 1000 / 100




    http://.com
    http://
    .com
    http://.com
    cascader
    https://


    With formatter (Upcase)
    With Disabled
    With Length (8)
    With variant
    With custom display character
    With custom ReactNode separator
    /////
    With custom function separator
    —————


    ¥RMB

    ¥RMB


    Exceed Max
    12 / 10
    Emoji count as length 1
    3
    Not exceed max
    6 / 6

    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
    17 / 100
    • textarea
      5.4.0
      textarea element
    • count
      5.4.0
      count element