logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHubCodeRabbit
6.4.5
  • Components Overview
  • Changelog
    v6.4.5
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • 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
      DEPRECATED
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.0
    • ConfigProvider
    • Util
When To Use
Examples
Basic Usage
Customized
Customize Input Component
Non-case-sensitive AutoComplete
Lookup-Patterns - Certain Category
Lookup-Patterns - Uncertain Category
Status
Variants
Customize clear button
Custom semantic dom styling
API
showSearch
Methods
Semantic DOM
Design Token
FAQ
Why doesn't the text composition system work well with onSearch in controlled mode?
Why won't a controlled open AutoComplete display a drop-down menu when options are empty?

AutoComplete

Autocomplete function of input field.
Importimport { AutoComplete } from 'antd';
GitHub
components/auto-completeIssueOpen issues
Docs
Edit this pageLLMs.md
TabsCascader

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
X
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
For Agents
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
WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

  • When you need an input box instead of a selector.
  • When you need input suggestions or helping text.

The differences with Select are:

  • AutoComplete is an input box with text hints, and users can type freely. The keyword is aiding input.
  • Select is selecting among given choices. The keyword is select.

Examples

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
allowClearShow clear buttonboolean | { clearIcon?: ReactNode }false5.8.0: Support Object type
backfillIf backfill selected item the input when using keyboardbooleanfalse
childrenCustomize input elementHTMLInputElement | HTMLTextAreaElement | React.ReactElement<InputProps><Input />
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
dataSourceData source of autocomplete options, please use options insteadDataSourceItemType[]--
defaultActiveFirstOptionWhether active first option by defaultbooleantrue
defaultOpenInitial open state of dropdownboolean-
defaultValueInitial selected optionstring-
disabledWhether disabled selectbooleanfalse
dropdownClassNameThe className of dropdown menu, please use classNames.popup.root insteadstring--
dropdownMatchSelectWidthDetermine whether the dropdown menu and the input are the same width, please use popupMatchSelectWidth insteadboolean | numbertrue-
dropdownRenderCustomize dropdown content, use popupRender instead(originNode: ReactNode) => ReactNode-4.24.0
popupRenderCustomize dropdown content(originNode: ReactNode) => ReactNode-
dropdownStyleThe style of dropdown menu, use styles.popup.root insteadCSSProperties-
popupClassNameThe className of dropdown menu, use classNames.popup.root insteadstring-4.23.0
popupMatchSelectWidthDetermine whether the dropdown menu and the select input are the same width. Default set min-width same as input. Will ignore when value less than select width. false will disable virtual scrollboolean | numbertrue
filterOptionIf true, filter options by input, if function, filter options against it. The function will receive two arguments, inputValue and option, if the function returns true, the option will be included in the filtered set; Otherwise, it will be excludedboolean | function(inputValue, option)true
getPopupContainerParent node of the dropdown. Default to body, if you encountered positioning problems during scroll, try changing to the scrollable area and position relative to it. Examplefunction(triggerNode)() => document.body
notFoundContentSpecify content to show when no result matchesReactNode-
openControlled open state of dropdownboolean-
optionsSelect options. Will get better perf than jsx definition{ label, value }[]-
placeholderThe placeholder of inputstring-
showSearchsearch for configurationtrue | Objecttrue
statusSet validation status'error' | 'warning'-4.19.0
sizeThe size of the input boxlarge | medium | small-
valueSelected optionstring-
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
variantVariants of inputoutlined | borderless | filled | underlinedoutlined5.13.0
virtualDisable virtual scroll when set to falsebooleantrue4.1.0
onBlurCalled when leaving the componentfunction()-
onChangeCalled when selecting an option or changing an input valuefunction(value)-
onDropdownVisibleChangeCalled when dropdown open, use onOpenChange instead(open: boolean) => void-
onOpenChangeCalled when dropdown open(open: boolean) => void-
onFocusCalled when entering the componentfunction()-
onSearchCalled when searching itemsfunction(value)-
onSelectCalled when a option is selected. param is option's value and option instancefunction(value, option)-
onClearCalled when clearfunction-4.6.0
onInputKeyDownCalled when key pressed(event: KeyboardEvent) => void-
onPopupScrollCalled when dropdown scrolls(event: UIEvent) => void-

showSearch

PropertyDescriptionTypeDefaultVersion
filterOptionIf true, filter options by input, if function, filter options against it. The function will receive two arguments, inputValue and option, if the function returns true, the option will be included in the filtered set; Otherwise, it will be excludedboolean | function(inputValue, option)true
onSearchCalled when searching itemsfunction(value)-

Methods

