Skip to content

Commit f88dc9a

Browse files
fix: update commentsubmit.tsx
1 parent e841711 commit f88dc9a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/components/respository/CommentSubmit.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ function CommentSubmit(props: CommentSubmitProps) {
3131

3232
const handleInput: FormEventHandler<HTMLTextAreaElement> = (e) => {
3333
const { value } = e.currentTarget;
34-
if (value.length == 0) {
35-
e.currentTarget.style.height = `58px`;
36-
} else {
37-
// 自动增加输入框的高度
38-
// 2 是 上下两个 border 的高度
39-
e.currentTarget.style.height = `${e.currentTarget.scrollHeight + 2}px`;
40-
}
34+
35+
e.currentTarget.style.height = 'auto';
36+
const newHeight = Math.max(e.currentTarget.scrollHeight + 2, 58);
37+
e.currentTarget.style.height = `${newHeight}px`;
4138

4239
setCommentData({
4340
...commentData,
44-
comment: value,
41+
comment: value.trim(),
4542
height: e.currentTarget.scrollHeight + 2,
4643
});
4744
};

0 commit comments

Comments
 (0)