Skip to content

Commit 4ce3c8c

Browse files
authored
feat: Chat add canSend API (#3063)
* feat: Chat add canSend API * chore: Modify the API version number in the documentation
1 parent fd13488 commit 4ce3c8c

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

content/plus/chat/index-en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,7 @@ render(DefaultChat);
16061606
|------|--------|-------|-------|
16071607
| align | Dialog layout, supports `leftRight`,`leftAlign` | string | `leftRight` |
16081608
| bottomSlot | bottom slot for chat | React.ReactNode | - |
1609+
| canSend | Whether the send button is enabled. Normally, no settings are needed; the component internally determines whether sending is enabled. If settings are configured, the settings will prevail. Added in v2.90.0. | boolean |
16091610
| chatBoxRenderConfig | chatBox rendering configuration | ChatBoxRenderConfig | - |
16101611
| chats | Controlled conversation list | Message | - |
16111612
| className | Custom class name | string | - |

content/plus/chat/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ render(DefaultChat);
16091609
|------|--------|-------|-------|
16101610
| align | 对话布局方式,支持 `leftRight``leftAlign` | string | `leftRight` |
16111611
| bottomSlot | 底部插槽 | React.ReactNode | - |
1612+
| canSend | 发送按钮是否可以发送。通常无需设置,由内部逻辑决定。如有设置,以此设置为准,v2.90.0 新增 | boolean |
16121613
| chatBoxRenderConfig | chatBox 渲染配置 | ChatBoxRenderConfig | - |
16131614
| chats | 受控对话列表 | Message | - |
16141615
| className | 自定义类名 | string | - |

packages/semi-foundation/chat/inputboxFoundation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export default class InputBoxFoundation <P = Record<string, any>, S = Record<str
6060

6161
getDisableSend = () => {
6262
const { content, attachment } = this.getStates();
63-
const { disableSend: disableSendInProps } = this.getProps();
63+
const { disableSend: disableSendInProps, canSend } = this.getProps();
64+
// 如果用户设置了 canSend API,则使用 canSend 值
65+
// If the user has configured the canSend API, then the canSend value will be used.
66+
if (typeof canSend === 'boolean') {
67+
return !canSend;
68+
}
6469
/** 不能发送的条件:(满足任1)
6570
* 1. props 中禁止发送;2. 没有文本输入,且没有上传文件; 3.上传文件中有状态不为 success 的
6671
* Conditions under which content cannot be sent: (any one of the following conditions must be met)

packages/semi-ui/chat/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
291291
customMarkDownComponents, mode, showClearContext,
292292
placeholder, inputBoxCls, inputBoxStyle,
293293
hintStyle, hintCls, uploadProps, uploadTipProps,
294-
sendHotKey, renderDivider, markdownRenderProps, enableUpload
294+
sendHotKey, renderDivider, markdownRenderProps, enableUpload,
295+
canSend,
295296
} = this.props;
296297
const { backBottomVisible, chats, wheelScroll, uploadAreaVisible } = this.state;
297298
let showStopGenerateFlag = false;
@@ -389,6 +390,7 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
389390
</span>)}
390391
{/* input area */}
391392
<InputBox
393+
canSend={canSend}
392394
showClearContext={showClearContext}
393395
uploadRef={this.uploadRef}
394396
manualUpload={this.adapter.manualUpload}

packages/semi-ui/chat/interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface CommonChatsProps {
2929
export interface ChatProps extends CommonChatsProps {
3030
style?: React.CSSProperties;
3131
className?: string;
32+
canSend?: boolean;
3233
hints?: string[];
3334
renderHintBox?: (props: {content: string; index: number;onHintClick: () => void}) => React.ReactNode;
3435
onHintClick?: (hint: string) => void;
@@ -158,6 +159,7 @@ export interface ChatBoxProps extends Omit<CommonChatsProps, "chats"> {
158159
}
159160

160161
export interface InputBoxProps {
162+
canSend?: boolean;
161163
showClearContext?: boolean;
162164
sendHotKey?: 'enter' | 'shift+enter';
163165
placeholder: string;

0 commit comments

Comments
 (0)