Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tree view] Label editing with custom TreeItem #14674

Open
KaralyosBela opened this issue Sep 19, 2024 · 1 comment
Open

[tree view] Label editing with custom TreeItem #14674

KaralyosBela opened this issue Sep 19, 2024 · 1 comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! customization: extend Logic customizability status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@KaralyosBela
Copy link

KaralyosBela commented Sep 19, 2024

The problem in depth

I'm having trouble getting the labelEditing experimental feature to work with a custom TreeItem when using RichTreeViewPro. According to the MUI documentation, there's an example of using a custom TreeItem with the RichTreeViewPro component here. However, when I add the experimentalFeatures={{ labelEditing: true }} and the isItemEditable part, it doesn't seem to function as expected.

Am I missing something, or is there an additional step I need to take to make this work?

Your environment

Chrome
"@mui/base": "^5.0.0-beta.26",
"@mui/icons-material": "^5.14.19",
"@mui/lab": "5.0.0-alpha.141",
"@mui/material": "^5.15.14",
"@mui/styles": "^5.14.20",
"@mui/x-data-grid-premium": "^7.15.0",
"@mui/x-license": "^7.0.0",
"@mui/x-tree-view": "^7.2.0",
"@mui/x-tree-view-pro": "^7.16.0",

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: rich tree view, label renaming, custom tree item
Order ID: 86461

@KaralyosBela KaralyosBela added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Sep 19, 2024
@github-actions github-actions bot added component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ labels Sep 19, 2024
@michelengelen
Copy link
Member

michelengelen commented Sep 19, 2024

This is because the custom label does not change between editing state and normal state. For this to work you need to get the itemState like this:

const {
disabled,
expanded,
selected,
focused,
editing,
editable,
disableSelection,
checkboxSelection,
handleExpansion,
handleSelection,
handleCheckboxSelection,
handleContentClick,
preventSelection,
expansionTrigger,
toggleItemEditing,
} = useTreeItemState(itemId);

And then render an input based on the editable property. Like this:

{editing ? (
<TreeItem2LabelInput {...labelInputProps} className={classes.labelInput} />
) : (
<div className={classes.label} {...(editable && { onDoubleClick: handleLabelDoubleClick })}>
{label}
</div>
)}

Warning

The label editing feature is still experimental. Any future release might include breaking changes.

@michelengelen michelengelen changed the title Rich tree view label editiing with custom tree item [tree view] Label editing with custom TreeItem Sep 19, 2024
@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: extend Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! customization: extend Logic customizability status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

2 participants