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.

Answer from Michael Price on Stack Overflow
🌐
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.
🌐
MUI
mui.com › x › react-tree-view › rich-tree-view › selection
Rich Tree View - Selection - MUI X
Data Grid · Date and Time Pickers ... the mouse in two ways: To select multiple independent items, hold Ctrl (or ⌘ Command on macOS) and click the items....
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>
    </>
  );
}
🌐
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
🌐
MUI
mui.com › x › react-tree-view
Tree View React component - MUI X
Free forever under MIT license. Includes core features such as expansion, selection, and label editing.
🌐
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: '@
Find elsewhere
🌐
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.
🌐
MUI
mui.com › x › react-tree-view › tree-item-customization
Tree Item Customization - MUI X
You can select a TreeItem in a Tree View by clicking its content slot. The demo below shows how to handle selection when the user clicks on an icon. ... <RichTreeView defaultExpandedItems={['grid', 'pickers']} items={MUI_X_PRODUCTS} slots={{ ...
🌐
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 › 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
🌐
MUI
mui.com › x › api › tree-view › tree-item
TreeItem API - MUI X
Simple Tree View - Selection · Tree Item customization · import { TreeItem } from '@mui/x-tree-view/TreeItem'; // or import { TreeItem } from '@mui/x-tree-view'; // or import { TreeItem } from '@mui/x-tree-view-pro'; Learn about the difference by reading this guide on minimizing bundle size.
🌐
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.
🌐
MUI
mui.com › blog › lab-tree-view-to-mui-x
The Tree View is moving to MUI X - MUI
August 21, 2023 - The Tree View is a component to represent hierarchical data presented as nodes in a tree-like format. The component allows to select one or multiple nodes. MUI X is a collection of advanced components built for complex use cases.