logoAnt Design X

DesignDevelopmentComponentsX SDKX MarkdownPlayground
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
  • Confirmation
    • Think
    • ThoughtChain
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
  • Tools
    • useXAgent
    • useXChat
    • XStream
    • XRequest
    • XProvider

Sender

A input component for chat.
Importimport { Sender } from "@ant-design/x";
Sourcecomponents/sender
Docs
Edit this pageChangelog

Resources

Ant Design
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

  • Need to build an input box for a dialogue scenario

Examples

API

Common props ref:Common props

SenderProps

PropertyDescriptionTypeDefaultVersion
allowSpeechWhether to allow speech inputboolean | SpeechConfigfalse-
classNamesClass nameSee below--
componentsCustom componentsRecord<'input', ComponentType>--
defaultValueDefault value of inputstring--
disabledWhether to disablebooleanfalse-
loadingWhether it is loadingbooleanfalse-
suffixSuffix content, shows action buttons by default. Set suffix={false} to hide default actions.React.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | falseoriNode-
headerHeader panelReact.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | falsefalse-
prefixPrefix contentReact.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | falsefalse-
footerFooter contentReact.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | falsefalse-
readOnlyWhether to make the input box read-onlybooleanfalse-
rootClassNameRoot element class namestring--
stylesSemantic DOM styleSee below--
submitTypeSubmit typeSubmitTypeenter | shiftEnter-
valueInput valuestring--
onSubmitCallback when click send button(message: string, slotConfig?: SlotConfigType[]) => void--
onChangeCallback when input value changes(value: string, event?: React.FormEvent<HTMLTextAreaElement> | React.ChangeEvent<HTMLTextAreaElement>, slotConfig?: SlotConfigType[]) => void--
onCancelCallback when click cancel button() => void--
onPasteFileCallback when paste files(firstFile: File, files: FileList) => void--
autoSizeHeight auto size feature, can be set to true | false or an object: { minRows: 2, maxRows: 6 }boolean | { minRows?: number; maxRows?: number }{ maxRows: 8 }-
initialSlotConfigSlot configuration, after configuration, the input box will become slot mode, supporting structured input. In this mode, value and defaultValue are invalid.SlotConfigType[]--
typescript
type SpeechConfig = {
// When setting `recording`, the built-in speech input function will be disabled.
// It is up to the developer to implement the third-party speech input function.
recording?: boolean;
onRecordingChange?: (recording: boolean) => void;
};
typescript
type ActionsComponents = {
SendButton: React.ComponentType<ButtonProps>;
ClearButton: React.ComponentType<ButtonProps>;
LoadingButton: React.ComponentType<ButtonProps>;
SpeechButton: React.ComponentType<ButtonProps>;
};

Sender Ref

