본문으로 건너뛰기

Tree View ​

Tree View는 폴더 구조처럼 위아래 관계가 있는 항목을 펼치고 접으며 보여 주는 목록입니다. 주로 데이터 카탈로그의 분류, 파일 구조, 조직도처럼 계층이 있는 데이터를 탐색할 때 사용됩니다. 화살표를 누르면 하위 항목이 펼쳐지고, checkable을 켜면 체크박스로 여러 항목을 한 번에 고를 수 있습니다.

State ​

Code ​

vue
<script setup>
import { ref } from 'vue'
import { Plus } from '@lucide/vue'
import { ATreeView } from '@mobigen/rnd-design-system'

const selected = ref(null)
const expanded = ref(['env'])
const checked = ref([])
const items = [
  {
    id: 'env',
    label: '환경',
    children: [
      { id: 'air', label: '대기질' },
      { id: 'water', label: '수질' }
    ]
  },
  { id: 'traffic', label: '교통' }
]
</script>

<template>
  <ATreeView
    v-model="selected"
    v-model:expanded="expanded"
    v-model:checked="checked"
    :items="items"
    checkable
    aria-label="데이터 카탈로그"
  >
    <template #actions="{ node }">
      <button v-if="node.children" type="button" :aria-label="`${node.label} 하위 항목 추가`">
        <Plus :size="16" />
      </button>
    </template>
  </ATreeView>
</template>

Props ​

속성값
items[{ id, label, children, hasChildren, loading, icon, count, disabled }]
modelValueString, Number
expandedArray
checkabletrue, false
checkedid[]
showIconstrue, false
indentNumber
ariaLabelString
loadingLabelString

Events ​

이벤트전달 값
update:modelValueid
update:expandedid[]
update:checkedid[]
selectnode
expandnode

Slots ​

슬롯전달 값
actions{ node, level }

Notes ​

  • 키보드로 위아래 화살표는 이동, 오른쪽 화살표는 펼치기, 왼쪽 화살표는 접기 또는 상위 항목으로 이동, Enter는 선택이다. Space는 checkable이 켜져 있으면 체크, 아니면 선택이다.
  • checked에는 자식이 없는 끝 노드의 id만 들어간다. 상위 노드는 하위 노드가 모두 체크되면 체크로, 일부만 체크되면 가로선으로 표시된다.
  • actions 슬롯의 버튼은 마우스를 올리거나 포커스가 있거나 선택된 줄에서만 보인다. 터치 화면에서는 항상 보인다.
  • id는 전체 트리에서 겹치지 않아야 한다.
  • 항목이 수천 개를 넘으면 화면이 느려질 수 있다. 하위 항목은 펼칠 때 불러오는 방식을 권장한다.
  • 펼칠 때 불러오려면 노드에 hasChildren: true를 주고 children은 비워 둔다. 펼치는 순간 expand 이벤트가 노드와 함께 발생하므로, 그때 loading을 켜고 불러온 뒤 children을 채우고 loading을 끈다.
  • hasChildren을 주지 않으면 children에 항목이 하나 이상 있을 때만 펼칠 수 있는 노드로 본다.
  • expand 는 펼칠 때만 발생하고 접을 때는 발생하지 않는다. 이미 불러온 노드인지는 호출부가 확인한다.