Sender输入框
Sender
输入框
用于聊天的输入框组件。
使用import { Sender } from "@ant-design/x"; |
文档 编辑此页... |
通用属性参考:通用属性
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| allowSpeech | 是否允许语音输入 | boolean | SpeechConfig | false | - |
| classNames | 样式类名 | 见下 | - | - |
| components | 自定义组件 | Record<'input', ComponentType> | - | - |
| defaultValue | 输入框默认值 | string | - | - |
| disabled | 是否禁用 | boolean | false | - |
| loading | 是否加载中 | boolean | false | - |
| suffix | 后缀内容,默认展示操作按钮,当不需要默认操作按钮时,可以设为 suffix={false} | React.ReactNode | false |(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode | false; | oriNode | - |
| header | 头部面板 | React.ReactNode | false |(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode | false; | false | - |
| prefix | 前缀内容 | React.ReactNode | false |(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode | false; | false | - |
| footer | 底部内容 | React.ReactNode | false |(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode | false; | false | - |
| readOnly | 是否让输入框只读 | boolean | false | - |
| rootClassName | 根元素样式类 | string | - | - |
| styles | 语义化定义样式 | 见下 | - | - |
| submitType | 提交模式 | SubmitType | enter | shiftEnter | - |
| value | 输入框值 | string | - | - |
| onSubmit | 点击发送按钮的回调 | (message: string, slotConfig?: SlotConfigType[]) => void | - | - |
| onChange | 输入框值改变的回调 | (value: string, event?: React.FormEvent<HTMLTextAreaElement> | React.ChangeEvent<HTMLTextAreaElement>, slotConfig?: SlotConfigType[]) => void | - | - |
| onCancel | 点击取消按钮的回调 | () => void | - | - |
| onPasteFile | 黏贴文件的回调 | (files: FileList) => void | - | - |
| autoSize | 自适应内容高度,可设置为 true | false 或对象:{ minRows: 2, maxRows: 6 } | boolean | { minRows?: number; maxRows?: number } | { maxRows: 8 } | - |
| slotConfig | 词槽配置,配置后输入框将变为词槽模式,支持结构化输入,此模式value 和 defaultValue 配置将无效。 | SlotConfigType[] | - | - |
type SpeechConfig = {// 当设置 `recording` 时,内置的语音输入功能将会被禁用。// 交由开发者实现三方语音输入的功能。recording?: boolean;onRecordingChange?: (recording: boolean) => void;};
type ActionsComponents = {SendButton: React.ComponentType<ButtonProps>;ClearButton: React.ComponentType<ButtonProps>;LoadingButton: React.ComponentType<ButtonProps>;SpeechButton: React.ComponentType<ButtonProps>;};
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| nativeElement | 外层容器 | HTMLDivElement | - | - |
| focus | 获取焦点,当 cursor = 'slot' 时焦点会在第一个插槽类型为 input 的输入框内,若不存在对应的 input 则效果会和 end 一致。 | (option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' | 'slot' }) | - | - |
| blur | 取消焦点 | () => void | - | - |
| insert | 插入文本或者插槽,使用插槽时需确保 slotConfig 已配置 | (value: string) => void | (slotConfig: SlotConfigType[], position?: insertPosition, replaceCharacters?: string) => void; | - | - |
| clear | 清空内容 | () => void | - | - |
| getValue | 获取当前内容和结构化配置 | () => { value: string; config: SlotConfigType[] } | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| type | 节点类型,决定渲染组件类型,必填 | 'text' | 'input' | 'select' | 'tag' | 'custom' | - | - |
| key | 唯一标识,type 为 text 时可省略 | string | - | - |
| formatResult | 格式化最终结果 | (value: any) => string | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| text | 文本内容 | string | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| props.placeholder | 占位符 | string | - | - |
| props.defaultValue | 默认值 | string | number | readonly string[] | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| props.options | 选项数组,必填 | string[] | - | - |
| props.placeholder | 占位符 | string | - | - |
| props.defaultValue | 默认值 | string | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| props.label | 标签内容,必填 | ReactNode | - | - |
| props.value | 标签值 | string | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| props.defaultValue | 默认值 | any | - | - |
| customRender | 自定义渲染函数 | (value: any, onChange: (value: any) => void, props: { disabled?:boolean,readOnly?: boolean},item: SlotConfigType) => React.ReactNode | - | - |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| children | 通用内容 | ReactNode | - | - |
| checkedChildren | 选中时的内容 | ReactNode | - | |
| unCheckedChildren | 非选中时的内容 | ReactNode | - | |
| icon | 设置图标组件 | ReactNode | - | |
| disabled | 是否禁用 | boolean | false | - |
| loading | 加载中的开关 | boolean | - | - |
| value | 开关的值 | boolean | false | - |
| onChange | 变化时的回调函数 | function(checked: boolean) | - | - |
| rootClassName | 根元素样式类 | string | - | - |
value 和 defaultValue 属性无效,请使用 ref 及回调事件获取输入框的值和词槽配置。onChange/onSubmit 回调的第三个参数 config,仅用于获取当前结构化内容。示例:
// ❌ 错误用法, slotConfig 为不受控用法const [config, setConfig] = useState([]);<SenderslotConfig={config}onChange={(value, e, config) => {setConfig(config);}}/>// ✅ 正确用法<Senderkey={key}slotConfig={config}onChange={(value, _e, config) => {// 仅用于获取结构化内容setKey('new_key')}}/>
| Token 名称 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| colorBgSlot | 词槽背景颜色 | string | rgba(22,119,255,0.06) |
| colorBorderInput | 输入框边框颜色 | string | rgba(0,0,0,0.1) |
| colorBorderSlot | 词槽边框颜色 | string | rgba(22,119,255,0.06) |
| colorBorderSlotHover | 词槽边框悬浮态颜色 | string | rgba(22,119,255,0.1) |
| colorTextSlot | 词槽文本颜色 | string | #1677ff |
| colorTextSlotPlaceholder | 词槽文本占位符颜色 | string | rgba(22,119,255,0.25) |
| switchCheckedBg | 开关选中背景颜色 | string | rgba(22,119,255,0.08) |
| switchCheckedHoverBg | 开关选中悬浮态背景颜色 | string | rgba(22,119,255,0.1) |
| switchUncheckedHoverBg | 开关未选中悬浮态背景颜色 | string | rgba(0,0,0,0.04) |