diff --git a/src/components/respository/CommentSubmit.tsx b/src/components/respository/CommentSubmit.tsx index 53e3d11..c82ee9a 100644 --- a/src/components/respository/CommentSubmit.tsx +++ b/src/components/respository/CommentSubmit.tsx @@ -31,17 +31,14 @@ 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, - comment: value, + comment: value.trim(), height: e.currentTarget.scrollHeight + 2, }); };