Skip to content

Commit 32bd960

Browse files
tomasyu985yangyu.1
andauthored
feat: chat input limt 4 lines and support card message (#286)
* fix: 修复小程序输入框输入超过 4 行是失去焦点的问题 * fix: taro chat 增加 card 节点 * chore: Publish fix/chat_input_4_lines --------- Co-authored-by: yangyu.1 <yangyu.1@bytedance.com>
1 parent 8a83c3d commit 32bd960

6 files changed

Lines changed: 29 additions & 25 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze/chat-sdk",
5+
"comment": "修复小程序输入框输入超过 4 行是失去焦点的问题",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@coze/chat-sdk",
10+
"email": "yangyu.1@bytedance.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze/chat-sdk",
5+
"comment": "taro chat 增加 card 节点",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@coze/chat-sdk",
10+
"email": "yangyu.1@bytedance.com"
11+
}

packages/chat-sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coze/chat-sdk",
3-
"version": "0.1.11-beta.18",
3+
"version": "0.1.11-beta.19",
44
"description": "Coze chat components for taro",
55
"license": "MIT",
66
"author": "gaoding.devingao@bytedance.com",
@@ -167,4 +167,4 @@
167167
"css": "Less",
168168
"framework": "React"
169169
}
170-
}
170+
}

packages/chat-sdk/src/chatflow/helper/chat-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class ChatFlowService extends ChatService {
262262
bodyData.ext = {
263263
_caller: this.chatFlowProps?.project?.caller,
264264
user_id: params.user_id,
265+
enable_card: 'true',
265266
};
266267
bodyData.suggest_reply_info = params.suggestPromoteInfo
267268
? {

packages/chat-sdk/src/libs/ui-kit/chat-input/textarea/index.module.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
display: block;
88
position: relative;
99
box-sizing: border-box;
10-
max-height: 80px;
11-
overflow: auto;
1210
&::-webkit-scrollbar {
1311
width: 6px;
1412
}
@@ -23,6 +21,7 @@
2321
font-weight: 400;
2422
padding: 0;
2523
line-height: 20px;
24+
max-height: 80px;
2625
box-sizing: border-box;
2726
background-color: transparent;
2827

packages/chat-sdk/src/libs/ui-kit/chat-input/textarea/index.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useState, useEffect, useRef } from 'react';
1+
import { FC, useEffect, useRef } from 'react';
22

33
import {
44
Textarea as TaroTextarea,
@@ -16,22 +16,15 @@ export const Textarea: FC<
1616
onInputChange: (val: string) => void;
1717
} & TextareaProps
1818
> = ({ onSendTextMessage, onInputChange, placeholder, ...rest }) => {
19-
const [lineNum, setLineNum] = useState(0);
20-
const { value, id = '' } = rest;
19+
const { id = '' } = rest;
2120

22-
const getHeight = usePersistCallback(
23-
(lineNumTemp: number) => `${Math.max(1, lineNumTemp) * 20}px`,
24-
);
2521
const handleInputChange = usePersistCallback((val: string) => {
2622
onInputChange(val);
2723
if (isWeb) {
2824
const el = getInputElInWeb();
2925
if (el) {
3026
el.style.height = '0px';
31-
const scrollHeight = Number(el?.scrollHeight) || 0;
32-
const lineNumTemp = Math.floor(scrollHeight / 20);
3327
el.style.height = 'inherit';
34-
setLineNum(lineNumTemp);
3528
}
3629
}
3730
});
@@ -40,11 +33,6 @@ export const Textarea: FC<
4033
onSendTextMessage,
4134
handleInputChange,
4235
});
43-
useEffect(() => {
44-
if (!value) {
45-
setLineNum(0);
46-
}
47-
}, [value]);
4836

4937
return (
5038
<View className={styles['input-padding-container']}>
@@ -56,12 +44,10 @@ export const Textarea: FC<
5644
showConfirmBar={true}
5745
controlled
5846
cursorSpacing={20}
47+
autoHeight
5948
placeholder={placeholder}
6049
placeholderClass={styles.placeholder}
6150
disableDefaultPadding={true}
62-
style={{
63-
height: getHeight(lineNum),
64-
}}
6551
onConfirm={() => {
6652
if (isMini) {
6753
onSendTextMessage();
@@ -71,10 +57,6 @@ export const Textarea: FC<
7157
logger.debug('onInputKeyDown: onInput ', event.detail.value);
7258
handleInputChange(event.detail.value);
7359
}}
74-
onLineChange={event => {
75-
logger.debug('ChatInput onLineChange:', event);
76-
!isWeb && setLineNum(event.detail.lineCount);
77-
}}
7860
{...rest}
7961
/>
8062
</View>

0 commit comments

Comments
 (0)