From 1bcd7a81dbe90feb975cf63facd3cbdf48d3efed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E7=94=B1=E7=9A=84=E4=B8=96=E7=95=8C=E4=BA=BA?= <3196812536@qq.com> Date: Fri, 15 Nov 2024 22:34:01 +0800 Subject: [PATCH 1/2] fix: textarea height problem --- src/components/respository/CommentSubmit.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/respository/CommentSubmit.tsx b/src/components/respository/CommentSubmit.tsx index 53e3d11a..6e3fbe65 100644 --- a/src/components/respository/CommentSubmit.tsx +++ b/src/components/respository/CommentSubmit.tsx @@ -31,13 +31,10 @@ function CommentSubmit(props: CommentSubmitProps) { const handleInput: FormEventHandler = (e) => { const { value } = e.currentTarget; - if (value.length == 0) { - e.currentTarget.style.height = `58px`; - } else { - // 自动增加输入框的高度 - // 2 是 上下两个 border 的高度 - e.currentTarget.style.height = `${e.currentTarget.scrollHeight + 2}px`; - } + + e.currentTarget.style.height = 'auto'; + const newHeight = Math.max(e.currentTarget.scrollHeight + 2, 58); + e.currentTarget.style.height = `${newHeight}px`; setCommentData({ ...commentData, From 79ed3ab2d2527ebb73be92eed8d6b16d5231574d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E7=94=B1=E7=9A=84=E4=B8=96=E7=95=8C=E4=BA=BA?= <3196812536@qq.com> Date: Sat, 7 Dec 2024 14:32:51 +0800 Subject: [PATCH 2/2] fix: textarea input with trim --- src/components/respository/CommentSubmit.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/respository/CommentSubmit.tsx b/src/components/respository/CommentSubmit.tsx index 6e3fbe65..b02b9bf5 100644 --- a/src/components/respository/CommentSubmit.tsx +++ b/src/components/respository/CommentSubmit.tsx @@ -30,7 +30,7 @@ function CommentSubmit(props: CommentSubmitProps) { const { t, belongId, className, onSuccess, onFail } = props; const handleInput: FormEventHandler = (e) => { - const { value } = e.currentTarget; + const value = e.currentTarget.value.trim(); e.currentTarget.style.height = 'auto'; const newHeight = Math.max(e.currentTarget.scrollHeight + 2, 58);