I needed a to deal with tree data in a project as well. I ended up creating MUI Tree Select.
You can demo it in this sandbox.

GitHub
github.com › mikepricedev › mui-tree-select
GitHub - mikepricedev/mui-tree-select: Material-UI autocomplete component for tree data structures.
Material-UI autocomplete component for tree data structures. - mikepricedev/mui-tree-select
Starred by 42 users
Forked by 11 users
Languages JavaScript 55.9% | TypeScript 44.1% | JavaScript 55.9% | TypeScript 44.1%
MUI
mui.com › x › react-tree-view › simple-tree-view › selection
Simple Tree View - Selection - MUI X
Use the onItemSelectionToggle prop to react to an item selection change: ... To use the apiRef object, you need to initialize it using the useSimpleTreeViewApiRef() hook as follows: const apiRef = useSimpleTreeViewApiRef(); return <SimpleTreeView apiRef={apiRef} items={ITEMS} />; CopyCopied(or $keyC) When your component first renders, apiRef.current is undefined. After the initial render, apiRef holds methods to interact imperatively with the Tree View.
Top answer 1 of 4
10
I needed a to deal with tree data in a project as well. I ended up creating MUI Tree Select.
You can demo it in this sandbox.

2 of 4
2
I searched a lot for that in the end I made this by myself sandbox. you can choose to parent or child with this and you can custom it easily.
import { ThemeProvider, createTheme } from "@mui/material/styles";
import React, { useState } from "react";
import ReactDOM from "react-dom";
import TreeItem from "@mui/lab/TreeItem";
import { Popover, TextField, Typography } from "@mui/material";
import clsx from "clsx";
import { TreeView, useTreeItem } from "@mui/lab";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import { useMediaQuery } from "@mui/material";
const data = [
{
id: "root",
name: "Parent",
children: [
{
id: "1",
name: "Child - 1"
},
{
id: "3",
name: "Child - 3",
children: [
{
id: "4",
name: "Child - 4"
}
]
}
]
},
{
id: "1root",
name: "Parent1",
children: [
{
id: "5",
name: "Child - 1-1"
},
{
id: "7",
name: "Child - 3-1",
children: [
{
id: "8",
name: "Child - 4-1"
}
]
}
]
}
];
const CustomContent = React.forwardRef(function CustomContent(props, ref) {
const {
classes,
className,
label,
nodeId,
icon: iconProp,
expansionIcon,
displayIcon
} = props;
const {
disabled,
expanded,
selected,
focused,
handleExpansion,
handleSelection,
preventSelection
} = useTreeItem(nodeId);
const icon = iconProp || expansionIcon || displayIcon;
const handleMouseDown = (event) => {
preventSelection(event);
};
const handleExpansionClick = (event) => {
handleExpansion(event);
};
const handleSelectionClick = (event) => {
handleSelection(event);
};
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
className={clsx(className, classes.root, {
[classes.expanded]: expanded,
[classes.selected]: selected,
[classes.focused]: focused,
[classes.disabled]: disabled
})}
onMouseDown={handleMouseDown}
ref={ref}
style={{ padding: "3px 0" }}
>
<div onClick={handleExpansionClick} className={classes.iconContainer}>
{icon}
</div>
<Typography
onClick={handleSelectionClick}
component="div"
className={classes.label}
>
{label}
</Typography>
</div>
);
});
const CustomTreeItem = (props) => (
<TreeItem ContentComponent={CustomContent} {...props} />
);
export default function RichObjectTreeView({ formik, edit }) {
const [anchorEl, setAnchorEl] = React.useState(null);
const [equipmentItem, setEquipmentItem] = useState("");
const [equipmentId, setEquipmentId] = useState("");
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const open = Boolean(anchorEl);
const id = open ? "simple-popover" : undefined;
const renderTree = (nodes) => (
<CustomTreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
{Array.isArray(nodes.children)
? nodes.children.map((node) => renderTree(node))
: null}
</CustomTreeItem>
);
return (
<>
<TextField
variant="standard"
required={false}
label="Equipment Item"
name="equipmentItem"
id="equipmentItem"
defaultValue={equipmentItem}
value={equipmentItem}
className="w-100"
inputProps={{ readOnly: !edit }}
onClick={handleClick}
/>
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
>
<TreeView
aria-label="icon expansion"
defaultSelected={equipmentId}
selected={equipmentId}
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronRightIcon />}
onNodeSelect={(e, id) => {
setEquipmentId(id);
setEquipmentItem(e.target.innerText);
}}
sx={{
height: 200,
flexGrow: 1,
minWidth: "200px",
overflowY: "auto"
}}
>
{data.map((item, i) => renderTree(item))}
</TreeView>
</Popover>
</>
);
}
Mikepricedev
mikepricedev.github.io › mui-tree-select › modules.html
MUI Tree Select
Utility type that gives the tree select value type.
CodeSandbox
codesandbox.io › examples › package › mui-tree-select
mui-tree-select examples - CodeSandbox
Use this online mui-tree-select playground to view and fork mui-tree-select example apps and templates on CodeSandbox.
npm
npmjs.com › package › mui-tree-select
mui-tree-select - npm
March 10, 2023 - Material-UI auto select component for tree data structures.. Latest version: 1.0.0-beta.11, last published: 3 years ago. Start using mui-tree-select in your project by running `npm i mui-tree-select`. There are no other projects in the npm registry using mui-tree-select.
» npm install mui-tree-select
Published Mar 10, 2023
Version 1.0.0-beta.11
Author Michael Price
johnnyreilly
johnnyreilly.com › home › blog › mui react tree view: check children, uncheck parents
MUI React Tree View: check children, uncheck parents | johnnyreilly
May 25, 2024 - This is the behaviour that I'm used to in a treeview component. In action it looks like this: We can implement this behaviour by tracking the selected nodes and then determining which nodes should be selected based on the current selection. The code below demonstrates how to do this: import * as React from 'react'; import Box from '@mui/material/Box'; import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; import { TreeViewBaseItem } from '@mui/x-tree-view/models'; const MUI_X_PRODUCTS: TreeViewBaseItem[] = [ { id: 'grid', label: 'Data Grid', children: [ { id: 'grid-community', label: '@
GitHub
github.com › dashty94 › mui-treeselect-component
GitHub - dashty94/mui-treeselect-component: A material ui treeselect component
import React from 'react'; import ReactDOM from 'react-dom'; import { Treeselect } from 'mui-treeselect-component'; function App() { return ( <> <Treeselect data={[ { id: '1', item: 'Item 1' }, { id: 2, item: 'Item 2', children: [{ id: 3, item: 'Item 3' }] } ]} label="Treeselect" idKey="id" valueKey="item" onChange={ ((value) => { //do something with selected value console.log(value); }, (dir = 'ltr')) } /> </> ); } ReactDOM.render(<App />, document.querySelector('#app')); Prop ·
Author dashty94
Mikepricedev
mikepricedev.github.io › mui-tree-select › interfaces › TreeSelectProps.html
TreeSelectProps | MUI Tree Select
Omit<AutocompleteProps<Node | TreeSelectFreeSoloValueMapping<Node, FreeSolo>, Multiple, DisableClearable, FreeSolo>, keyof UseTreeSelectProps<Node, Multiple, DisableClearable, FreeSolo> | "loading" | "options" | "renderOption" | "renderTags"> ... Retrieve the child nodes of node. ... Rejections must be handled when returning a Promise. When null, the caller is requesting root select options.
CodeSandbox
codesandbox.io › p › sandbox › mui-tree-select-2tgb4
mui-tree-select
CodeSandbox is a cloud development platform that empowers developers to code, collaborate and ship projects of any size from any device in record time.
GitHub
github.com › djheroez › mui-tree-select
GitHub - djheroez/mui-tree-select: A Select component with a TreeView dropdown
A Select that allows users to choose an option from a TreeView · Designed to easily work with React MUI and form frameworks such as React Hook Form and Formik.
Author djheroez
GitHub
github.com › mui › mui-x › issues › 12802
[tree view] How to have Selectable Tree component · Issue #12802 · mui/mui-x
April 16, 2024 - The problem in depth I want to have a Tree which I can check/Uncheck childrens, please take a look on a demo that I created before I've searched on MUIX documentation but did not found a soluti...
Author Aberkati
GitHub
github.com › mui › material-ui › issues › 16795
[Treeview] Node selection support · Issue #16795 · mui/material-ui
July 29, 2019 - No event is fired at node selection, onNodeToggle event doesn't fire for leaf nodes, onClick event can be attached to each TreeItem as a workaround, however it doesn't support keyboard action.
Author zjaml
Material-UI
v4.mui.com › components › tree-view
Tree View React component - Material-UI [v4]
Tree views also support multi selection.
Telerik
telerik.com › components › treeview › selection › updating selected items
React TreeView Selection Updating Selected Items - KendoReact
Learn how to work with TreeView data and update the selectable TreeView nodes by using the available approaches supported by the KendoReact TreeView in React projects.