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

NavList

원문 보기 위키 갱신

NavList는 내비게이션 링크의 세로 목록을 렌더링하는 컴포넌트입니다. 사용자의 현재 컨텍스트에 맞는 탐색 링크를 정리하고, 현재 어느 뷰에 있는지 표시해 줍니다.

출처: 문서

본문

NavList는 사용자의 현재 컨텍스트에 대한 내비게이션 링크를 구성하고, 현재 보고 있는 뷰를 표시합니다. 보통 기본 콘텐츠 영역에 렌더링되는 것을 변경하는 사이드바로 사용됩니다.

React 예제 (React examples)

기본 (Default)

<NavList>
  <NavList.Item href="#" aria-current="page">
    Item 1
  </NavList.Item>
  <NavList.Item href="#">Item 2</NavList.Item>
  <NavList.Item href="#">Item 3</NavList.Item>
</NavList>

그룹 항목 섹션 (Grouped item sections)

긴 목록에서 탐색을 단순화하려면 그룹을 사용하세요. 중첩 ul에서 항목을 의미적으로 그룹화하지 않는 시각적 섹션에는 구분선(dividers)을 사용하세요.

<NavList>
  <NavList.Group title="Group 1">
    <NavList.Item aria-current="true" href="#">
      Item 1A
    </NavList.Item>
    <NavList.Item href="#">Item 1B</NavList.Item>
    <NavList.Item href="#">Item 1C</NavList.Item>
  </NavList.Group>
  <NavList.Group title="Group 2">
    <NavList.Item href="#">Item 2A</NavList.Item>
    <NavList.Item href="#">Item 2B</NavList.Item>
    <NavList.Item href="#">Item 2C</NavList.Item>
  </NavList.Group>
</NavList>

제목과 함께 (With a heading)

NavList.Heading으로 내비게이션 영역에 제목을 부여하세요. 기본적으로 h2를 렌더링하고, <nav> 랜드마크를 자동으로 명명하며, 그룹 제목을 한 단계 아래에 중첩합니다(h2 아래의 h3). 설정 스타일 페이지에서 내비게이션이 올바른 제목 개요를 갖도록 권장됩니다. 자세한 내용은 접근성 지침(accessibility guidance)을 참고하세요.

<NavList>
  <NavList.Heading>Settings</NavList.Heading>
  <NavList.Group title="Account">
    <NavList.Item href="#" aria-current="page">
      Profile
    </NavList.Item>
    <NavList.Item href="#">Appearance</NavList.Item>
  </NavList.Group>
  <NavList.Group title="Security">
    <NavList.Item href="#">Password and authentication</NavList.Item>
    <NavList.Item href="#">Sessions</NavList.Item>
  </NavList.Group>
</NavList>

제목이 보조 기술에는 영역을 명명하지만 시각적으로는 보이지 않아야 할 때 visuallyHidden prop을 사용하세요.

<NavList>
  <NavList.Heading visuallyHidden>Settings</NavList.Heading>
  <NavList.Group title="Account">
    <NavList.Item href="#" aria-current="page">
      Profile
    </NavList.Item>
    <NavList.Item href="#">Appearance</NavList.Item>
  </NavList.Group>
  <NavList.Group title="Security">
    <NavList.Item href="#">Password and authentication</NavList.Item>
    <NavList.Item href="#">Sessions</NavList.Item>
  </NavList.Group>
</NavList>

중첩 하위 내비게이션 항목 (Nested subnav items)

최상위 항목은 하위 항목을 펼치고/접을 수 있습니다. 최상위 항목만 토글 역할을 하며 링크는 아닙니다. 최대 4단계 중첩까지 사용하세요 — 더 필요하다면 내비게이션 설계를 다시 고려하세요.

깊게 중첩된 내비게이션 구조를 지원하기 위해 NavList를 TreeView로 대체하지 마세요. TreeView는 내비게이션의 접근 가능한 대체물이 아닙니다. 다른 목적을 제공하며 보조 기술이 내비게이션으로 인식하지 않기 때문입니다.

