# Ant Design Component Documentation This file contains aggregated content from all component docs. > Total 73 components ## _util Source: https://ant.design/components/_util.md --- category: Components title: Util description: Utilities are used to assist development and provide some common utility methods. showImport: false cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rRDlT7ST8DUAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rRDlT7ST8DUAAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 group: title: Other order: 99 --- Available since `5.13.0`. ## GetRef Get the `ref` property definition of the component, which is very useful for components that are not directly exposed or child components. ```tsx import { Select } from 'antd'; import type { GetRef } from 'antd'; type SelectRefType = GetRef; // BaseSelectRef ``` ## GetProps Get the `props` property definition of the component: ```tsx import { Checkbox } from 'antd'; import type { GetProps } from 'antd'; type CheckboxGroupType = GetProps; ``` Also supports getting the property definition of Context: ```tsx import type { GetProps } from 'antd'; interface InternalContextProps { name: string; } const Context = React.createContext({ name: 'Ant Design' }); type ContextType = GetProps; // InternalContextProps ``` ## GetProp Get the single `props` or `context` property definition of the component. It has encapsulated `NonNullable`, so you don't have to worry about it being empty: ```tsx import { Select } from 'antd'; import type { GetProp, SelectProps } from 'antd'; // Both of these can work type SelectOptionType1 = GetProp[number]; type SelectOptionType2 = GetProp[number]; type ContextOptionType = GetProp; ``` --- ## affix Source: https://ant.design/components/affix.md --- category: Components title: Affix description: Stick an element to the viewport. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*YSm4RI3iOJ8AAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*03dxS64LxeQAAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 group: title: Other order: 7 --- ## When To Use On longer web pages, it's helpful to stick component into the viewport. This is common for menus and actions. Please note that Affix should not cover other content on the page, especially when the size of the viewport is small. > Notes for developers > > After version `5.10.0`, we rewrite Affix use FC, Some methods of obtaining `ref` and calling internal instance methods will be invalid. ## Examples ### Basic The simplest usage. ```tsx import React from 'react'; import { Affix, Button } from 'antd'; const App: React.FC = () => { const [top, setTop] = React.useState(100); const [bottom, setBottom] = React.useState(100); return ( <>
); }; export default App; ``` ### Callback Callback with affixed state. ```tsx import React from 'react'; import { Affix, Button } from 'antd'; const App: React.FC = () => ( console.log(affixed)}> ); export default App; ``` ### Container to scroll. Set a `target` for 'Affix', which is listen to scroll event of target element (default is `window`). ```tsx import React from 'react'; import { Affix, Button } from 'antd'; const containerStyle: React.CSSProperties = { width: '100%', height: 100, overflow: 'auto', boxShadow: '0 0 0 1px #1677ff', scrollbarWidth: 'thin', scrollbarGutter: 'stable', }; const style: React.CSSProperties = { width: '100%', height: 1000, }; const App: React.FC = () => { const [container, setContainer] = React.useState(null); return (
container}>
); }; export default App; ``` ## API Common props ref:[Common props](/docs/react/common-props) | Property | Description | Type | Default | | --- | --- | --- | --- | | offsetBottom | Offset from the bottom of the viewport (in pixels) | number | - | | offsetTop | Offset from the top of the viewport (in pixels) | number | 0 | | target | Specifies the scrollable area DOM node | () => HTMLElement | () => window | | onChange | Callback for when Affix state is changed | (affixed?: boolean) => void | - | **Note:** Children of `Affix` must not have the property `position: absolute`, but you can set `position: absolute` on `Affix` itself: ```jsx ... ``` ## FAQ ### When binding container with `target` in Affix, elements sometimes move out of the container. {#faq-target-container} We only listen to container scroll events for performance consideration. You can add custom listeners if you still want to: Related issues:[#3938](https://github.com/ant-design/ant-design/issues/3938) [#5642](https://github.com/ant-design/ant-design/issues/5642) [#16120](https://github.com/ant-design/ant-design/issues/16120) ### When Affix is ​​used in a horizontal scroll container, the position of the element `left` is incorrect. {#faq-horizontal-scroll} Affix is ​​generally only applicable to areas with one-way scrolling, and only supports usage in vertical scrolling containers. If you want to use it in a horizontal container, you can consider implementing with the native `position: sticky` property. Related issues:[#29108](https://github.com/ant-design/ant-design/issues/29108) --- ## alert Source: https://ant.design/components/alert.md --- category: Components title: Alert description: Display warning messages that require attention. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*QsvtS41m45UAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*gOTISoMFZV0AAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 group: title: Feedback order: 6 --- ## When To Use - When you need to show alert messages to users. - When you need a persistent static container which is closable by user actions. ## Examples ### Basic The simplest usage for short messages. ```tsx import React from 'react'; import { Alert } from 'antd'; const App: React.FC = () => ; export default App; ``` ### More types There are 4 types of Alert: `success`, `info`, `warning`, `error`. ```tsx import React from 'react'; import { Alert } from 'antd'; const App: React.FC = () => ( <>


); export default App; ``` ### Closable To show close button. ```tsx import React from 'react'; import { Alert } from 'antd'; const onClose: React.MouseEventHandler = (e) => { console.log(e, 'I was closed.'); }; const App: React.FC = () => ( <>


); export default App; ``` ### Description Additional description for alert message. ```tsx import React from 'react'; import { Alert } from 'antd'; const App: React.FC = () => ( <>


); export default App; ``` ### Icon A relevant icon will make information clearer and more friendly. ```tsx import React from 'react'; import { Alert } from 'antd'; const App: React.FC = () => ( <>






); export default App; ``` ### Banner Display Alert as a banner at top of page. ```tsx import React from 'react'; import { Alert } from 'antd'; const App: React.FC = () => ( <>


); export default App; ``` ### Loop Banner Show a loop banner by using with [react-text-loop-next](https://npmjs.com/package/react-text-loop-next) or [react-fast-marquee](https://npmjs.com/package/react-fast-marquee). ```tsx import React from 'react'; import { Alert } from 'antd'; import Marquee from 'react-fast-marquee'; const App: React.FC = () => ( I can be a React component, multiple React components, or just some text. } /> ); export default App; ``` ### Smoothly Unmount Smoothly unmount Alert upon close. ```tsx import React, { useState } from 'react'; import { Alert, Switch } from 'antd'; const App: React.FC = () => { const [visible, setVisible] = useState(true); const handleClose = () => { setVisible(false); }; return ( <> {visible && ( )}

click the close button to see the effect

); }; export default App; ``` ### ErrorBoundary ErrorBoundary Component for making error handling easier in [React](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary). ```tsx import React, { useState } from 'react'; import { Alert, Button } from 'antd'; const { ErrorBoundary } = Alert; const ThrowError: React.FC = () => { const [error, setError] = useState(); const onClick = () => { setError(new Error('An Uncaught Error')); }; if (error) { throw error; } return ( ); }; const App: React.FC = () => ( ); export default App; ``` ### Custom action Custom action. ```tsx import React from 'react'; import { Alert, Button, Space } from 'antd'; const App: React.FC = () => ( <> UNDO } closable />
Detail } />
} closable />
} closable /> ); export default App; ``` ### Custom semantic dom styling You can customize the [semantic dom](#semantic-dom) style of Alert by passing objects/functions through `classNames` and `styles`. ```tsx import React from 'react'; import { Alert, Button, Flex } from 'antd'; import type { AlertProps, AlertSemanticType } from 'antd'; import { createStaticStyles } from 'antd-style'; const classNames = createStaticStyles(({ css }) => ({ root: css` border: 2px dashed #ccc; border-radius: 8px; padding: 12px; `, })); const styleFn: AlertProps['styles'] = ({ props: { type } }): AlertSemanticType['styles'] => { if (type === 'success') { return { root: { backgroundColor: 'rgba(82, 196, 26, 0.1)', borderColor: '#b7eb8f', }, icon: { color: '#52c41a', }, }; } if (type === 'warning') { return { root: { backgroundColor: 'rgba(250, 173, 20, 0.1)', borderColor: '#ffe58f', }, icon: { color: '#faad14', }, }; } return {}; }; const App: React.FC = () => { const alertSharedProps: AlertProps = { showIcon: true, classNames: { root: classNames.root, }, }; return ( Action} /> ); }; export default App; ``` ## API Common props ref:[Common props](/docs/react/common-props) | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | action | The action of Alert | ReactNode | - | 4.9.0 | | ~~afterClose~~ | Called when close animation is finished, please use `closable.afterClose` instead | () => void | - | | | banner | Whether to show as banner | boolean | false | | | classNames | Customize class for each semantic structure inside the component. Supports object or function | Record<[SemanticDOM](#semantic-dom), string> \| (info: { props }) => Record<[SemanticDOM](#semantic-dom), string> | - | | | closable | The config of closable, >=5.15.0: support `aria-*` | boolean \| [ClosableType](#closabletype) & React.AriaAttributes | `false` | | | description | Additional content of Alert | ReactNode | - | | | icon | Custom icon, effective when `showIcon` is true | ReactNode | - | | | ~~message~~ | Content of Alert, please use `title` instead | ReactNode | - | | | title | Content of Alert | ReactNode | - | | | showIcon | Whether to show icon | boolean | false, in `banner` mode default is true | | | styles | Customize inline style for each semantic structure inside the component. Supports object or function | Record<[SemanticDOM](#semantic-dom), CSSProperties> \| (info: { props }) => Record<[SemanticDOM](#semantic-dom), CSSProperties> | - | | | type | Type of Alert styles, options: `success`, `info`, `warning`, `error` | string | `info`, in `banner` mode default is `warning` | | | ~~onClose~~ | Callback when Alert is closed, please use `closable.onClose` instead | (e: MouseEvent) => void | - | | ### ClosableType | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | afterClose | Called when close animation is finished | function | - | - | | closeIcon | Custom close icon | ReactNode | - | - | | onClose | Callback when Alert is closed | (e: MouseEvent) => void | - | - | ### Alert.ErrorBoundary | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | description | Custom error description to show | ReactNode | {{ error stack }} | | | ~~message~~ | Custom error message to show, please use `title` instead | ReactNode | {{ error }} | | | title | Custom error title to show | ReactNode | {{ error }} | | ## Semantic DOM https://ant.design/components/alert/semantic.md ## Design Token ## Component Token (Alert) | Token Name | Description | Type | Default Value | | --- | --- | --- | --- | | defaultPadding | Default padding | Padding \| undefined | 8px 12px | | withDescriptionIconSize | Icon size with description | number | 24 | | withDescriptionPadding | Padding with description | Padding \| undefined | 20px 24px | ## Global Token | Token Name | Description | Type | Default Value | | --- | --- | --- | --- | | borderRadiusLG | LG size border radius, used in some large border radius components, such as Card, Modal and other components. | number | | | colorError | Used to represent the visual elements of the operation failure, such as the error Button, error Result component, etc. | string | | | colorErrorBg | The background color of the error state. | string | | | colorErrorBorder | The border color of the error state. | string | | | colorIcon | Weak action. Such as `allowClear` or Alert close button | string | | | colorIconHover | Weak action hover color. Such as `allowClear` or Alert close button | string | | | colorInfo | Used to represent the operation information of the Token sequence, such as Alert, Tag, Progress, and other components use these map tokens. | string | | | colorInfoBg | Light background color of information color. | string | | | colorInfoBorder | Border color of information color. | string | | | colorSuccess | Used to represent the token sequence of operation success, such as Result, Progress and other components will use these map tokens. | string | | | colorSuccessBg | Light background color of success color, used for Tag and Alert success state background color | string | | | colorSuccessBorder | Border color of success color, used for Tag and Alert success state border color | string | | | colorText | Default text color which comply with W3C standards, and this color is also the darkest neutral color. | string | | | colorTextHeading | Control the font color of heading. | string | | | colorWarning | Used to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens. | string | | | colorWarningBg | The background color of the warning state. | string | | | colorWarningBorder | The border color of the warning state. | string | | | fontFamily | The 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 | | | fontSize | The most widely used font size in the design system, from which the text gradient will be derived. | number | | | fontSizeIcon | Control the font size of operation icon in Select, Cascader, etc. Normally same as fontSizeSM. | number | | | fontSizeLG | Large font size | number | | | lineHeight | Line height of text. | number | | | lineType | Border style of base components | string | | | lineWidth | Border width of base components | number | | | marginSM | Control the margin of an element, with a medium-small size. | number | | | marginXS | Control the margin of an element, with a small size. | number | | | motionDurationMid | Motion speed, medium speed. Used for medium element animation interaction. | string | | | motionDurationSlow | Motion speed, slow speed. Used for large element animation interaction. | string | | | motionEaseInOutCirc | Preset motion curve. | string | | --- ## anchor Source: https://ant.design/components/anchor.md --- category: Components title: Anchor description: Hyperlinks to scroll on one page. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*ufP1TLS5VvIAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*_9_eTrgvHNQAAAAAAAAAAAAADrJ8AQ/original demo: group: title: Navigation order: 3 --- ## When To Use For displaying anchor hyperlinks on page and jumping between them. > Notes for developers > > After version `4.24.0`, we rewrite Anchor use FC, Some methods of obtaining `ref` and calling internal instance methods will invalid. ## Examples ### Basic The simplest usage. ```tsx import React from 'react'; import { Anchor, Col, Row } from 'antd'; const App: React.FC = () => (
); export default App; ``` ### Horizontal Anchor Horizontally aligned anchors ```tsx import React from 'react'; import { Anchor } from 'antd'; const App: React.FC = () => ( <>
); export default App; ``` ### Static Anchor Do not change state when page is scrolling. ```tsx import React from 'react'; import { Anchor } from 'antd'; const App: React.FC = () => ( ); export default App; ``` ### Customize the onClick event Clicking on an anchor does not record history. ```tsx import React from 'react'; import { Anchor } from 'antd'; const handleClick = ( e: React.MouseEvent, link: { title: React.ReactNode; href: string; }, ) => { e.preventDefault(); console.log(link); }; const App: React.FC = () => ( ); export default App; ``` ### Customize the anchor highlight Customize the anchor highlight. ```tsx import React from 'react'; import { Anchor } from 'antd'; const getCurrentAnchor = () => '#anchor-demo-static'; const App: React.FC = () => ( ); export default App; ``` ### Set Anchor scroll offset Anchor target scroll to screen center. ```tsx import React, { useEffect, useState } from 'react'; import { Anchor, Col, Row } from 'antd'; const style: React.CSSProperties = { height: '30vh', backgroundColor: 'rgba(0, 0, 0, 0.85)', position: 'fixed', top: 0, insetInlineStart: 0, width: '75%', color: '#fff', }; const App: React.FC = () => { const topRef = React.useRef(null); const [targetOffset, setTargetOffset] = useState(); useEffect(() => { setTargetOffset(topRef.current?.clientHeight); }, []); return (
Part 1
Part 2
Part 3
Fixed Top Block
); }; export default App; ``` ### Listening for anchor link change Listening for anchor link change. ```tsx import React from 'react'; import { Anchor } from 'antd'; const onChange = (link: string) => { console.log('Anchor:OnChange', link); }; const App: React.FC = () => ( ); export default App; ``` ### Replace href in history Replace path in browser history, so back button returns to previous page instead of previous anchor item. ```tsx import React from 'react'; import { Anchor, Col, Row } from 'antd'; const App: React.FC = () => (
); export default App; ``` ### Custom semantic dom styling You can customize the [semantic dom](#semantic-dom) style of Anchor by passing objects/functions through `classNames` and `styles`. ```tsx import React from 'react'; import { Anchor, Col, Row } from 'antd'; import type { AnchorProps } from 'antd'; const classNamesObject: AnchorProps['classNames'] = { root: 'demo-anchor-root', item: 'demo-anchor-item', itemTitle: 'demo-anchor-title', indicator: 'demo-anchor-indicator', }; const stylesFn: AnchorProps['styles'] = (info) => { if (info.props.direction === 'vertical') { return { root: { backgroundColor: 'rgba(255,251,230,0.5)', height: '100vh', }, } satisfies AnchorProps['styles']; } return {}; }; const items: NonNullable = [ { key: 'part-1', href: '#part-1', title: 'Part 1', }, { key: 'part-2', href: '#part-2', title: 'Part 2', }, { key: 'part-3', href: '#part-3', title: 'Part 3', }, ]; const App: React.FC = () => { return (
); }; export default App; ``` ## API Common props ref:[Common props](/docs/react/common-props) ### Anchor Props | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | affix | Fixed mode of Anchor | boolean \| Omit | true | object: 5.19.0 | | bounds | Bounding distance of anchor area | number | 5 | | | classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<[SemanticDOM](#semantic-dom), string> \| (info: { props })=> Record<[SemanticDOM](#semantic-dom), string> | - | | | getContainer | Scrolling container | () => HTMLElement | () => window | | | getCurrentAnchor | Customize the anchor highlight | (activeLink: string) => string | - | | | offsetTop | Pixels to offset from top when calculating position of scroll | number | 0 | | | showInkInFixed | Whether show ink-square when `affix={false}` | boolean | false | | | styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<[SemanticDOM](#semantic-dom), CSSProperties> \| (info: { props })=> Record<[SemanticDOM](#semantic-dom), CSSProperties> | - | | | targetOffset | Anchor scroll offset, default as `offsetTop`, [example](#anchor-demo-targetoffset) | number | - | | | onChange | Listening for anchor link change | (currentActiveLink: string) => void | | | | onClick | Set the handler to handle `click` event | (e: MouseEvent, link: object) => void | - | | | items | Data configuration option content, support nesting through children | { key, href, title, target, children }\[] [see](#anchoritem) | - | 5.1.0 | | direction | Set Anchor direction | `vertical` \| `horizontal` | `vertical` | 5.2.0 | | replace | Replace items' href in browser history instead of pushing it | boolean | false | 5.7.0 | ### AnchorItem | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | key | The unique identifier of the Anchor Link | string \| number | - | | | href | The target of hyperlink | string | | | | target | Specifies where to display the linked URL | string | | | | title | The content of hyperlink | ReactNode | | | | children | Nested Anchor Link, `Attention: This attribute does not support horizontal orientation` | [AnchorItem](#anchoritem)\[] | - | | | replace | Replace item href in browser history instead of pushing it | boolean | false | 5.7.0 | ### Link Props We recommend using the items form instead. | Property | Description | Type | Default | Version | | -------- | ----------------------------------------- | --------- | ------- | ------- | | href | The target of hyperlink | string | | | | target | Specifies where to display the linked URL | string | | | | title | The content of hyperlink | ReactNode | | | ## Semantic DOM https://ant.design/components/anchor/semantic.md ## Design Token ## Component Token (Anchor) | Token Name | Description | Type | Default Value | | --- | --- | --- | --- | | linkPaddingBlock | Vertical padding of link | number | 4 | | linkPaddingInlineStart | Horizontal padding of link | number | 16 | ## Global Token | Token Name | Description | Type | Default Value | | --- | --- | --- | --- | | colorPrimary | Brand 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 | | | colorSplit | Used as the color of separator, this color is the same as colorBorderSecondary but with transparency. | string | | | colorText | Default text color which comply with W3C standards, and this color is also the darkest neutral color. | string | | | fontFamily | The 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 | | | fontSize | The most widely used font size in the design system, from which the text gradient will be derived. | number | | | fontSizeLG | Large font size | number | | | lineHeight | Line height of text. | number | | | lineType | Border style of base components | string | | | lineWidth | Border width of base components | number | | | lineWidthBold | The default line width of the outline class components, such as Button, Input, Select, etc. | number | | | motionDurationSlow | Motion speed, slow speed. Used for large element animation interaction. | string | | | paddingXXS | Control the extra extra small padding of the element. | number | | ## FAQ ### In version `5.25.0+`, the `:target` pseudo-class of the destination element does not take effect as expected after anchor navigation. {#faq-target-pseudo-class} For the purpose of page performance optimization, the implementation of anchor navigation has been changed from `window.location.href` to `window.history.pushState/replaceState`. Since `pushState/replaceState` does not trigger a page reload, the browser will not automatically update the matching state of the `:target` pseudo-class. To resolve this issue, you can manually construct the full URL: `href = window.location.origin + window.location.pathname + '#xxx'`. Related issues: [#53143](https://github.com/ant-design/ant-design/issues/53143) [#54255](https://github.com/ant-design/ant-design/issues/54255) --- ## app Source: https://ant.design/components/app.md --- category: Components group: Other title: App description: Application wrapper for some global usages. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*HJz8SZos2wgAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*oC92TK44Ex8AAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 --- ## When To Use - Provide reset styles based on `.ant-app` element. - You could use static methods of `message/notification/Modal` from `useApp` without writing `contextHolder` manually. ## Examples ### Basic Get instance for `message`, `notification`, `modal`. ```tsx import React from 'react'; import { App, Button, Space } from 'antd'; // Sub page const Page: React.FC = () => { const { message, modal, notification } = App.useApp(); const showMessage = () => { message.success('Success!'); }; const showModal = () => { modal.warning({ title: 'This is a warning message', content: 'some messages...some messages...', }); }; const showNotification = () => { notification.info({ title: 'Notification topLeft', description: 'Hello, Ant Design!!', placement: 'topLeft', }); }; return ( ); }; // Entry component export default () => ( ); ``` ### Hooks config Config for `message`, `notification`. ```tsx import React from 'react'; import { App, Button, Space } from 'antd'; // Sub page const Page: React.FC = () => { const { message, notification } = App.useApp(); const showMessage = () => { message.success('Success!'); }; const showNotification = () => { notification.info({ title: 'Notification', description: 'Hello, Ant Design!!', }); }; return ( ); }; // Entry component export default () => ( ); ``` ## How to use ### Basic usage App provides upstream and downstream method calls through `Context`, because useApp needs to be used as a subcomponent, we recommend encapsulating App at the top level in the application. ```tsx import React from 'react'; import { App } from 'antd'; const MyPage: React.FC = () => { const { message, notification, modal } = App.useApp(); message.success('Good!'); notification.info({ title: 'Good' }); modal.warning({ title: 'Good' }); // .... // other message, notification, modal static function return
Hello word
; }; const MyApp: React.FC = () => ( ); export default MyApp; ``` Note: App.useApp must be available under App. ### Sequence with ConfigProvider The App component can only use the token in the `ConfigProvider`, if you need to use the Token, the ConfigProvider and the App component must appear in pairs. ```tsx ... ``` ### Embedded usage scenarios (if not necessary, try not to do nesting) {#embedded-usage-scenarios} ```tsx ... ... ``` ### Global scene (redux scene) {#global-scene-redux} ```tsx // Entry component import { App } from 'antd'; import type { MessageInstance } from 'antd/es/message/interface'; import type { ModalStaticFunctions } from 'antd/es/modal/confirm'; import type { NotificationInstance } from 'antd/es/notification/interface'; let message: MessageInstance; let notification: NotificationInstance; let modal: Omit; export default () => { const staticFunction = App.useApp(); message = staticFunction.message; modal = staticFunction.modal; notification = staticFunction.notification; return null; }; export { message, modal, notification }; ``` ```tsx // sub page import React from 'react'; import { Button, Space } from 'antd'; import { message } from './store'; export default () => { const showMessage = () => { message.success('Success!'); }; return ( ); }; ``` ## API Common props ref:[Common props](/docs/react/common-props) > This component is available since `antd@5.1.0`. ### App | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | component | Config render element, if `false` will not create DOM node | ComponentType \| false | div | 5.11.0 | | message | Global config for Message | [MessageConfig](/components/message/#messageconfig) | - | 5.3.0 | | notification | Global config for Notification | [NotificationConfig](/components/notification/#notificationconfig) | - | 5.3.0 | ## Design Token ## Global Token | Token Name | Description | Type | Default Value | | --- | --- | --- | --- | | colorText | Default text color which comply with W3C standards, and this color is also the darkest neutral color. | string | | | fontFamily | The 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 | | | fontSize | The most widely used font size in the design system, from which the text gradient will be derived. | number | | | lineHeight | Line height of text. | number | | ## FAQ ### CSS Var doesn't work inside `` {#faq-css-var-component-false} Make sure the App `component` is a valid html tag, so when you're turning on CSS variables, there's a container to hold the CSS class name. If not set, it defaults to the `div` tag. If set to `false`, no additional DOM nodes will be created, and no default styles will be provided. --- ## auto-complete Source: https://ant.design/components/auto-complete.md --- category: Components title: AutoComplete description: Autocomplete function of input field. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*g8THS4NpV6sAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*WERTQ6qvgEYAAAAAAAAAAAAADrJ8AQ/original group: title: Data Entry order: 4 demo: cols: 2 --- ## 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 ### Basic Usage Basic Usage, set data source of autocomplete with `options` property. ```tsx import React, { useState } from 'react'; import { AutoComplete } from 'antd'; import type { AutoCompleteProps } from 'antd'; const mockVal = (str: string, repeat = 1) => ({ value: str.repeat(repeat), }); const App: React.FC = () => { const [value, setValue] = useState(''); const [options, setOptions] = useState([]); const [anotherOptions, setAnotherOptions] = useState([]); const getPanelValue = (searchText: string) => !searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)]; const onSelect = (data: string) => { console.log('onSelect', data); }; const onChange = (data: string) => { setValue(data); }; return ( <> setOptions(getPanelValue(text)), }} placeholder="input here" />

