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

트리(Tree)

원문 보기 위키 갱신

Arco Design의 Data Display 컴포넌트인 Tree는 폴더, 카탈로그, 조직 구조처럼 많은 단계로 이루어진 콘텐츠의 계층 관계를 명확하게 보여주고, 펼치기·접기·선택 같은 인터랙티브 기능을 갖추고 있어요.

출처: 문서

본문

API

Tree

속성 설명 타입 기본값 버전
autoExpandParent 부모 노드를 자동으로 펼칠지 여부 boolean true -
blockNode 남은 가로 공간을 차지할지 여부 boolean - -
checkable 노드 앞에 체크박스를 추가할지 여부 boolean - -
checkStrictly 부모-자식 연관 관계를 끊을지 여부 boolean - -
draggable 노드를 드래그할 수 있는지 여부 boolean - -
multiple 여러 개 선택을 지원할지 여부 boolean - -
selectable 선택할 수 있는지 여부 boolean true -
showLine 연결선을 표시할지 여부 boolean - -
size 크기를 설정해요 'mini' | 'small' | 'default' | 'large' - -
actionOnClick 노드를 클릭했을 때의 동작 ActionOnClick | ActionOnClick[] - select
allowDrop 노드에 드롭하는 것을 허용할지 여부 (dragNode는 2.23.0부터) AllowDrop () => true 2.7.0
checkedKeys 체크된 노드의 key (controlled) string[] - -
checkedStrategy 반환 값을 커스터마이징해요
all: 선택된 모든 노드를 반환해요
parent: 부모와 자식 노드가 모두 선택되었을 때 부모 노드만 반환해요
child: 자식 노드만 반환해요
SHOW_ALL | SHOW_PARENT | SHOW_CHILD all -
className 추가 css 클래스 string | string[] - -
defaultCheckedKeys 기본으로 체크되는 노드의 key string[] - -
defaultExpandedKeys 기본으로 펼쳐지는 노드의 key string[] - -
defaultSelectedKeys 기본으로 선택되는 노드의 key string[] - -
expandedKeys 펼쳐진 노드의 key (controlled) string[] - -
fieldNames key, title, isLeaf, disabled, children의 커스텀 필드 이름 FieldNamesType - 2.11.0
halfCheckedKeys 반쯤 체크된(half checked) 노드의 key들 string[] - 2.27.0
loadMore 비동기로 데이터를 로드할 때의 콜백이고, Promise를 반환해요 (node: NodeInstance) => Promise<void> - -
onDragEnd 노드가 드래그를 끝냈을 때의 콜백 (e: DragEvent<HTMLSpanElement>, node: NodeInstance) => void - -
onDragLeave 노드가 유효한 대상에서 벗어났을 때의 콜백 (e: DragEvent<HTMLSpanElement>, node: NodeInstance) => void - -
onDragOver 노드가 유효한 대상 위로 드래그되었을 때의 콜백 (e: DragEvent<HTMLSpanElement>, node: NodeInstance) => void - -
onDragStart 노드가 드래그를 시작했을 때의 콜백 (e: DragEvent<HTMLSpanElement>, node: NodeInstance) => void - -
onDrop 노드가 유효한 대상에 드롭되었을 때의 콜백 (info: {e: DragEvent<HTMLSpanElement>;dragNode: NodeInstance | null;dropNode: NodeInstance | null;dropPosition: number;}) => void - -
selectedKeys 선택된 노드의 key (controlled) string[] - -
style 추가 스타일 CSSProperties - -
treeData treeData를 전달하면 트리 구조를 생성할 수 있어요 TreeDataType[] - -
virtualListProps 가상 리스트(virtual-list) 속성을 전달해요. 이 파라미터를 넘기면 가상 스크롤이 켜져요 AvailableVirtualListProps - 2.11.0
icons 노드 아이콘을 커스터마이징해요 | ((nodeProps: NodeProps) => {dragIcon?: ReactNode;switcherIcon?: ReactNode;loadingIcon?: ReactNode;})| {dragIcon?: ReactNode;switcherIcon?: ReactNode;loadingIcon?: ReactNode;} FieldNamesType 2.9.0
onCheck 노드를 체크했을 때의 콜백 (checkedKeys: string[],extra: {node: NodeInstance;checkedNodes: NodeInstance[];checked: boolean;halfCheckedKeys: string[];halfCheckedNodes: NodeInstance[];e: Event;}) => void - -
onExpand 노드를 펼치거나 접었을 때의 콜백 (expandedKeys: string[],exra?: { expanded: boolean; node: NodeInstance; expandedNodes: NodeInstance[] }) => void - -
onSelect 노드를 선택했을 때의 콜백 (selectedKeys: string[],extra: {selected: boolean;selectedNodes: NodeInstance[];node: NodeInstance;e: Event;}) => void - -
renderExtra 추가 노드를 렌더링해요 (props: NodeProps) => ReactNode - -
renderTitle title 렌더링을 커스터마이징해요 (props: NodeProps) => ReactNode - -

Tree.Node

속성 설명 타입 기본값
checkable 체크박스를 표시할지 여부 boolean -
disableCheckbox 체크를 비활성화할지 여부 boolean -
disabled 노드를 비활성화할지 여부 boolean -
draggable 현재 노드를 드래그할 수 있는지 여부 boolean -
isLeaf 리프(leaf) 노드인지 여부예요. 동적으로 로드할 때 유효해요 boolean -
selectable 선택할 수 있는지 여부 boolean true
icons 노드 아이콘을 커스터마이징해요. Tree보다 우선순위가 높아요. Tree의 icons 속성이 동시에 설정되면 병합돼요. TreeProps['icons'] -
icon 커스텀 아이콘 ReactNode -
title 노드의 제목 string | ReactNode -
className 추가 css 클래스 string | string[] -
style 추가 스타일 CSSProperties -

AllowDrop

export type AllowDrop = (options: {
  dropNode: NodeInstance;
  dragNode: NodeInstance | null;
  dropPosition: number;
}) => boolean;

TreeDataType

export type TreeDataType = NodeProps & {
  key?: string;
  _index?: number;
  children?: TreeDataType[];
  [key: string]: any;
};

FieldNamesType

export type FieldNamesType = {
  key?: string;
  title?: string;
  disabled?: string;
  children?: string;
  isLeaf?: string;
  disableCheckbox?: string;
  checkable?: string;
};

AvailableVirtualListProps

export type AvailableVirtualListProps = Pick<
  VirtualListProps<any>,
  | "height"
  | "itemHeight"
  | "threshold"
  | "isStaticItemHeight"
  | "scrollOptions"
  | "onScroll"
  | "wrapperChild"
>;

ActionOnClick

export type ActionOnClick = "select" | "check" | "expand";

NodeInstance

export type NodeInstance = ReactElement<
  PropsWithChildren<NodeProps>,
  typeof TreeNode
>;

VirtualListProps

속성 설명 타입 기본값
height 볼 수 있는 영역의 높이 (2.11.0부터 80% 같은 string 타입 지원) number 200
threshold 가상 스크롤을 자동으로 켜는 요소 개수 임계값이에요. null을 넘기면 가상 스크롤이 꺼져요. number | null 100
isStaticItemHeight 같은 높이의 정적 요소인지 여부 boolean true

더 알아보기 (Learn more)

더 자세한 내용은 Arco Design 공식 문서에서 확인할 수 있어요.