Skip to Content

Comment

댓글 목록을 렌더링하고 페이지네이션·답글 버튼·스크롤 위치 복원 기능을 제공하는 컨테이너 컴포넌트


개요

Comment 컴포넌트는 작성자·작성일·답글 대상자·본문·답글 버튼으로 구성된 댓글 항목을 스크롤 가능한 목록으로 제공합니다.

주요 특징

  • 댓글 목록 렌더링: 작성자·작성일·답글 대상자·본문 구조
  • 더보기 페이지네이션: 버튼 클릭으로 추가 댓글 로드
  • 로딩 상태: 스피너 오버레이 표시
  • 빈 상태: 안내 문구 표시
  • 답글 버튼: 클릭 시 댓글 데이터 콜백 전달
  • 스크롤 위치 관리: initialScrollTop + ref.getScrollTop()

기본 사용

댓글 목록을 렌더링합니다.

홍길동2025-06-01 09:30
프로젝트 진행 상황에 대해 공유 부탁드립니다.
김철수홍길동2025-06-01 10:15
현재 80% 완료되었습니다.
이영희2025-06-02 14:00
리뷰 완료했습니다.

빈 상태

댓글이 없을 때 안내 문구를 표시합니다.

아직 작성된 댓글이 없습니다.

로딩 상태

데이터를 불러오는 동안 스피너 오버레이를 표시합니다.

홍길동2025-06-01 09:30
프로젝트 진행 상황에 대해 공유 부탁드립니다.
김철수홍길동2025-06-01 10:15
현재 80% 완료되었습니다.

더보기 (페이지네이션)

hasMore=true이면 더보기 버튼이 표시되고, 클릭 시 onLoadMore가 호출됩니다.

홍길동2025-06-01 09:30
프로젝트 진행 상황에 대해 공유 부탁드립니다.
김철수홍길동2025-06-01 10:15
현재 80% 완료되었습니다.

표시 중: 2 / 5


답글 버튼 클릭

답글 버튼 클릭 시 onClickButton 콜백으로 해당 댓글의 index와 데이터가 전달됩니다.

홍길동2025-06-01 09:30
프로젝트 진행 상황에 대해 공유 부탁드립니다.
김철수홍길동2025-06-01 10:15
현재 80% 완료되었습니다.
이영희2025-06-02 14:00
리뷰 완료했습니다.

스크롤 위치 관리

initialScrollTop으로 스크롤 위치를 복원하고, ref.getScrollTop()으로 현재 위치를 조회할 수 있습니다.

import { useRef } from "react" import { Comment, type CommentRef } from "@vortex/ui-cals" function MyPage() { const commentRef = useRef<CommentRef>(null) // 페이지 이탈 시 저장 const saveScrollPosition = () => { const scrollTop = commentRef.current?.getScrollTop() ?? 0 sessionStorage.setItem("commentScroll", String(scrollTop)) } // 복원 const savedTop = Number(sessionStorage.getItem("commentScroll") || 0) return <Comment ref={commentRef} comments={comments} initialScrollTop={savedTop} /> }

API Reference

Props

PropTypeDefaultDescription
commentsCommentItem[][]댓글 목록 데이터
loadingbooleanfalse로딩 상태
hasMorebooleanfalse더 불러올 댓글 존재 여부
heightnumber | string250스크롤 영역 높이
emptyTextstring"댓글이 없습니다."빈 상태 안내 문구
visiblebooleantrue표시 여부
buttonLabelstring"답글"답글 버튼 텍스트
showButtonbooleantrue답글 버튼 표시 여부
pageSizenumber20한 번에 불러올 댓글 수
initialScrollTopnumber-초기 스크롤 위치 복원
classNamestring-컨테이너 className
styleReact.CSSProperties-인라인 스타일

Events

EventTypeDescription
onLoadMore() => void더보기 버튼 클릭 시 호출
onClickButton(data: CommentClickData) => void답글 버튼 클릭 시 호출

Ref (CommentRef)

MethodReturn TypeDescription
getScrollTop()number현재 스크롤 위치 반환

Types

interface CommentItem { id: string author: string date: string replyTo?: string content: string } interface CommentClickData { index: number comment: CommentItem }

접근성

권장 사항

  • ✅ 댓글 목록에 role="list" 자동 적용
  • ✅ 각 댓글 항목에 role="listitem" 자동 적용
  • ✅ 로딩 시 aria-busy="true" 적용
  • ✅ 답글 버튼에 작성자 이름 포함 aria-label 제공

관련 컴포넌트

Last updated on