Tree
A recursive, hierarchical list component powered by Reka UI where folders expand and leaf items are selectable.
Installation
npx raya-ui@latest add treeFile Structure
your-project
components
ui
tree
Tree.vue
API Reference
Props
itemsArray[]The hierarchical recursive data array to render.
modelValueany | any[]The currently selected item(s). Use standard v-model binding.
multiplebooleanfalseAllows multiple selections. When true, modelValue must be an array.
expandedstring[][]An array of the currently expanded folder keys. Use v-model:expanded binding.
selectionBehaviorenum"toggle"Controls selection behavior. replace deselects others on click (unless modifier key is held). toggle naturally adds/removes.
labelKeystring"label"The object property key to use for the item's label text.
childrenKeystring"children"The object property key to use to identify nested children arrays.
Slots
#itemOverrides the default rendering for each tree item. Provides { item, expanded, selected, indeterminate } in the slot scope.
- app
- components
- Button.vue
- Card.vue
- Tree.vue
- pages
- assets
- package.json
- README.md
Expanded Folders
[
"app",
"components"
]Active Selection
nullSettings
Allow selecting multiple files.
source-code.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Tree } from '@/components/ui/tree'
import { Folder, File, FileCode, Image as ImageIcon, Archive } from 'lucide-vue-next'
const items = [
{
label: 'app',
icon: Folder,
children: [
{
label: 'components',
icon: Folder,
children: [
{ label: 'Button.vue', icon: FileCode },
{ label: 'Card.vue', icon: FileCode }
]
},
{
label: 'pages',
icon: Folder,
children: [
{ label: 'index.vue', icon: FileCode }
]
}
]
},
{ label: 'package.json', icon: Archive }
]
const selection = ref()
const expanded = ref(['app'])
</script>
<template>
<Tree
v-model="selection"
v-model:expanded="expanded"
:items="items"
/>
</template>