본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Truncate

원문 보기 위키 갱신

Truncate는 넘치는 텍스트를 줄임표(ellipsis)로 짧게 보여주는 데 쓰는 컴포넌트예요. 기본 사용법, 부모에 맞추기, 커스텀 최대 너비, 호버 시 펼치기, 그리고 Props를 다뤄요.

출처: 문서

본문

React 예시

기본(Default)

<Truncate title="Some example text">Some example text</Truncate>

부모에 맞추기(Fit to parent)

maxWidth를 100%로 설정하면 부모 컨테이너 폭에 맞춰 잘라요.

<div style={{maxWidth: '125px', width: '100%'}}>
  <Truncate title="Some example text" maxWidth="100%">
    Some example text
  </Truncate>
</div>

커스텀 최대 너비

<Truncate title="Hover this example text" maxWidth="10ch">
  Some example text
</Truncate>

호버 시 펼치기(Expand on hover)

expandable을 설정하면 호버 시 잘린 전체 텍스트를 표시해요.

<Truncate title="Hover this example text" expandable>
  Hover this example text
</Truncate>

Props

Truncate

이름 기본값 설명
maxWidth 125 텍스트의 최대 너비 설정(number)
inline false 텍스트를 인라인 블록으로 표시하고 상단에 세로 정렬(boolean)
expandable false 잘린 텍스트를 호버 시 표시할 수 있게 함(boolean)
as 'div' React.ElementType

더 알아보기 (Learn more)