Skip to content

Sender 输入框

用于聊天的输入框组件。

何时使用

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

代码演示

基本用法

基础用法,受控进行状态管理。自定义触发器。

提交用法

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

语音输入

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

自定义语音输入

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

自定义按钮

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

`Shift + Enter` to submit

展开面板

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

引用

使用 header 做引用效果。

"Tell more about Ant Design X"

自定义底部内容

使用 footer 自定义底部内容。

调整样式

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

黏贴文件

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

聚焦

使用 ref 选项控制聚焦。

API

SenderProps

属性说明类型默认值版本
actions自定义按钮,当不需要默认操作按钮时,可以设为 actions={false}VNode | (oriNode, info: { components: ActionsComponents }) => VNode--
allowSpeech是否允许语音输入boolean | SpeechConfigfalse-
classNames样式类名见下--
components自定义组件Record<'input', ComponentType>--
defaultValue输入框默认值string--
disabled是否禁用booleanfalse-
loading是否加载中booleanfalse-
header头部面板VNode--
prefix前缀内容VNode--
footer底部内容ReactNode | (info: { components: ActionsComponents }) => ReactNode--
readOnly是否让输入框只读booleanfalse-
rootClassName根元素样式类string--
styles语义化定义样式见下--
submitType提交模式SubmitTypeenter | shiftEnter-
value(v-model)输入框值string--
onSubmit点击发送按钮的回调(message: string) => void--
onChange输入框值改变的回调(value: string, event?: FormEvent | ChangeEvent ) => 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: InstanceType<ButtonProps>;
  ClearButton: InstanceType<ButtonProps>;
  LoadingButton: InstanceType<ButtonProps>;
  SpeechButton: InstanceType<ButtonProps>;
};

Sender Slots

插槽名说明类型
header头部面板-
prefix前缀内容_
actions操作按钮{ ori?: VNode; info?: { components: { SendButton: InstanceType<Button>; ClearButton: InstanceType<Button>; LoadingButton: InstanceType<Button>; SpeechButton: InstanceType<Button>; } } }
footer底部内容{ info?: { components: { SendButton: InstanceType<Button>; ClearButton: InstanceType<Button>; LoadingButton: InstanceType<Button>; SpeechButton: InstanceType<Button>; } } }

Sender Ref

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

Sender.Header

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

Semantic DOM

  • prefix
    前缀
  • input
    输入框
  • actions
    操作列表
Header
Content
  • header
    头部
  • header-content
    头部内容
  • footer
    尾部

主题变量(Design Token)