
Shadcn Tree View
A Shadcn UI component for displaying and navigating hierarchical data, featuring expandable levels, custom icons, drag & drop, and click handlers.

Interactive Tree View Component for Shadcn UI
This Tree View component, designed for Shadcn UI, empowers developers to present hierarchical data structures in an intuitive and interactive manner. Users can easily navigate through nested levels by expanding and collapsing parent nodes. It offers a clean way to manage complex data relationships, enhancing user experience in applications requiring structured information display, such as file explorers or category trees. It supports custom icons, action buttons, and drag & drop functionality for a rich user experience.
Features:
- Item Interaction: Allows users to expand, collapse, and select elements within the hierarchical structure.
- Custom Item Icons: Supports assigning distinct icons for items based on their current state (default, open, selected).
- Default Tree Icons: Enables setting global default icons for parent nodes (expandable items) and child leaves (non-expandable items) throughout the tree.
- Action Buttons: Facilitates embedding custom interactive elements, like buttons, for each item in the tree using ReactNode.
- Click Handlers: Provides functionality to define custom actions upon clicking individual items or changing tree selection via
onSelectChange
. - Drag & Drop Support: Features built-in capability for users to reorder items using drag and drop, with per-item
draggable
anddroppable
flags. - Disabled State: Allows specific items to be marked as disabled, preventing user interaction and visually indicating their status.
- Initial Selection: Offers a prop (
initialSelectedItemId
) to pre-select a specific item when the tree component initially loads. - Selection Change Callback: Triggers a specified function (
onSelectChange
) when the selected item in the tree changes, passing the new item's data. - Expand All Option: Includes a prop (
expandAll
) to automatically expand all collapsible nodes upon the component's first render. - Flexible Data Input: Accepts
data
as either a singleTreeDataItem
object or an array ofTreeDataItem
objects. - Item-Level Customization: Permits individual items to have unique names and specific icons for default, selected, and open states.
Summary:
The Shadcn Tree View component provides a flexible and feature-rich solution for rendering hierarchical data. It allows for easy navigation of nested structures through expand/collapse actions, item selection, custom icons, and drag-and-drop capabilities. Developers can integrate this component to build sophisticated user interfaces for displaying complex data relationships, enhancing organization and usability within their Shadcn UI based applications, complete with item-specific actions and event handling.

Similar to Shadcn Tree View:


