logoAnt Design X

设计研发组件演示
  • 总览
  • 通用
    • Bubble对话气泡
    • Conversations管理对话
  • 唤醒
    • Welcome欢迎
    • Prompts提示集
  • 表达
    • Attachments输入附件
    • Sender输入框
    • Suggestion快捷指令
  • 确认
    • ThoughtChain思维链
  • 工具
    • useXAgent模型调度
    • useXChat数据管理
    • XStream流
    • XRequest请求
    • XProvider全局化配置

Sender
输入框

用于聊天的输入框组件。
使用import { Sender } from "@ant-design/x";
源码components/sender
文档
编辑此页更新日志

相关资源

Ant Design
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-首页模板集
Scaffolds-脚手架市场
Umi-React 应用开发框架
dumi-组件/文档研发工具
qiankun-微前端框架
Ant Motion-设计动效
国内镜像站点 🇨🇳

社区

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconf logoSEE Conf-蚂蚁体验科技大会
加入我们

帮助

GitHub
更新日志
常见问题
报告 Bug
议题
讨论区
StackOverflow
SegmentFault

Ant XTech logo更多产品

yuque logo语雀-构建你的数字花园
AntV logoAntV-数据可视化解决方案
Egg logoEgg-企业级 Node.js 框架
Kitchen logoKitchen-Sketch 工具集
Galacean logoGalacean-互动图形解决方案
xtech logo蚂蚁体验科技
主题编辑器
Made with ❤ by
蚂蚁集团和 Ant Design 开源社区
loading

何时使用

  • 需要构建一个对话场景下的输入框

代码演示

基本用法

基础用法,受控进行状态管理。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
提交模式

通过 submitType 控制换行与提交模式。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
语音输入

语音输入,需要用户同意麦克风权限。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
自定义语音输入

自定义语音逻辑,从而实现调用三方库的语音识别功能。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
`Shift + Enter` to submit
自定义按钮

通过 actions 属性,可以自定义发送按钮的行为。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
展开面板

使用 header 自定义文件上传示例。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
"Tell more about Ant Design X"
引用

使用 header 做引用效果。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Deep Thinking
自定义底部内容

使用 footer 自定义底部内容。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
调整样式

通过 actions 属性,调整默认样式。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Attachments
Upload files
Click or drag files to this area to upload
黏贴文件

使用 onPasteFile 获取黏贴的文件,配合 Attachments 进行文件上传。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
聚焦

使用 ref 选项控制聚焦。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

通用属性参考:通用属性

SenderProps

属性说明类型默认值版本
actions自定义按钮,当不需要默认操作按钮时,可以设为 actions={false}ReactNode | (oriNode, info: { components: ActionsComponents }) => ReactNode--
allowSpeech是否允许语音输入boolean | SpeechConfigfalse-
classNames样式类名见下--
components自定义组件Record<'input', ComponentType>--
defaultValue输入框默认值string--
disabled是否禁用booleanfalse-
loading是否加载中booleanfalse-
header头部面板ReactNode--
prefix前缀内容ReactNode--
footer底部内容ReactNode | (info: { components: ActionsComponents }) => ReactNode--
readOnly是否让输入框只读booleanfalse-
rootClassName根元素样式类string--
styles语义化定义样式见下--
submitType提交模式SubmitTypeenter | shiftEnter-
value输入框值string--
onSubmit点击发送按钮的回调(message: string) => void--
onChange输入框值改变的回调(value: string, event?: React.FormEvent<HTMLTextAreaElement> | React.ChangeEvent<HTMLTextAreaElement> ) => void--
onCancel点击取消按钮的回调() => void--
onPasteFile黏贴文件的回调(firstFile: File, files: FileList) => void--
autoSize自适应内容高度,可设置为 true | false 或对象:{ minRows: 2, maxRows: 6 }boolean | { minRows?: number; maxRows?: number }{ maxRows: 8 }-
typescript
type SpeechConfig = {
// 当设置 `recording` 时,内置的语音输入功能将会被禁用。
// 交由开发者实现三方语音输入的功能。
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

属性说明类型默认值版本
nativeElement外层容器HTMLDivElement--
focus获取焦点(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' })--
blur取消焦点() => void--

Sender.Header

属性说明类型默认值版本
children面板内容ReactNode--
closable是否可关闭booleantrue-
forceRender强制渲染,在初始化便需要 ref 内部元素时使用booleanfalse-
open是否展开boolean--
title标题ReactNode--
onOpenChange展开状态改变的回调(open: boolean) => void--

Semantic DOM

Deep thinking can understand the intent behind.
  • prefix
    前缀
  • input
    输入框
  • actions
    操作列表
  • footer
    底部
Header
Content
  • header
    头部
  • content
    内容

主题变量(Design Token)