<NavList>
  <NavList.Item href="#" defaultOpen>
    Item 1
    <NavList.SubNav>
      <NavList.Item href="#" aria-current="page">
        Sub item 1
      </NavList.Item>
      <NavList.Item href="#">Sub item 2</NavList.Item>
    </NavList.SubNav>
  </NavList.Item>
  <NavList.Item href="#">Item 2</NavList.Item>
  <NavList.Item href="#">Item 3</NavList.Item>
</NavList>

선두 비주얼이 있는 항목 (Items with leading visuals)

선두 비주얼(Leading visuals)은 항목이 무엇인지에 대한 시각적 힌트를 보여 주는 데 흔히 사용됩니다. 예를 들어 연결되는 뷰를 나타내는 아이콘 또는 아바타가 있습니다.

<NavList>
  <NavList.Item href="#" aria-current="page">
    <NavList.LeadingVisual>
      <RepoIcon />
    </NavList.LeadingVisual>
    Repos
  </NavList.Item>
  <NavList.Item href="#">
    <NavList.LeadingVisual>
      <PersonIcon />
    </NavList.LeadingVisual>
    People
  </NavList.Item>
  <NavList.Item href="#">
    <NavList.LeadingVisual>
      <FileDirectoryIcon />
    </NavList.LeadingVisual>
    Folders
  </NavList.Item>
</NavList>

트레일링 비주얼이 있는 항목 (Items with trailing visuals)

트레일링 비주얼(Trailing visuals)은 항목에 대한 보조 정보를 보여 주는 데 흔히 사용됩니다. 예를 들어 페이지의 읽지 않은 알림 개수가 있습니다.

<NavList>
  <NavList.Item href="#" target="_blank" aria-current="page">
    Item 1
    <NavList.TrailingVisual>
      <LinkExternalIcon />
    </NavList.TrailingVisual>
  </NavList.Item>
  <NavList.Item href="#" target="_blank">
    Item 2
    <NavList.TrailingVisual>
      <LinkExternalIcon />
    </NavList.TrailingVisual>
  </NavList.Item>
  <NavList.Item href="#" target="_blank">
    Item 3
    <NavList.TrailingVisual>
      <LinkExternalIcon />
    </NavList.TrailingVisual>
  </NavList.Item>
</NavList>

트레일링 액션이 있는 항목 (Items with trailing actions)

<NavList>
  <NavList.Item href="#" aria-current="page">
    Item 1
    <NavList.TrailingAction
      label="Pin item 1"
      icon={PinIcon}
      onSelect={() => {
        alert('Fake pin Item 1')
      }}
    />
  </NavList.Item>
  <NavList.Item href="#">
    Item 2
    <NavList.TrailingAction
      label="Pin item 2"
      icon={PinIcon}
      onSelect={() => {
        alert('Fake pin Item 2')
      }}
    />
  </NavList.Item>
  <NavList.Item href="#">
    Item 3
    <NavList.TrailingAction
      label="Pin item 3"
      icon={PinIcon}
      onSelect={() => {
        alert('Fake pin Item 3')
      }}
    />
  </NavList.Item>
</NavList>

더 많은 코드 예제 (More code examples)

NavList Storybook 스토리를 참고하세요.

Props

