Tree View
Tree View
A tree view that assembles all the functionalities of the Accordion component to create a tree view.
Installation
Why there is two components?
The TreeView component has two different ways to be used, that you can choose , based on your choice , that you have picked in the installation section.
-
The first approach is the
tree-view
component that is based on thetree-view-api
components, in other words it is a wrapper for devs that don't want to have an custom functionality, but you still have the access to customise the ui , some of the benifits are :- Full control over the UI.
- All functionality is provided out of the box , including the (Virtualization , Selection , Expend/Collapse , Keyboard Navigation).
- You can customise the functionality if you want.
-
The second approach is the
tree-view-api
component that is based on the radix-ui-accordion components, and it is the primitive api that you can use to build your own custom tree view, some of the benifits are:- Full control over the UI.
- You can customise the functionality as you want.
API Reference
prop | type | default value |
---|---|---|
initialSelectedId | string | -- |
expendAll | boolean | false |
elements* | TreeViewElement[] | -- |
initialExpendedItems | string[] | -- |
openIcon | ReactNode | <FolderOpenIcon /> |
closeIcon | ReactNode | <FolderIcon /> |
fileIcon | ReactNode | <FileIcon /> |
TreeViewElement
The TreeViewElement object accepts the following props:
field | type | default Value |
---|---|---|
id* | string | -- |
name* | string | -- |
children | TreeViewElement[] | -- |
isSelectable | boolean | -- |
Accessibility
Currently, the TreeView component is fully accessible and supports keyboard navigation.
Keyboard Navigation
key | Description |
---|---|
Tab | enter a nested folder |
Tab + Shift | exit the current selected folder |
ArrowDown | Increments by one step horzintanly |
ArrowUp | Decrements by one step horzintanly |
Enter | Opens/Close a folder , select a file |
Usage
The TreeView component has two different ways to be used, that you can choose , based on your choice , that you have picked in the installation section.