NameDescriptionVersion
blur()Remove focus
focus()Get focus

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
activeBorderColorActive border colorstring#1677ff
activeOutlineColorActive outline colorstringrgba(5,145,255,0.1)
clearBgBackground color of clear buttonstring#ffffff
hoverBorderColorHover border colorstring#4096ff
multipleItemBgBackground color of multiple tagstringrgba(0,0,0,0.06)
multipleItemBorderColorBorder color of multiple tagstringtransparent
multipleItemBorderColorDisabledBorder color of multiple tag when disabledstringtransparent
multipleItemColorDisabledText color of multiple tag when disabledstringrgba(0,0,0,0.25)
multipleItemHeightHeight of multiple tagnumber24
multipleItemHeightLGHeight of multiple tag with large sizenumber32
multipleItemHeightSMHeight of multiple tag with small sizenumber16
multipleSelectorBgDisabledBackground color of multiple selector when disabledstringrgba(0,0,0,0.04)
optionActiveBgBackground color when option is activestringrgba(0,0,0,0.04)
optionFontSizeFont size of optionnumber14
optionHeightHeight of optionnumber32
optionLineHeightLine height of optionLineHeight<string | number> | undefined1.5714285714285714
optionPaddingPadding of optionPadding<string | number> | undefined5px 12px
optionSelectedBgBackground color when option is selectedstring#e6f4ff
optionSelectedColorText color when option is selectedstringrgba(0,0,0,0.88)
optionSelectedFontWeightFont weight when option is selectedFontWeight | undefined600
selectorBgBackground color of selectorstring#ffffff
showArrowPaddingInlineEndInline end padding of arrownumber18
singleItemHeightLGHeight of single selected item with large sizenumber40
zIndexPopupz-index of dropdownnumber1050
Global TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgBaseUsed to derive the base variable of the background color gradient. In v5, we added a layer of background color derivation algorithm to produce map token of background color. But PLEASE DO NOT USE this Seed Token directly in the code!string#fff
colorBgContainerContainer background color, e.g: default button, input box, etc. Be sure not to confuse this with `colorBgElevated`.string#ffffff
colorBgContainerDisabledControl the background color of container in disabled state.stringrgba(0,0,0,0.04)
colorBgElevatedContainer background color of the popup layer, in dark mode the color value of this token will be a little brighter than `colorBgContainer`. E.g: modal, pop-up, menu, etc.string#ffffff
colorBorderDefault border color, used to separate different elements, such as: form separator, card separator, etc.string#d9d9d9
colorBorderDisabledControl the border color of the element in the disabled state.string#d9d9d9
colorErrorUsed to represent the visual elements of the operation failure, such as the error Button, error Result component, etc.string#ff4d4f
colorErrorAffixControl the color of form control prefix/suffix in error state.string#ff4d4f
colorErrorBgThe background color of the error state.string#fff2f0
colorErrorBgHoverThe hover state background color of the error state.string#fff1f0
colorErrorBorderHoverThe hover state border color of the error state.string#ffa39e
colorErrorOutlineControl the outline color of input component in error state.stringrgba(255,38,5,0.06)
colorErrorTextThe default state of the text in the error color.string#ff4d4f
colorFillSecondaryThe second level of fill color can outline the shape of the element more clearly, such as Rate, Skeleton, etc. It can also be used as the Hover state of the third level of fill color, such as Table, etc.stringrgba(0,0,0,0.06)
colorFillTertiaryThe third level of fill color is used to outline the shape of the element, such as Slider, Segmented, etc. If there is no emphasis requirement, it is recommended to use the third level of fill color as the default fill color.stringrgba(0,0,0,0.04)
colorIconWeak action. Such as `allowClear` or Alert close buttonstringrgba(0,0,0,0.45)
colorIconHoverWeak action hover color. Such as `allowClear` or Alert close buttonstringrgba(0,0,0,0.88)
colorPrimaryBrand color is one of the most direct visual elements to reflect the characteristics and communication of the product. After you have selected the brand color, we will automatically generate a complete color palette and assign it effective design semantics.string#1677ff
colorSplitUsed as the color of separator, this color is the same as colorBorderSecondary but with transparency.stringrgba(5,5,5,0.06)
colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
colorTextDescriptionControl the font color of text description.stringrgba(0,0,0,0.45)
colorTextDisabledControl the color of text in disabled state.stringrgba(0,0,0,0.25)
colorTextPlaceholderControl the color of placeholder text.stringrgba(0,0,0,0.25)
colorTextQuaternaryThe fourth level of text color is the lightest text color, such as form input prompt text, disabled color text, etc.stringrgba(0,0,0,0.25)
colorWarningUsed to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens.string#faad14
colorWarningAffixControl the color of form control prefix/suffix in warning state.string#faad14
colorWarningBgThe background color of the warning state.string#fffbe6
colorWarningBgHoverThe hover state background color of the warning state.string#fff1b8
colorWarningHoverThe hover state of the warning color.string#ffd666
colorWarningOutlineControl the outline color of input component in warning state.stringrgba(255,215,5,0.1)
borderRadiusBorder radius of base componentsnumber6
borderRadiusLGLG size border radius, used in some large border radius components, such as Card, Modal and other components.number8
borderRadiusSMSM size border radius, used in small size components, such as Button, Input, Select and other input components in small sizenumber4
borderRadiusXSXS size border radius, used in some small border radius components, such as Segmented, Arrow and other components with small border radius.number2
boxShadowSecondaryControl the secondary box shadow style of an element.string 0 6px 16px 0 rgba(0,0,0,0.08), 0 3px 6px -4px rgba(0,0,0,0.12), 0 9px 28px 8px rgba(0,0,0,0.05)
controlHeightThe height of the basic controls such as buttons and input boxes in Ant Designnumber32
controlHeightLGLG component heightnumber40
controlHeightSMSM component heightnumber24
controlItemBgActiveHoverControl the background color of control component item when hovering and active.string#bae0ff
controlOutlineWidthControl the outline width of input component.number2
controlPaddingHorizontalControl the horizontal padding of an element.number12
fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
fontSizeIconControl the font size of operation icon in Select, Cascader, etc. Normally same as fontSizeSM.number12
fontSizeLGLarge font sizenumber16
fontSizeSMSmall font sizenumber12
lineHeightLine height of text.number1.5714285714285714
lineHeightLGLine height of large text.number1.5
lineTypeBorder style of base componentsstringsolid
lineWidthBorder width of base componentsnumber1
marginXSControl the margin of an element, with a small size.number8
motionDurationMidMotion speed, medium speed. Used for medium element animation interaction.string0.2s
motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
motionEaseInOutPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.645, 0.045, 0.355, 1)External Link Icon
motionEaseInOutCircPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.78, 0.14, 0.15, 0.86)External Link Icon
motionEaseInQuintPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.755, 0.05, 0.855, 0.06)External Link Icon
motionEaseOutCircPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.08, 0.82, 0.17, 1)External Link Icon
motionEaseOutQuintPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.23, 1, 0.32, 1)External Link Icon
paddingSMControl the small padding of the element.number12
paddingXSControl the extra small padding of the element.number8
paddingXXSControl the extra extra small padding of the element.number4