Name Default Description
aria-label string
aria-labelledby string
disableItemGap false boolean — 항목 간격(item gap) 기능이 활성화될 때 항목 사이의 간격을 비활성화합니다.
ref React.RefObject
as "nav" React.ElementType
Name Default Description
as "h2" 'h2' | 'h3' — NavList의 의미론적 제목 수준. 자식 그룹 제목의 기본 수준도 설정합니다(한 단계 더 깊게 렌더링: h2 아래 h3, h3 아래 h4). 계층이 얕게 유지되도록 h2/h3로 제한됩니다.
visuallyHidden false boolean — 제목을 시각적으로 숨기면서 보조 기술에는 유지하고 nav 랜드마크의 접근 가능한 이름으로 사용합니다.
children Required ReactNode — NavList 제목으로 렌더링되는 텍스트
id string — 제목 요소의 커스텀 id. 설정되면 nav 랜드마크를 명명하는 aria-labelledby 대상으로 사용됩니다. 그렇지 않으면 생성된 id가 사용됩니다.
className string — 커스텀 CSS 클래스 이름
style React.CSSProperties — 커스텀 CSS 스타일
Name Default Description
href string — 항목이 이동하는 URL. href는 기본 <a> 요소에 전달됩니다. as가 지정되면 컴포넌트에 다른 props가 필요할 수 있습니다. 항목에 sub-nav가 있으면 항목은 <button>으로 렌더링되고 href는 무시됩니다.
aria-current false 'page' | 'step' | 'location' | 'date' | 'time' | true | false — 항목이 현재 페이지를 나타내려면 aria-current를 "page"로, 페이지의 현재 위치를 나타내려면 "location"으로 설정하세요. aria-current에 대한 자세한 내용은 MDN을 참고하세요.
defaultOpen boolean — 항목에 SubNav가 있을 때 처음 렌더링될 때의 열림 상태
inactiveText string — 이 항목이 현재 비활성이고 활성화될 수 없는 이유를 설명하는 텍스트
ref React.RefObject
as "a" React.ElementType — 더 많은 prop 옵션은 a를 참고하세요
Name Default Description
variant 'inline' 'inline' | 'block' — inline 설명은 주요 텍스트 옆에, block 설명은 주요 텍스트 아래에 배치됩니다.
truncate false boolean — inline 설명이 넘칠 때 텍스트를 잘라낼지 여부
className string — 커스텀 CSS 클래스 이름
style React.CSSProperties — 커스텀 CSS 스타일
Name Default Description
ref React.RefObject
Name Default Description
ref React.RefObject
Name Default Description
ref React.RefObject
Name Default Description
children Required ReactNode — 관련된 NavList.Items 집합
title string — 그룹의 제목으로 렌더링되는 텍스트. 또는 NavList.GroupHeading 컴포넌트를 NavList.Group의 자식으로 전달할 수 있습니다. title과 NavList.GroupHeading이 모두 전달되면 NavList.GroupHeading이 제목으로 렌더링됩니다.
hideDivider false boolean — 그룹 앞에 렌더링되는 구분선을 숨길지 여부
ref React.RefObject
Name Default Description
auxiliaryText string — Group에 대한 추가 정보를 제공하는 보조 텍스트
variant 'subtle' | 'filled' — 스타일 변형. 사용은 재량입니다. "filled"은 배경에 겹쳐져 주변 콘텐츠에서 오프셋되고, "subtle"은 주변 콘텐츠에서 상대적으로 덜 오프셋됩니다.
visuallyHidden boolean
ref React.RefObject
as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' — 그룹 제목의 제목 수준. 의미론적 제목 태그를 설정합니다. 기본값은 NavList.Heading보다 한 단계 아래(h2 아래 h3, h3 아래 h4)이며, NavList.Heading이 없으면 h3입니다.
Name Default Description
ref React.RefObject
Name Default Description
as button a | button — 렌더링할 HTML 요소
label Required string — 컨트롤의 접근 가능한 이름
icon Required string — IconButton에 전달할 Octicon. 설정되지 않으면 TrailingAction은 IconButton 대신 Button으로 렌더링됩니다.
href string — TrailingAction이 링크로 렌더링될 때의 href
Name Default Description
label Required string — 컨트롤의 접근 가능한 이름
pages 0 number — 총 페이지 수. 한 번에 표시할 항목 수를 계산하는 데 사용됩니다.
items Required Array — 그룹에 렌더링할 NavList.Items
renderItem (item: {text: string}) => React.ReactNode — 그룹에 렌더링할 ReactNode를 반환하는 함수. 제공되지 않으면 그룹은 배열의 항목만 렌더링합니다.
ref React.RefObject

더 알아보기 (Learn more)

  • NavList 접근성 문서 — 내비게이션 영역의 접근성 기준을 확인하세요.
  • 깊은 내비게이션 중첩에 TreeView를 사용하지 않는 이유를 참고하세요.
  • aria-current 속성을 올바르게 사용해 현재 뷰를 표시하는 방법을 살펴보세요.