components
Tailwind CSS Tree View
Use Tree View to navigate hierarchical data, making it perfect for directories, hierarchies, and more. Effortlessly expand, collapse, and select tree nodes.
Class Name | Type | Description |
---|---|---|
tree-view-space | Modifier | Style space and border for sub-menu. |
tree-view-selected:{tw-utility-class} | Modifier | A utility that applies specific Tailwind classes when an item is selected. |
tree-view-disabled:{tw-utility-class} | Modifier | A utility that applies specific Tailwind classes when an item has “disabled” class. |
accordion-heading | Component | Container class specifically for child elements within accordion-item . |
accordion-toggle | Component | This class is responsible for toggling the tree-view between open and closed states. |
accordion-content | Component | This class defines the content within each tree-view section. |
accordion-item | Component | This class represents each individual item within the tree-view structure. |
accordion-item-active | Component | This class applies styling to indicate an active item within the tree-view. |
To initialize the Tree View component, apply the data-tree-view
attribute to the wrapper element. This attribute activates the Tree View functionality on the specified element.
Each item in the Tree View is defined by the data-tree-view-item
attribute. Add this attribute to the individual item elements within the Tree View to indicate which parts of the structure are items that can be interacted with.
Utilize the provided example for Tree View. You can change icon, text as per your needs.
<div id="tree-view" class="rounded" role="tree" aria-orientation="vertical" data-tree-view="">
<!-- 1st Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="basic-tree-view-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="basic-tree-view-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">assets</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="basic-tree-view-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="tree-view-space">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="basic-tree-view-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="basic-tree-view-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">css</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="basic-tree-view-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="tree-view-space">
<!-- 3rd Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="basic-tree-view-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="basic-tree-view-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="basic-tree-view-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-sub-level-two-heading-one" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">docs.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<span class="text-base-content">README.txt</span>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="basic-tree-view-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="basic-tree-view-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="basic-tree-view-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-sub-level-two-heading-two" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">input.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<span class="text-base-content">.gitignore</span>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="basic-tree-view-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="basic-tree-view-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">img</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="basic-tree-view-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-sub-heading-two" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">hero.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">untitled.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="basic-tree-view-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="basic-tree-view-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">js</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="basic-tree-view-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-sub-heading-three" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="basic-tree-view-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="basic-tree-view-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">scripts</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="basic-tree-view-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-heading-two" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">www.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="basic-tree-view-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="basic-tree-view-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">templates</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="basic-tree-view-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="basic-tree-view-heading-three" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">index.html</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
</div>
This demo demonstrates how to close the currently open element within its group.
<div id="tree-view" class="rounded" role="tree" aria-orientation="vertical" data-tree-view="">
<div class="accordion">
<!-- 1st Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="close-currently-opened-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="close-currently-opened-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">assets</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="close-currently-opened-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="accordion tree-view-space">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="close-currently-opened-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="close-currently-opened-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">css</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="close-currently-opened-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="accordion tree-view-space">
<!-- 3rd Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="close-currently-opened-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="close-currently-opened-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="close-currently-opened-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-sub-level-two-heading-one" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">docs.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<span class="text-base-content">README.txt</span>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="close-currently-opened-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="close-currently-opened-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="close-currently-opened-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-sub-level-two-heading-two" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">input.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<span class="text-base-content">.gitignore</span>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="close-currently-opened-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="close-currently-opened-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">img</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="close-currently-opened-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-sub-heading-two" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">hero.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">untitled.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="close-currently-opened-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="close-currently-opened-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">js</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="close-currently-opened-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-sub-heading-three" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="close-currently-opened-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="close-currently-opened-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">scripts</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="close-currently-opened-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-heading-two" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">www.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="close-currently-opened-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="close-currently-opened-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">templates</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="close-currently-opened-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="close-currently-opened-heading-three" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">index.html</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
</div>
<!-- End 1st Level Accordion -->
</div>
You may select multiple folders/files by holding shift, ctrl | cmd key.
The example below demonstrates the drag-and-drop functionality for items.
<div id="tree-view-nested" class="rounded" role="tree" aria-orientation="vertical" data-tree-view="">
<!-- 1st Level Accordion Group -->
<div data-nested-draggable="">
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1 active" role="treeitem" aria-expanded="true" id="draggable-tree-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-tree-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">assets</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-tree-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2 active" role="treeitem" aria-expanded="true" id="draggable-tree-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-tree-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">css</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-tree-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-3 active" role="treeitem" aria-expanded="true" id="draggable-tree-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-tree-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="draggable-tree-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-sub-level-two-heading-one" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">docs.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 rounded-md px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<span class="text-base-content">README.txt</span>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-3" role="treeitem" aria-expanded="false" id="draggable-tree-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-tree-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="draggable-tree-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-sub-level-two-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">input.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<span class="text-base-content">.gitignore</span>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="draggable-tree-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-tree-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">img</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-tree-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-sub-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">hero.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div role="treeitem" class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">untitled.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2" role="treeitem" aria-expanded="false" id="draggable-tree-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-tree-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">js</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-tree-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-sub-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1" role="treeitem" aria-expanded="false" id="draggable-tree-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-tree-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">scripts</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-tree-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">www.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1" role="treeitem" aria-expanded="false" id="draggable-tree-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-tree-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">templates</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-tree-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-tree-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">index.html</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
</div>
<!-- End 1st Level Accordion Group -->
</div>
<!-- End Tree Root -->
<script>
window.addEventListener('load', () => {
;(function () {
const draggable = document.querySelectorAll('[data-nested-draggable]')
draggable.forEach(el => {
const options = {
group: 'nested',
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.65,
ghostClass: 'dragged',
onEnd: evt => {
const { item } = evt
if (item.classList.contains('accordion')) {
let existingInstance = HSAccordion.getInstance(item, true)
let updatedInstance
existingInstance.element.update()
updatedInstance = HSAccordion.getInstance(item, true)
window.$hsAccordionCollection.map(el => {
if (
el.element.el !== existingInstance.element.el &&
el.element.group === existingInstance.element.group &&
el.element.el.closest('.accordion') &&
el.element.el.classList.contains('active') &&
existingInstance.element.el.classList.contains('active')
)
el.element.hide()
return el
})
}
if (!!item.hasAttribute('data-tree-view-item')) {
const treeViewItem = HSTreeView.getInstance(item.closest('[data-tree-view]'), true)
treeViewItem.element.update()
}
}
}
const data = el.getAttribute('data-nested-draggable')
const dataOptions = data ? JSON.parse(data) : {}
const sortable = new Sortable(el, _.merge(options, dataOptions))
})
})()
})
</script>
The example below demonstrates drag-and-drop functionality, including the ability to close the currently open element within its group.
<!-- Tree Root -->
<div id="tree-view-nested-alt" class="rounded" role="tree" aria-orientation="vertical" data-tree-view="">
<!-- 1st Level Accordion Group -->
<div class="accordion" data-nested-draggable="">
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1 active" role="treeitem" aria-expanded="true" id="draggable-and-auto-collapse-one-level-group-tree-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div
class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5"
>
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-and-auto-collapse-one-level-group-tree-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">assets</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="accordion tree-view-space" data-nested-draggable="">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2 active" role="treeitem" aria-expanded="true" id="draggable-and-auto-collapse-one-level-group-tree-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">css</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="accordion tree-view-space" data-nested-draggable="">
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-3 active" role="treeitem" aria-expanded="true" id="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-heading-one" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">docs.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 tree-view-disabled:opacity-50 disabled px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<span class="text-base-content">README.txt</span>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-3" role="treeitem" aria-expanded="false" id="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-sub-level-two-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">input.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<span class="text-base-content">.gitignore</span>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2" role="treeitem" aria-expanded="false" id="draggable-and-auto-collapse-one-level-group-tree-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">img</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-sub-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">hero.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">untitled.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2" role="treeitem" aria-expanded="false" id="draggable-and-auto-collapse-one-level-group-tree-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">js</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-sub-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1" role="treeitem" aria-expanded="false" id="draggable-and-auto-collapse-one-level-group-tree-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="draggable-and-auto-collapse-one-level-group-tree-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">scripts</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">www.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-1 tree-view-disabled:opacity-50 disabled" role="treeitem" aria-expanded="false" id="draggable-and-auto-collapse-one-level-group-tree-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle tree-view-disabled:pointer-events-none btn btn-sm btn-circle btn-text" disabled="" aria-expanded="false" aria-controls="draggable-and-auto-collapse-one-level-group-tree-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">templates</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="draggable-and-auto-collapse-one-level-group-tree-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="draggable-and-auto-collapse-one-level-group-tree-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">index.html</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
</div>
<!-- End 1st Level Accordion Group -->
</div>
<!-- End Tree Root -->
<script>
window.addEventListener('load', () => {
;(function () {
const draggable = document.querySelectorAll('[data-nested-draggable]')
draggable.forEach(el => {
const options = {
group: 'nested',
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.65,
ghostClass: 'dragged',
onEnd: evt => {
const { item } = evt
if (item.classList.contains('accordion')) {
let existingInstance = HSAccordion.getInstance(item, true)
let updatedInstance
existingInstance.element.update()
updatedInstance = HSAccordion.getInstance(item, true)
window.$hsAccordionCollection.map(el => {
if (
el.element.el !== existingInstance.element.el &&
el.element.group === existingInstance.element.group &&
el.element.el.closest('.accordion') &&
el.element.el.classList.contains('active') &&
existingInstance.element.el.classList.contains('active')
)
el.element.hide()
return el
})
}
if (!!item.hasAttribute('data-tree-view-item')) {
const treeViewItem = HSTreeView.getInstance(item.closest('[data-tree-view]'), true)
treeViewItem.element.update()
}
}
}
const data = el.getAttribute('data-nested-draggable')
const dataOptions = data ? JSON.parse(data) : {}
const sortable = new Sortable(el, _.merge(options, dataOptions))
})
})()
})
</script>
You can select folders and files by marking the checkboxes.
<!-- Tree Root -->
<div id="tree-view-checkbox" role="tree" aria-orientation="vertical"
data-tree-view='{
"controlBy": "checkbox",
"autoSelectChildren": true
}'
>
<!-- 1st Level Accordion Group -->
<div data-nested-draggable="">
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-1 active" role="treeitem" aria-expanded="true" id="checkbox-tree-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="checkbox-tree-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="assets" value="assets" />
<label class="label label-text text-base" for="assets">assets</label>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="checkbox-tree-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-2 active" role="treeitem" aria-expanded="true" id="checkbox-tree-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="checkbox-tree-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="css" value="css" />
<label class="label label-text text-base" for="css">css</label>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="checkbox-tree-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-3 active" role="treeitem" aria-expanded="true" id="checkbox-tree-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="checkbox-tree-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="main" value="main" />
<label class="label label-text text-base" for="main">main</label>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="checkbox-tree-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-sub-level-two-heading-one" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="mainCss" value="main.css" />
<label class="label label-text text-base" for="mainCss">main.css</label>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="docs" value="docs.css" />
<label class="label label-text text-base" for="docs">docs.css</label>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-4 tree-view-disabled:opacity-50 disabled px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="readme" value="README.txt" disabled />
<label class="label label-text text-base" for="readme">README.txt</label>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-3" role="treeitem" aria-expanded="false" id="checkbox-tree-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="checkbox-tree-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="tailwind" value="tailwind" />
<label class="label label-text text-base" for="tailwind">tailwind</label>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="checkbox-tree-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-sub-level-two-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-4 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="inputCss" value="input.css" />
<label class="label label-text text-base" for="inputCss">input.css</label>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-3 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="gitignore" value=".gitignore" />
<label class="label label-text text-base" for="gitignore">.gitignore</label>
</div>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-2" role="treeitem" aria-expanded="false" id="checkbox-tree-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="checkbox-tree-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="img" value="img" />
<label class="label label-text text-base" for="img">img</label>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="checkbox-tree-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-sub-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="hero" value="hero.jpg" />
<label class="label label-text text-base" for="hero">hero.jpg</label>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="tailwindPng" value="tailwind.png" />
<label class="label label-text text-base" for="tailwindPng">tailwind.png</label>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="untitled" value="untitled.png" />
<label class="label label-text text-base" for="untitled">untitled.png</label>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-2" role="treeitem" aria-expanded="false" id="checkbox-tree-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="checkbox-tree-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="js" value="js" />
<label class="label label-text text-base" for="js">js</label>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="checkbox-tree-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-sub-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-3 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="flyonuiJpg" value="flyonui.jpg" />
<label class="label label-text text-base" for="flyonuiJpg">flyonui.jpg</label>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-1" role="treeitem" aria-expanded="false" id="checkbox-tree-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="checkbox-tree-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="scripts" value="scripts" />
<label class="label label-text text-base" for="scripts">scripts</label>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="checkbox-tree-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-heading-two" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="flyonuiJs" value="flyonui.js" />
<label class="label label-text text-base" for="flyonuiJs">flyonui.js</label>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="tailwindJS" value="tailwind.js" />
<label class="label label-text text-base" for="tailwindJS">tailwind.js</label>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="www" value="www.js" />
<label class="label label-text text-base" for="www">www.js</label>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item dragged:bg-primary/20 dragged:rounded nested-2-1 tree-view-disabled:opacity-50 disabled" role="treeitem" aria-expanded="false" id="checkbox-tree-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle tree-view-disabled:pointer-events-none btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="checkbox-tree-collapse-three" disabled="" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<span class="text-base-content">
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="templates" value="templates" disabled />
<label class="label label-text text-base" for="templates">templates</label>
</div>
</span>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="checkbox-tree-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="checkbox-tree-heading-three" >
<div class="tree-view-space" data-nested-draggable="">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 dragged:bg-primary/20 dragged:rounded nested-2-2 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-2">
<input type="checkbox" class="checkbox checkbox-xs" id="indexHtml" value="index.html" />
<label class="label label-text text-base" for="indexHtml">index.html</label>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
</div>
<!-- End 1st Level Accordion Group -->
</div>
<!-- End Tree Root -->
<script>
window.addEventListener('load', () => {
;(function () {
const draggable = document.querySelectorAll('[data-nested-draggable]')
draggable.forEach(el => {
const options = {
group: 'nested',
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.65,
ghostClass: 'dragged',
onEnd: evt => {
const { item } = evt
if (item.classList.contains('accordion')) {
let existingInstance = HSAccordion.getInstance(item, true)
let updatedInstance
existingInstance.element.update()
updatedInstance = HSAccordion.getInstance(item, true)
window.$hsAccordionCollection.map(el => {
if (
el.element.el !== existingInstance.element.el &&
el.element.group === existingInstance.element.group &&
el.element.el.closest('.accordion') &&
el.element.el.classList.contains('active') &&
existingInstance.element.el.classList.contains('active')
)
el.element.hide()
return el
})
}
if (!!item.hasAttribute('data-tree-view-item')) {
const treeViewItem = HSTreeView.getInstance(item.closest('[data-tree-view]'), true)
treeViewItem.element.update()
}
}
}
const data = el.getAttribute('data-nested-draggable')
const dataOptions = data ? JSON.parse(data) : {}
const sortable = new Sortable(el, _.merge(options, dataOptions))
})
})()
})
</script>
The destroy
method is provided to facilitate the destruction of a tree-view element.
<div id="tree-view-to-destroy" class="rounded w-fit" role="tree" aria-orientation="vertical" data-tree-view="">
<!-- 1st Level Accordion Group -->
<!-- 1st Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="destroy-tree-view-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="destroy-tree-view-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">assets</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="destroy-tree-view-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-heading-one" >
<!-- 2nd Level Accordion Group -->
<div class="tree-view-space">
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="destroy-tree-view-sub-heading-one"
data-tree-view-item='{
"value": "css",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="destroy-tree-view-sub-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">css</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="destroy-tree-view-sub-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-sub-heading-one" >
<!-- 3rd Level Accordion Group -->
<div class="tree-view-space">
<!-- 3rd Level Accordion -->
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="destroy-tree-view-sub-level-two-heading-one"
data-tree-view-item='{
"value": "main",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="destroy-tree-view-sub-level-two-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="destroy-tree-view-sub-level-two-collapse-one" class="accordion-content w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-sub-level-two-heading-one" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "main.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">main.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "docs.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">docs.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-2"
data-tree-view-item='{
"value": "README.txt",
"isDir": false
}'
>
<span class="text-base-content">README.txt</span>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="destroy-tree-view-sub-level-two-heading-two"
data-tree-view-item='{
"value": "tailwind",
"isDir": true
}'
>
<!-- 3rd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="destroy-tree-view-sub-level-two-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind</span>
</div>
</div>
</div>
</div>
<!-- End 3rd Level Accordion Heading -->
<!-- 3rd Level Collapse -->
<div id="destroy-tree-view-sub-level-two-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-sub-level-two-heading-two" >
<div class="tree-view-space">
<!-- 3rd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "input.css",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">input.css</span>
</div>
</div>
</div>
<!-- End 3rd Level Item -->
</div>
</div>
<!-- End 3rd Level Collapse -->
</div>
<!-- End 3rd Level Accordion -->
<!-- 3rd Level Heading -->
<div class="tree-view-selected:bg-base-200/60 rounded-md px-1.5 py-0.5" role="treeitem"
data-tree-view-item='{
"value": ".gitignore",
"isDir": false
}'
>
<span class="text-base-content">.gitignore</span>
</div>
<!-- End 3rd Level Heading -->
</div>
<!-- End 3rd Level Accordion Group -->
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="destroy-tree-view-sub-heading-two"
data-tree-view-item='{
"value": "img",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="destroy-tree-view-sub-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">img</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="destroy-tree-view-sub-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-sub-heading-two" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "hero.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">hero.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div role="treeitem" class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "untitled.png",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">untitled.png</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
<!-- 2nd Level Nested Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="destroy-tree-view-sub-heading-three"
data-tree-view-item='{
"value": "js",
"isDir": true
}'
>
<!-- 2nd Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="destroy-tree-view-sub-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">js</span>
</div>
</div>
</div>
</div>
<!-- End 2nd Level Accordion Heading -->
<!-- 2nd Level Collapse -->
<div id="destroy-tree-view-sub-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-sub-heading-three" >
<div class="tree-view-space">
<!-- 2nd Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.jpg</span>
</div>
</div>
</div>
<!-- End 2nd Level Item -->
</div>
</div>
<!-- End 2nd Level Collapse -->
</div>
<!-- End 2nd Level Nested Accordion -->
</div>
<!-- 2nd Level Accordion Group -->
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="destroy-tree-view-heading-two"
data-tree-view-item='{
"value": "scripts",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="destroy-tree-view-collapse-two" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">scripts</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="destroy-tree-view-collapse-two" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-heading-two" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "flyonui.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">flyonui.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "tailwind.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">tailwind.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "www.js",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">www.js</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion -->
<!-- 1st Level Accordion -->
<div class="accordion-item" role="treeitem" aria-expanded="false" id="destroy-tree-view-heading-three"
data-tree-view-item='{
"value": "templates",
"isDir": true
}'
>
<!-- 1st Level Accordion Heading -->
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="false" aria-controls="destroy-tree-view-collapse-three" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
<div class="tree-view-selected:bg-base-200/60 grow cursor-pointer rounded-md px-1.5">
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--folder] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">templates</span>
</div>
</div>
</div>
</div>
<!-- End 1st Level Accordion Heading -->
<!-- 1st Level Collapse -->
<div id="destroy-tree-view-collapse-three" class="accordion-content hidden w-full overflow-hidden transition-[height] duration-300" role="group" aria-labelledby="destroy-tree-view-heading-three" >
<div class="tree-view-space">
<!-- 1st Level Item -->
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "index.html",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--file] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">index.html</span>
</div>
</div>
</div>
<!-- End 1st Level Item -->
</div>
</div>
<!-- End 1st Level Collapse -->
</div>
<!-- End 1st Level Accordion Group -->
</div>
<!-- End Tree Root -->
<div class="mt-4 flex gap-3">
<button class="btn btn-primary" id="destroy-btn">Destroy</button>
<button class="btn btn-primary" id="reinit-btn" disabled>Reinitialize</button>
</div>
<script>
window.addEventListener('load', () => {
;(function () {
const treeView = document.querySelector('#tree-view-to-destroy')
const accordions = document.querySelectorAll('#tree-view-to-destroy .accordion-item')
const destroy = document.querySelector('#destroy-btn')
const reinit = document.querySelector('#reinit-btn')
destroy.addEventListener('click', () => {
const treeViewInstance = HSTreeView.getInstance(treeView, true)
treeViewInstance.element.destroy()
accordions.forEach(el => {
const accordionInstance = HSAccordion.getInstance(el, true)
accordionInstance.element.destroy()
})
destroy.setAttribute('disabled', 'disabled')
reinit.removeAttribute('disabled')
})
reinit.addEventListener('click', () => {
HSTreeView.autoInit()
HSAccordion.autoInit()
reinit.setAttribute('disabled', 'disabled')
destroy.removeAttribute('disabled')
})
})()
})
</script>
PARAMETERS | DESCRIPTION | OPTIONS | DEFAULT VALUE |
---|---|---|---|
data-tree-view | Activate the Tree View by applying it to the element, and ensure it is added to the wrapper. | - | - |
:controlBy | Informs the plugin of the active mode and handles events based on the selected mode. | checkbox / button | button |
:autoSelectChildren | This option is available when the controlBy parameter is set to checkbox and the item is a directory (isDir: true) . When the item is selected, all nested items inherit the value of the parent. | boolean | false |
:isIndeterminate | Applies an indeterminate visual style when the controlBy parameter is set to checkbox . | boolean | true |
data-tree-view-item | Specifies the element within the initialized component that represents the item. This should be applied to the item itself. | - | - |
:id | Optional. Desired identifier. | string | - |
:value | The value that will be included in the resulting array. | string | - |
:isDir | Determines that the element is a directory and handles it accordingly. | boolean | false |
The HSTreeView
object is contained within the global window
object.
METHOD | DESCRIPTION |
---|---|
PUBLIC METHODS | |
update() | Update the element, particularly when rearranging the order of items. |
getSelectedItems() | Returns a list of selected items. |
destroy() | Destroys the instance, removes generated markup (if any), removes added classes and attributes. |
STATIC METHODS | |
HSTreeView.getInstance(target, isInstance) | Returns the element associated to the target .
|
Below, we demonstrate how to use the update methods. Assign an ID to the data-tree-view
as shown.
<div role="tree" id="tree-view-method" aria-orientation="vertical" data-tree-view>
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="cco-four-heading-one"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="cco-four-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
assets
</div>
<div id="cco-four-collapse-one" class="accordion-content overflow-hidden px-2 transition-[height] duration-300" role="group" aria-labelledby="cco-four-heading-one" >
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "image.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">image.jpg</span>
</div>
</div>
</div>
</div>
</div>
</div>
<hr />
<button class="btn btn-outline" id="get-items-btn">Log Selected</button>
<script>
window.addEventListener('load', function () {
// Update Methods
const treeView = HSTreeView.getInstance('#tree-view-method', true)
const getItemsBtn = document.querySelector('#get-items-btn')
getItemsBtn.addEventListener('click', () => {
console.log(treeView.element.getSelectedItems())
})
})
</script>
Update Element
const treeView = HSTreeView.getInstance('#tree-view-method', true);
const updateBtn = document.querySelector('#update-btn');
updateBtn.addEventListener('click', () => {
treeView.element.update();
});
Get selected items
// This method is used in above example.
const treeView = HSTreeView.getInstance('#tree-view-method', true)
const getItemsBtn = document.querySelector('#get-items-btn')
getItemsBtn.addEventListener('click', () => {
console.log(treeView.element.getSelectedItems())
})
Destroy instance
const treeView = document.querySelector('#tree-view-to-destroy')
const accordions = document.querySelectorAll('#tree-view-to-destroy .accordion-item')
const destroy = document.querySelector('#destroy-btn')
destroy.addEventListener('click', () => {
const treeViewInstance = HSTreeView.getInstance(treeView, true)
treeViewInstance.element.destroy()
accordions.forEach(el => {
const accordionInstance = HSAccordion.getInstance(el, true)
accordionInstance.element.destroy()
})
})
METHOD | DESCRIPTION | RETURNING VALUE |
---|---|---|
on:click | Called when any item was selected. | { id: string; value: string; isDir: boolean; path: string; isSelected: boolean; } |
Just like in the methods section, assign an ID to the data-tree-view
in events. Click on the item, and observe the console
output.
<div role="tree" id="tree-view-event" aria-orientation="vertical" data-tree-view>
<div class="accordion-item active" role="treeitem" aria-expanded="true" id="cco-four-heading-one-alt"
data-tree-view-item='{
"value": "assets",
"isDir": true
}'
>
<div class="accordion-heading tree-view-selected:bg-base-200/60 flex w-full items-center gap-x-0.5 rounded-md py-0.5" >
<button class="accordion-toggle btn btn-sm btn-circle btn-text" aria-expanded="true" aria-controls="cco-four-collapse-one" >
<span class="icon-[tabler--plus] text-base-content/80 accordion-item-active:rotate-45 size-4 transition-all duration-300" ></span>
</button>
assets
</div>
<div id="cco-four-collapse-one" class="accordion-content overflow-hidden px-2 transition-[height] duration-300" role="group" aria-labelledby="cco-four-heading-one-alt" >
<div class="tree-view-selected:bg-base-200/60 cursor-pointer rounded-md px-2" role="treeitem"
data-tree-view-item='{
"value": "image.jpg",
"isDir": false
}'
>
<div class="flex items-center gap-x-3">
<span class="icon-[tabler--photo] text-base-content size-4 flex-shrink-0"></span>
<div class="grow">
<span class="text-base-content">image.jpg</span>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
window.addEventListener('load', function () {
const el = HSTreeView.getInstance('#tree-view-event', true)
el.element.on('click', data => {
console.log('data', data)
})
})
</script>
When select changes event example.
const el = HSTreeView.getInstance('#tree-view-event', true)
el.element.on('click', data => {
console.log('data', data)
})