FAQ

Why doesn't the text composition system work well with onSearch in controlled mode?

Please use onChange to manage control state. onSearch is used for searching input which is not the same as onChange. Besides, clicking on the option will not trigger the onSearch event.

Related issue: #18230 #17916

Why won't a controlled open AutoComplete display a drop-down menu when options are empty?

The AutoComplete component is essentially an extension of the Input form element. When the options property is empty, displaying empty text could mislead the user into believing the component is not operational, when in fact they are still able to input text. To avoid confusion, the open property will not display the drop-down menu when set to true and in combination with an empty options property. The open property must be used in conjunction with the options property.

Basic Usage

Basic Usage, set data source of autocomplete with options property.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customize Input Component

Customize Input Component

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Lookup-Patterns - Certain Category

Demonstration of Lookup Patterns: Certain Category. Basic Usage, set options of autocomplete with options property.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Status

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

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customize clear button

Customize clear button

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customized

You could set custom Option label

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Non-case-sensitive AutoComplete

A non-case-sensitive AutoComplete

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Lookup-Patterns - Uncertain Category

Demonstration of Lookup Patterns: Uncertain Category.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Variants

There are outlined, filled, borderless, and underlined variants to choose from.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
5.13.0
Custom semantic dom styling

You can customize the semantic dom style of AutoComplete by passing objects/functions through classNames and styles.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
input here


control mode
UnClearable


Customized clear icon
input here
try to type `b`
Outlined
Filled
Borderless
Underlined
object styles
function styles
prefix
Please select
  • root
    Root element with relative positioning, inline-flex layout, cursor styles, transitions, border and other basic selector container styles
  • prefix
    Prefix element with layout and styling for prefix content
  • content
    Multiple selection container with layout, spacing, and wrapping styles for selected items
  • placeholder
    Placeholder element with font styles and colors for placeholder text
  • clear
    Clear button element with layout, styling and interactive effects for clear button
  • input
    Input element with search input styling, cursor control, font inheritance and other search-related styles. Remove border styles
  • popup.root
    Popup element with popup layer positioning, z-index, background, border, box-shadow and other popup container styles
  • popup.list
    Popup list element with option list layout, scrolling, max-height and other list container styles
  • popup.listItem
    Popup item element with option item padding, hover effects, selected states, disabled states and other option interactive styles