diff --git a/components/sender/index.tsx b/components/sender/index.tsx index 816c10a42..d2b9c0649 100644 --- a/components/sender/index.tsx +++ b/components/sender/index.tsx @@ -76,6 +76,7 @@ export interface SenderProps actions?: React.ReactNode | ActionsRender; allowSpeech?: AllowSpeech; prefix?: React.ReactNode; + onlyInputFocus?: boolean; footer?: React.ReactNode | FooterRender; header?: React.ReactNode; autoSize?: boolean | { minRows?: number; maxRows?: number }; @@ -124,6 +125,7 @@ const ForwardSender = React.forwardRef((props, ref) => { disabled, allowSpeech, prefix, + onlyInputFocus, footer, header, onPaste, @@ -266,6 +268,11 @@ const ForwardSender = React.forwardRef((props, ref) => { e.preventDefault(); } + if (onlyInputFocus && !(e.target as HTMLElement)?.closest(`.${inputCls}`)) { + e.preventDefault(); + return; + } + inputRef.current?.focus(); }; diff --git a/components/sender/index.zh-CN.md b/components/sender/index.zh-CN.md index 383bfaf83..8e22b6ef6 100644 --- a/components/sender/index.zh-CN.md +++ b/components/sender/index.zh-CN.md @@ -46,6 +46,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*cOfrS4fVkOMAAA | loading | 是否加载中 | boolean | false | - | | header | 头部面板 | ReactNode | - | - | | prefix | 前缀内容 | ReactNode | - | - | +| onlyInputFocus | 是否只有点击input的时候会获得聚焦 | boolean | false | - | | footer | 底部内容 | ReactNode \| (info: { components: ActionsComponents }) => ReactNode | - | - | | readOnly | 是否让输入框只读 | boolean | false | - | | rootClassName | 根元素样式类 | string | - | - |