Participate in the WeaveFox "AI Artist" contest to win SEE Conf tickets and thousands of prizes

logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Confirmation
    • Sources
    • Think
    • ThoughtChain
  • Feedback
    • Actions
    • FileCard
  • Others
    • XProvider

Sender

An input box component used for chat.
Importimport { Sender } from "@ant-design/x";
Sourcecomponents/sender
Docs
Edit this page...
Changelog
loading

When To Use

  • When you need to build an input box for chat scenarios

Code Examples

API

Common props ref:Common props

SenderProps

PropertyDescriptionTypeDefaultVersion
allowSpeechWhether to allow voice inputboolean | SpeechConfigfalse-
classNamesStyle class namesSee below--
componentsCustom componentsRecord<'input', ComponentType>--
defaultValueDefault value of the input boxstring--
disabledWhether to disablebooleanfalse-
loadingWhether in loading statebooleanfalse-
suffixSuffix content, displays action buttons by default. When you don't need the default action buttons, you can set suffix={false}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 style classstring--
stylesSemantic style definitionSee below--
submitTypeSubmission modeSubmitTypeenter | shiftEnter-
valueInput box valuestring--
onSubmitCallback for clicking the send button(message: string, slotConfig?: SlotConfigType[]) => void--
onChangeCallback for input box value change(value: string, event?: React.FormEvent<HTMLTextAreaElement> | React.ChangeEvent<HTMLTextAreaElement>, slotConfig?: SlotConfigType[]) => void--
onCancelCallback for clicking the cancel button() => void--
onPasteFileCallback for pasting files(files: FileList) => void--
autoSizeAuto-adjust content height, can be set to true | false or object: { minRows: 2, maxRows: 6 }boolean | { minRows?: number; maxRows?: number }{ maxRows: 8 }-
slotConfigSlot configuration, after configuration the input box will switch to slot mode, supporting structured input. In this mode, value and defaultValue configurations will be invalid.SlotConfigType[]--
typescript
type SpeechConfig = {
// When `recording` is set, the built-in voice input feature will be disabled.
// Developers need to implement third-party voice input functionality.
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--
focusGet focus, when cursor = 'slot' the focus will be in the first slot of type input, if no corresponding input exists it will behave the same as end(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' | 'slot' })--
blurRemove focus() => void--
insertInsert text or slots, when using slots ensure slotConfig is configured(value: string) => void | (slotConfig: SlotConfigType[], position?: insertPosition, replaceCharacters?: string) => 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 the 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 rendering function(value: any, onChange: (value: any) => void, props: { disabled?: boolean, readOnly?: boolean }, item: SlotConfigType) => React.ReactNode--

Sender.Header

PropertyDescriptionTypeDefaultVersion
childrenPanel contentReactNode--
classNamesStyle class namesSee below--
closableWhether it can be closedbooleantrue-
forceRenderForce rendering, use when you need to reference internal elements during initializationbooleanfalse-
openWhether to expandboolean--
stylesSemantic style definitionSee below--
titleTitleReactNode--
onOpenChangeCallback for expansion state change(open: boolean) => void--

Sender.Switch

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

⚠️ Slot Mode Notes

  • In slot mode, value and defaultValue properties are invalid, please use ref and callback events to get the input box value and slot configuration.
  • In slot mode, the third parameter config of onChange/onSubmit callbacks is only used to get the current structured content.

Example:

jsx
// ❌ Incorrect usage, slotConfig is for uncontrolled usage
const [config, setConfig] = useState([]);
<Sender
slotConfig={config}
onChange={(value, e, config) => {
setConfig(config);
}}
/>
// ✅ Correct usage
<Sender
key={key}
slotConfig={config}
onChange={(value, _e, config) => {
// Only used to get structured content
setKey('new_key')
}}
/>

Semantic DOM

Theme Variables (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 Input

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 Toggle

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 Methods

Control the newline and submit mode through submitType.

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

Speech input requires user permission to access the microphone.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Voice 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
Expand Panel

Use header to customize the file upload example.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Quick Commands

Agent input box with quick commands and suggestions, type @ to trigger quick commands.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
References

Use header to do the reference effect.

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

Use footer to customize the footer content.

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

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
Attachments
"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
  • content
    Content
Header
Content
  • header
    Header
  • content
    Header Content