펼치기
긴 글의 첫 몇 줄을 보여 주고, 사용자가 원할 때 전체 내용을 펼칩니다.
이 페이지의 내용
펼치기 컴포넌트는 설명, 리뷰, 변경 기록처럼 긴 글의 첫 몇 줄을 보여 주고, 사용자가 원할 때 나머지를 펼칩니다. 접힌 상태에서는 텍스트 하단이 점차 흐려집니다. 아래쪽 토글을 누르면 토글이 뒤집히고 텍스트가 전체 높이로 펼쳐집니다.
펼치기
<details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><svg class="icon expand-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /> </svg> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details>import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'<details className="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary className="expand-toggle"> <span className="expand-more">Show more</span><span className="expand-less">Show less</span><ChevronDownIcon className="icon expand-chevron" /> </summary> <p className="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script> import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script setup>import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'</script><template> <details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p> </details></template>기본 HTML 요소인 <details>를 사용하며, 토글은 그 안의 <summary>로, 문구와 expand-chevron 아이콘을 담습니다. 따라서 키보드 조작, 페이지 내 검색, 보조 기술을 기본으로 지원합니다. 브라우저가 ::details-content를 지원하면 접힌 상태에서도 미리보기가 표시됩니다. 그 외의 브라우저에서는 일반적인 details 요소처럼 접힌 상태에서 텍스트가 숨겨지며, 토글로 펼칠 수 있습니다.
<details>의 요구 사항에 따라 summary는 마크업에서 맨 앞에 배치하며, 화면에서는 텍스트 아래에 표시합니다.
#줄 수
--expand-lines는 텍스트 자체의 줄 높이를 기준으로 미리보기에 표시할 줄 수를 정합니다. 기본값은 4줄입니다.
줄 수
<details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><svg class="icon expand-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /> </svg> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details>import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'<details className="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style={{ '--expand-lines': '2' } as React.CSSProperties}> <summary className="expand-toggle"> <span className="expand-more">Read the full note</span><span className="expand-less">Show less</span><ChevronDownIcon className="icon expand-chevron" /> </summary> <p className="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script> import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script setup>import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'</script><template> <details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p> </details></template>#토글 문구
두 상태에 사용할 문구를 expand-more와 expand-less에 넣으세요. 스타일시트가 현재 상태에 맞는 문구를 표시합니다. 가능하면 "더 보기"처럼 막연한 문구보다 "리뷰 전체 읽기"처럼 펼쳤을 때 볼 수 있는 내용을 구체적으로 적으세요. 두 상태에 같은 문구를 써도 자연스럽다면 summary에 일반 텍스트로 작성하세요.
#사용 시점
대부분의 독자가 훑어보는 글에 펼치기 컴포넌트를 사용하세요. 질문과 답변 목록에는 접힌 상태에서 각 항목의 제목만 표시하는 아코디언을 사용하세요. 숨겨지는 부분에는 링크나 컨트롤을 넣지 마세요. 접힌 상태에서도 키보드로 미리보기에서 잘린 요소에 포커스를 이동할 수 있습니다.
#접근성
- 보조 기술은 summary를 버튼으로 인식하고 텍스트가 펼쳐져 있는지 알려 줍니다. 페이지 내 검색에서 details 내부에 일치하는 내용이 있으면 해당 요소가 펼쳐집니다.
- 텍스트에 마스크를 씌워 하단을 흐리게 처리하므로, 마지막으로 보이는 줄은 흐려지고 앞부분의 줄은 원래 대비를 유지합니다.
- 동작 줄이기가 활성화되어 있으면 텍스트가 즉시 펼쳐집니다.
#클래스
| 클래스 | 설명 |
|---|---|
expand | details 요소입니다. 닫혀 있을 때는 아래쪽으로 갈수록 흐려지는 미리보기를 표시합니다. |
expand-toggle | summary는 마크업에서 맨 앞에 두고 화면에서는 텍스트 아래에 표시합니다. 열고 닫을 때 꺾쇠 방향이 바뀝니다 |
expand-chevron | 토글이 문구 뒤에 담는 꺾쇠 아이콘입니다. 텍스트가 열려 있는 동안 반대 방향을 향합니다 |
expand-more | 닫혀 있을 때 토글에 표시되는 문구 |
expand-less | 열려 있을 때 토글에 표시되는 문구 |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--expand-lines | 4 | 텍스트 자체의 줄 높이를 기준으로 줄 수로 지정하는 미리보기 높이 |