logoAnt Design

⌘ K
  • 디자인
  • 개발
  • 컴포넌트
  • 블로그
  • 자료
5.21.3
  • 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
  • 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
    • Tabs
    • 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

Input

Through mouse or keyboard input content, it is the most basic form field wrapper.
가져오기import{ Input }from"antd";
소스components/input
문서
이 페이지 수정변경 로그

Resources

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
ahooks-React Hooks Library
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
Work with Us

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
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
enterButtonWhether to show an enter button after input. This property conflicts with the addonAfter propertyReactNodefalse
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 filledfunction(value: string)-

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

컴포넌트 토큰어떻게 사용하나요?

토큰 이름설명타입기본값
activeBg输入框激活状态时背景颜色string#ffffff
activeBorderColor激活态边框色string#1677ff
activeShadow激活态阴影string0 0 0 2px rgba(5, 145, 255, 0.1)
addonBg前/后置标签背景色stringrgba(0, 0, 0, 0.02)
errorActiveShadow错误状态时激活态阴影string0 0 0 2px rgba(255, 38, 5, 0.06)
hoverBg输入框hover状态时背景颜色string#ffffff
hoverBorderColor悬浮态边框色string#4096ff
inputFontSize字体大小number14
inputFontSizeLG大号字体大小number16
inputFontSizeSM小号字体大小number14
paddingBlock输入框纵向内边距number4
paddingBlockLG大号输入框纵向内边距number7
paddingBlockSM小号输入框纵向内边距number0
paddingInline输入框横向内边距number11
paddingInlineLG大号输入框横向内边距number11
paddingInlineSM小号输入框横向内边距number7
warningActiveShadow警告状态时激活态阴影string0 0 0 2px rgba(255, 215, 5, 0.1)

글로벌 토큰어떻게 사용하나요?

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.

Basic usage
codepen icon
External Link Icon
expand codeexpand code
Variants
codepen icon
External Link Icon
expand codeexpand code
5.13.0
Pre / Post tab
codepen icon
External Link Icon
expand codeexpand code
Input Group
codepen icon
External Link Icon
expand codeexpand code
Search box with loading
codepen icon
External Link Icon
expand codeexpand code
Autosizing the height to fit the content
codepen icon
External Link Icon
expand codeexpand code
Format Tooltip Input
codepen icon
External Link Icon
expand codeexpand code
Password box
codepen icon
External Link Icon
expand codeexpand code
With character counting
codepen icon
External Link Icon
expand codeexpand code
Status
codepen icon
External Link Icon
expand codeexpand code
Style Debug
codepen icon
External Link Icon
expand codeexpand code
TextArea
codepen icon
External Link Icon
expand codeexpand code
debug token
codepen icon
External Link Icon
expand codeexpand code
Three sizes of Input
codepen icon
External Link Icon
expand codeexpand code
Filled Debug
codepen icon
External Link Icon
expand codeexpand code
Compact Style
codepen icon
External Link Icon
expand codeexpand code
Search box
codepen icon
External Link Icon
expand codeexpand code
TextArea
codepen icon
External Link Icon
expand codeexpand code
OTP
codepen icon
External Link Icon
expand codeexpand code
5.16.0
prefix and suffix
codepen icon
External Link Icon
expand codeexpand code
With clear icon
codepen icon
External Link Icon
expand codeexpand code
Custom count logic
codepen icon
External Link Icon
expand codeexpand code
>= 5.10.0
Focus
codepen icon
External Link Icon
expand codeexpand code
Text Align
codepen icon
External Link Icon
expand codeexpand code
debug Pre / Post tab
codepen icon
External Link Icon
expand codeexpand code
http://.com
http://
.com
http://.com
cascader




Zhejiang


Option1
@



Option1-1
Option2-2

Between

Sign Up
Email

Home
Select Address




0 / 200 / 1000 / 100
¥RMB¥RMB$$




$$$
http://.comhttp://.comhttp://.com
.com.com.com
http://http://http://
012
https://
Zhejiang
https://


With formatter (Upcase)
With Disabled
With Length (8)
With variant
With custom display character


¥RMB

¥RMB


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

Ant Design1212
Jack
Zhejiang / Hangzhou / West Lake
input here

Http://$.comYY
Input addon Button:


Input addon Button icon:
17
  • input
    5.4.0
    입력 요소
  • prefix
    5.4.0
    접두사 요소
  • suffix
    5.4.0
    접미사 요소
  • count
    5.4.0
    카운트 요소
17 / 100
  • textarea
    5.4.0
    텍스트 영역 요소
  • count
    5.4.0
    글자 수 요소