question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TreeItem ContentComponent custom props

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Custom props are not possible in typescript currently.

Expected Behavior 🤔

Type should be more open: ContentProps?: React.HTMLAttributes<HTMLElement>;

Steps to Reproduce 🕹

  • Use typescript
  • Create custom ContentComponent with additional custom prop
  • Try to pass custom prop via ContentProps

Context 🔦

I’m trying to use Link instead of handleSelection callback to use native browser navigation. Sounds this legit?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

2reactions
vaimeocommented, Mar 31, 2022

I found the way as mentioned on following document: https://github.com/mui/material-ui/blob/512896973499adbbda057e7f3685d1b23cc02de9/docs/src/components/productX/XTreeViewDemo.tsx

Step1 Add custom property along TreeItemContentProps on custom component create

 const CustomContentChildContent = React.forwardRef(function CustomContent(
        props: TreeItemContentProps & { myCustomData?: string },
        ref,
    )

Step2 Add custom property to with TreeItemProps

const CustomTreeItemChild = (
  props: TreeItemProps & {
    ContentProps?: { myCustomData?: string };
  },
) => <StyledTreeItem ContentComponent={CustomContentChildContent} {...props} />;

Step3

Add property in the component you are calling <CustomTreeItemChild nodeId="3" label={item.name} ContentProps={{ myCustomData: 'anything-i-can-pass' }} />

0reactions
vaimeocommented, Mar 30, 2022

Any working snippet here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material-UI - How to pass custom props to a custom TreeItem?
Step1 Add custom property along TreeItemContentProps on custom component create const CustomContentChildContent = React.
Read more >
TreeItem API - Material UI - MUI
TreeItem API. API reference docs for the React TreeItem component. Learn about the props, CSS, and other APIs of this exported module.
Read more >
Material-UI TreeView - How to get the nodeId of the TreeItem ...
Unfortunately, this props was removed in Material-UI 5.0.0 alpha-12 in favor of ContentComponent . This API requires you to write significantly more code, ......
Read more >
React MUI TreeItem API - GeeksforGeeks
ContentComponent : It should be a TreeItemContent and used as a content node. ContentProps: It is used for content props. disabled: It is...
Read more >
Tree View (Vue arborescente) - material-ui - GitLab - CREATE
title: Tree View React component components: TreeView, TreeItem ... You can use the ContentComponent prop and the useTreeItem hook to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found