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

[docs] TreeItem2 customization #12719

Closed
sdancer75 opened this issue Apr 9, 2024 · 4 comments
Closed

[docs] TreeItem2 customization #12719

sdancer75 opened this issue Apr 9, 2024 · 4 comments
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation recipe status: waiting for author Issue with insufficient information support: docs-feedback Feedback from documentation page

Comments

@sdancer75
Copy link

sdancer75 commented Apr 9, 2024

Related page

https://mui.com/x/api/tree-view/tree-item-2/

Kind of issue

Missing information

Issue description

There is not enough documentation and examples how to customize the TreeItem2 with css.

For example, how to change the bgColor on the selected TreeItem2?

The css classes are not exported from the TreeItem2 component and almost all examples concerns the old TreeItem even when rich item tree is used.

Context

To customize my own TreeItem2

Search keywords: TreeItem2

@sdancer75 sdancer75 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Apr 9, 2024
@zannager zannager added docs Improvements or additions to the documentation component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! labels Apr 9, 2024
@flaviendelangle
Copy link
Member

Hi,

We should indeed improve the documentation around this component.
For the classes, you can import the one of TreeItem, they are shared across the two components to make the migration easier.
Most CSS customization should be identical between the two components.

@michelengelen michelengelen added recipe and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 10, 2024
@sdancer75
Copy link
Author

sdancer75 commented Apr 11, 2024

When you keep the same name for one component ie classes but you change all others ie TreeItem2Root, TreeItem2Content, etc is confusing.

Anyway, using the same example from react-tree-view headless API from https://mui.com/x/react-tree-view/rich-tree-view/customization/#headless-api I can not change the background color of the selected item.

My codesandbox is here

https://codesandbox.io/p/sandbox/condescending-merkle-5pk7wt?file=%2Fsrc%2FDemo.js%3A39%2C16

I unsuccessfully tried to customize the context with this code. Any recommendation for that?

const CustomTreeItemContent = styled(TreeItem2Content)(({ theme }) => ({
  [`&.Mui-focused, &.Mui-selected, &.Mui-selected.Mui-focused`]: {
    backgroundColor: "red",
    color: "white",
  },
}));

@flaviendelangle
Copy link
Member

Sorry for the super long delay
We do not add the classes to the slots when using the headless API, because we don't want to be opinionated on this.
Depending on what the team working on our headless components decides, we might introduce data attributes in the future but this is not standardized yet.

You can add the classes you need yourself, see the updated example

@flaviendelangle flaviendelangle added the status: waiting for author Issue with insufficient information label Jul 16, 2024
Copy link

The issue has been inactive for 7 days and has been automatically closed.

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! docs Improvements or additions to the documentation recipe status: waiting for author Issue with insufficient information support: docs-feedback Feedback from documentation page
Projects
None yet
Development

No branches or pull requests

4 participants