百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-super-treeview

> 前端框架
开源

最后,一个可在各个层面进行自定义的 React Treeview 组件

100 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

最后,一个可在各个层面进行自定义的 React Treeview 组件

React Super Treeview

:clap: Finally, a React Treeview component which is customizable on every level.

Add/remove nodes, put your own animation, load data asynchronously, and even multi-select

:star2: See Demo w/ Example code

Gif feature demo

shift + click multi-select gmail-style

Full Features

  • Expand/Collapse
  • Checkbox
  • Delete button
  • Provide custom delete button
  • Asynchronously load data
  • Provide custom loading indicator
  • Delete animation
  • Unlimited nesting
  • Granular control over when to show expand, checkbox or delete options
  • Multi-select/unselect checkbox (shift + Check) like Gmail
  • Control the node adding/delete animation speed

How to install

npm install react-super-treeview --save

Basic Usage

Start using the component in just 2 steps.

Step 1: Import and use component in React:

…

Step 2: Import styles to project

Import SuperTreeview styles with css or scss file.

The styles are in node_modules/react-super-treeview/dist/style.css or style.scss

Note: When you use the scss file, you can modify the style variables for quick styling.

Using webpack

If you are using webpack, put this in your project's styles.

~react-super-treeview/dist/style.css 

or scss

~react-super-treeview/dist/style.scss

the tilda ~ tells webpack to pick-up the file from node_modules folder

Manually importing styles

You can also manually copy the css/scss file from node_modules/react-super-treeview/dist/style.(s)css and put it in your project files

All Props

Required Props *

Props Type Default Description
data * array none Data that will be displayed in the tree.
onUpdateCb * function none Function callback when data gets changed (deleted, expanded/collapsed, checked/unchecked).
depth number 0 Value that tracks the depth of the node tree. The root/highest depth is 0. Children nodes are depth+1 upto infinity.
deleteElement element `
` Element that displays as the delete button.
getStyleClassCb function (node, depth) => { return ' '; } Return the class name string you want to add on the node.
isCheckable function (node, depth) => { return true; } Return true/false to show/hide checkbox on node.
isDeletable function (node, depth) => { return true; } Return true/false to show/hide delete button on node.
isExpandable function (node, depth) => { return true; } Return true/false to show/hide expand/collapse button (►) on node.
keywordChildren string 'children' Set the key where the component should look for the children elements.
keywordChildrenLoading string 'isChildrenLoading' Set the key that indicates if the children nodes are loading or now. If true then the loadingElement is shown. NOTE: Make sure that the node is expanded (isExpanded: true) for the loadingElement.
keywordKey string 'id' This is the value that is set as the key attribute on the node (`
). It defaults to the id` key. This must be a unique key, if not provided or is not unique, will break the animation feature.
keywordLabel string 'name' The node text is printed from the name key. If you want some other key value to be printed, provide the key here.
loadingElement element `
` Element that shows when data is being loading. Provide your custom loading element with this prop.
noChildrenAvailableMessage string 'no data found' Message that shows when the expanded node has no children.
onCheckToggleCb function (arrayOfNodes, depth) => {} Function callback when checkbox gets toggled. The callback provides an array of nodes (arrayOfNodes) that got checked/unchecked. Since `` has a multi-select feature, hence its an array here. All nodes will have the same isChecked state, either true or false. The callback also provides the depth of the node that got checked/unchecked.
onDeleteCb function (node, updatedData, depth) => { return true; } Function callback when node delete button gets clicked. The callback provides the node being deleted, its depth, and the updated data (updatedData) with the deleted node removed. Return true if you want to proceed with the deletion, and false if you do not want to delete the node. Returning true will trigger the onUpdateCb() prop, discussed below.
onExpandToggleCb function (node, depth) => {} Function callback when node Expands/Collapses. The callback function provides the node that got toggled, and its depth.
transitionEnterTimeout number 1200 Time in milliseconds for node appear animation.
transitionExitTimeout number 1200 Time in milliseconds for node remove

Data Format

[
    {
        id: 1,
        name: 'Any String',
        isExpanded: true,
        isChecked: true,
        isChildrenLoading: false
        children: [
            id: 2,
            name: 'Any String',
            isExpanded: true,
            isChecked: true,
            isChildrenLoading: true
            children: []
        ]
    }
];

Test

bash
npm test

Shoutout

Shoutout to Andrew Onyshchuk for suggesting a clean API exposing strategy.

Thank you TJ Hubert and Prashanth Naika for your contribution to the animation feature and the bug fixes.

TODO:

  • Bug: keywordKey prop is not being applied
  • Feature: Make user friendly prop names for keywordKey, keywordChildren etc
  • Performance: Remove the need for lodash
  • Feature: Stretch goal: Add ability to add custom decorator/element per node
  • Feature: Add css class on nodes based on its state i.e
  • Feature: Provide .scss file with configurable variables
  • Workflow: Provide auto-launch browser feature when examples are run with npm run examples

License

SuperTreeview is MIT licensed.

Issues· 36 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcheckboxcollapsecustomizablereact

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架