PropertyDescriptionTypeDefaultVersion
nativeElementOuter containerHTMLDivElement--
focusSet focus(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' })--
blurRemove focus() => void--
insertInsert text or slot(s). When using slot(s), make sure initialSlotConfig is set.(value: string) => void | (slotConfig: SlotConfigType[], position?: insertPosition) => void;--
clearClear content() => void--
getValueGet current content and structured configuration() => { value: string; config: SlotConfigType[] }--

SlotConfigType

PropertyDescriptionTypeDefaultVersion
typeNode type, determines the rendering component type, required'text' | 'input' | 'select' | 'tag' | 'custom'--
keyUnique identifier, can be omitted when type is textstring--
formatResultFormat final result(value: any) => string--
text node properties
PropertyDescriptionTypeDefaultVersion
textText contentstring--
input node properties
PropertyDescriptionTypeDefaultVersion
props.placeholderPlaceholderstring--
props.defaultValueDefault valuestring | number | readonly string[]--
select node properties
PropertyDescriptionTypeDefaultVersion
props.optionsOptions array, requiredstring[]--
props.placeholderPlaceholderstring--
props.defaultValueDefault valuestring--
tag node properties
PropertyDescriptionTypeDefaultVersion
props.labelTag content, requiredReactNode--
props.valueTag valuestring--
custom node properties
PropertyDescriptionTypeDefaultVersion
props.defaultValueDefault valueany--
customRenderCustom render function(value: any, onChange: (value: any) => void, item: SlotConfigType) => React.ReactNode--

Sender.Header

PropertyDescriptionTypeDefaultVersion
childrenPanel contentReactNode--
classNamesClass nameSee below--
closableWhether the panel can be closedbooleantrue-
forceRenderForce render, use when need ref internal elements on initbooleanfalse-
openWhether to expandboolean--
stylesSemantic DOM styleSee below--
titleTitle contentReactNode--
onOpenChangeCallback when the expansion state changes(open: boolean) => void--

Sender.Switch

PropertyDescriptionTypeDefaultVersion
childrenGeneral contentReactNode--
checkedChildrenContent when checkedReactNode--
unCheckedChildrenContent when uncheckedReactNode--
iconSet icon componentReactNode--
disabledWhether disabledbooleanfalse-
loadingLoading stateboolean--
valueSwitch valuebooleanfalse-
onChangeCallback when changedfunction(checked: boolean)--
rootClassNameRoot element class namestring--

⚠️ Notes for Slot Mode

  • In slot mode, the value and defaultValue properties are invalid. Please use ref and callback events to get the value and slotConfig.
  • In slot mode, the third parameter config of the onChange/onSubmit callback is only used to get the current structured content. Do not assign it directly back to slotConfig, otherwise the input box content will be reset. Only update slotConfig when you need to switch or reset the slot structure as a whole.
  • Usually, initialSlotConfig should only be set once during initialization or when the structure changes. If you need to force re-render the component, use a different key prop.

Example:

jsx
// ❌ Wrong usage (initialSlotConfig is for initialization only)
<Sender
initialSlotConfig={config}
onChange={(value, e, config) => {
setConfig(config);
}}
/>
// ✅ Correct usage
<Sender
key={key}
initialSlotConfig={config}
onChange={(value, _e, config) => {
// Only used to get structured content, use key to force re-render
setKey('new_key');
console.log(value, config);
}}
/>

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgSlotSlot background colorstringrgba(22,119,255,0.06)
colorBorderInputInput border colorstringrgba(0,0,0,0.1)
colorBorderSlotSlot border colorstringrgba(22,119,255,0.06)
colorBorderSlotHoverSlot border hover colorstringrgba(22,119,255,0.1)
colorTextSlotSlot text colorstring#1677ff
colorTextSlotPlaceholderSlot text placeholder colorstringrgba(22,119,255,0.25)
switchCheckedBgSwitch checked background colostringrgba(22,119,255,0.08)
switchCheckedHoverBgSwitch checked hover background colorstringrgba(22,119,255,0.1)
switchUncheckedHoverBgSwitch unchecked hover background colorstringrgba(0,0,0,0.04)
Global TokenHow to use?
Agent Sender

Agent input box.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Basic Usage

Basic usage. State management in controlled.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Feature Switch

Feature switch, used to enable/disable features of Sender.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Slot Mode

Provide slots and dropdown selections in the input to improve user input efficiency and accuracy.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Instance Methods

Use the ref option to control focus, text insertion, and more.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Submit Type

Control the newline and submit mode through submitType.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Speech Input

Speech input requires user permission to access the microphone.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Speech Input

Customize the voice logic to achieve the voice recognition function of calling a third-party library.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Suffix

Customize the behavior of the send button through the actions property.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Expandable Panel

Use header to customize the file upload example.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Reference

Use header to do the reference effect.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Footer

Use footer to customize the footer content.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Adjust Style

Adjust actions by customizing the suffix.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Paste Files

Use onPasteFile to get pasted files, and upload them with Attachments.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Attachments
Default:
Custom checked/unchecked content:
Disabled:
Loading:
DefaultValue:
Controlled mode:
`Shift + Enter` to submit
"Tell more about Ant Design X"
Deep Thinking
Attachments
Upload files
Click or drag files to this area to upload
Deep thinking can understand the intent behind.
  • root
    Root
  • prefix
    Prefix
  • input
    Input
  • suffix
    Suffix
  • footer
    Footer
  • switch
    Switch
Header
Content
  • header
    Header
  • content
    Content