setAnotherOptions(getPanelValue(text)) }} options={anotherOptions} style={{ width: 200 }} onSelect={onSelect} onChange={onChange} placeholder="control mode" /> ); }; export default App; ``` ### Customized You could set custom `Option` label ```tsx import React from 'react'; import { AutoComplete } from 'antd'; import type { AutoCompleteProps } from 'antd'; const App: React.FC = () => { const [options, setOptions] = React.useState([]); const handleSearch = (value: string) => { setOptions(() => { if (!value || value.includes('@')) { return []; } return ['gmail.com', '163.com', 'qq.com'].map((domain) => ({ label: `${value}@${domain}`, value: `${value}@${domain}`, })); }); }; return ( ); }; export default App; ``` ### Customize Input Component Customize Input Component ```tsx import React, { useState } from 'react'; import { AutoComplete, Input } from 'antd'; import type { AutoCompleteProps } from 'antd'; const { TextArea } = Input; const App: React.FC = () => { const [options, setOptions] = useState([]); const handleSearch = (value: string) => { setOptions( !value ? [] : [{ value }, { value: value + value }, { value: value + value + value }], ); }; const handleKeyPress = (ev: React.KeyboardEvent) => { console.log('handleKeyPress', ev); }; const onSelect = (value: string) => { console.log('onSelect', value); }; return (