1- import { StyledText } from '.. /Text/StyledText' ;
2- import { CommentLayout , SendContainer , CommentTextarea , SendImg } from './styles' ;
3- import Send from '../../ assets/default/send-comment.svg' ;
1+ import { StyledText } from '@components /Text/StyledText' ;
2+ import { CommentLayout , SendContainer , CommentTextarea , SendButton } from './styles' ;
3+ import send from '@ assets/default/send-comment.svg' ;
44import React , { useEffect , useRef , useState } from 'react' ;
55import { CommentProps } from './dto' ;
66
7- const Comment : React . FC < CommentProps > = ( { content, sendComment, isModal } ) => {
7+ const Comment : React . FC < CommentProps > = ( { content, sendComment, isModal = false } ) => {
88 const [ comment , setComment ] = useState ( '' ) ;
99 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
1010
11- // textarea 높이 조정 함수
11+ // textarea 높이 조정
1212 const adjustTextareaHeight = ( ) => {
1313 if ( textareaRef . current ) {
1414 textareaRef . current . style . height = '1.2rem' ; // 초기 높이 설정
1515 textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ; // 스크롤 높이에 맞춰 재조정
1616 }
1717 } ;
1818
19- useEffect ( ( ) => {
20- adjustTextareaHeight ( ) ;
21- } , [ comment ] ) ; // comment가 변경될 때만 높이 재조정
22-
23- const handleChangeComment = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
19+ const handleCommentChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
2420 if ( e . target . value . length <= 100 ) {
2521 setComment ( e . target . value ) ;
2622 }
2723 } ;
2824
29- const handleKeyDown = ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
25+ const handleEnterKeyDown = ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
3026 if ( comment === '' ) {
3127 e . preventDefault ( ) ;
3228 return ;
@@ -48,18 +44,25 @@ const Comment: React.FC<CommentProps> = ({ content, sendComment, isModal }) => {
4844 }
4945 } ;
5046
47+ // comment가 변경될 때만 높이 재조정
48+ useEffect ( ( ) => {
49+ adjustTextareaHeight ( ) ;
50+ } , [ comment ] ) ;
51+
5152 return (
5253 < CommentLayout $isModal = { isModal } >
53- < StyledText $textTheme = { { style : 'body1-regular' , lineHeight : 1.5 } } > { content } </ StyledText >
54+ < StyledText $textTheme = { { style : 'body1-regular' } } > { content } </ StyledText >
5455 < SendContainer >
5556 < CommentTextarea
5657 ref = { textareaRef }
5758 value = { comment }
58- onChange = { handleChangeComment }
59- onKeyDown = { handleKeyDown }
59+ onChange = { handleCommentChange }
60+ onKeyDown = { handleEnterKeyDown }
6061 maxLength = { 100 }
6162 />
62- < SendImg src = { Send } onClick = { handleSendButtonClick } />
63+ < SendButton onClick = { handleSendButtonClick } >
64+ < img src = { send } alt = "메시지 전송 아이콘" />
65+ </ SendButton >
6366 </ SendContainer >
6467 </ CommentLayout >
6568 ) ;
0 commit comments