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

[TreeView] Expose the item slots at the tree view level #13867

Open
flaviendelangle opened this issue Jul 17, 2024 · 0 comments
Open

[TreeView] Expose the item slots at the tree view level #13867

flaviendelangle opened this issue Jul 17, 2024 · 0 comments
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! customization: logic Logic customizability v8.x

Comments

@flaviendelangle
Copy link
Member

flaviendelangle commented Jul 17, 2024

The following issue should only be done in v8 because I don't want to introduce an API on the tree view components that would not work with the default TreeItem component. So I'm waiting for us to drop the old customization API before doing it.

Add the following slots to the tree view components:

  • itemRoot (passed to the root slot of the TreeItem component)
  • itemContent (passed to the content slot of the TreeItem component)
  • itemGroupTransition (passed to the groupTransition slot of the TreeItem component)
  • itemIconContainer (passed to the iconContainer slot of the TreeItem component)
  • itemCheckbox (passed to the checkbox slot of the TreeItem component)
  • itemLabel (passed to the label slot of the TreeItem component)

I propose to add those to both SimpleTreeView and RichTreeView and if the slot is defined at the item level then it overrides the one at the tree view level (same as what we do for the icons).

Here is a few customization examples it would simplify:

CustomAnimation.tsx:

--- a/docs/data/tree-view/rich-tree-view/customization/CustomAnimation.tsx
+++ b/docs/data/tree-view/rich-tree-view/customization/CustomAnimation.tsx
@@ -56,7 +56,7 @@ export default function CustomAnimation() {
     <Box sx={{ minHeight: 352, minWidth: 250 }}>
       <RichTreeView
         defaultExpandedItems={['grid']}
-        slotProps={{ item: { slots: { groupTransition: TransitionComponent } } }}
+        slots={{ itemGroupTransition: TransitionComponent }}
         items={MUI_X_PRODUCTS}
       />
     </Box>

LabelSlotProps.tsx:

--- a/docs/data/tree-view/rich-tree-view/customization/LabelSlotProps.tsx
+++ b/docs/data/tree-view/rich-tree-view/customization/LabelSlotProps.tsx
@@ -34,27 +34,17 @@ const MUI_X_PRODUCTS: TreeViewBaseItem[] = [
   },
 ];
 
-const CustomTreeItem = React.forwardRef(
-  (props: TreeItem2Props, ref: React.Ref<HTMLLIElement>) => (
-    <TreeItem2
-      ref={ref}
-      {...props}
-      slotProps={{
-        label: {
-          id: `${props.itemId}-label`,
-        },
-      }}
-    />
-  ),
-);
-
 export default function LabelSlotProps() {
   return (
     <Box sx={{ minHeight: 352, minWidth: 250 }}>
       <RichTreeView
         items={MUI_X_PRODUCTS}
         defaultExpandedItems={['grid']}
-        slots={{ item: CustomTreeItem }}
+        slotProps={{
+          itemLabel: ({ itemId }) => ({
+            id: `${itemId}-label`,
+          }),
+        }}
       />
     </Box>
   );

Search keywords:

@flaviendelangle flaviendelangle added component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! v8.x labels Jul 17, 2024
@flaviendelangle flaviendelangle added the customization: logic Logic customizability label Jul 17, 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: logic Logic customizability v8.x
Projects
None yet
Development

No branches or pull requests

1 participant