diff --git a/docs/data/pages.ts b/docs/data/pages.ts
index 3977bf50b95af..ee4684125d361 100644
--- a/docs/data/pages.ts
+++ b/docs/data/pages.ts
@@ -482,7 +482,6 @@ const pages: MuiPage[] = [
children: [
{ pathname: '/x/react-tree-view', title: 'Overview' },
{ pathname: '/x/react-tree-view/getting-started' },
- { pathname: '/x/react-tree-view/accessibility' },
{
pathname: '/x/react-tree-view/simple-tree-view',
subheader: 'Simple Tree View',
@@ -505,6 +504,14 @@ const pages: MuiPage[] = [
{ pathname: '/x/react-tree-view/rich-tree-view/focus' },
],
},
+ {
+ pathname: '/x/react-tree-view/common-features',
+ subheader: 'Common features',
+ children: [
+ { pathname: '/x/react-tree-view/accessibility' },
+ { pathname: '/x/react-tree-view/tree-item-customization', title: 'Item customization' },
+ ],
+ },
{
pathname: '/x/api/tree-view-group',
title: 'API Reference',
diff --git a/docs/data/tree-view/tree-item-customization/IndentationAtItemLevel.js b/docs/data/tree-view/tree-item-customization/IndentationAtItemLevel.js
new file mode 100644
index 0000000000000..5a8f88b88527b
--- /dev/null
+++ b/docs/data/tree-view/tree-item-customization/IndentationAtItemLevel.js
@@ -0,0 +1,36 @@
+import * as React from 'react';
+import Box from '@mui/material/Box';
+
+import { RichTreeView } from '@mui/x-tree-view/RichTreeView';
+
+const MUI_X_PRODUCTS = [
+ {
+ id: 'grid',
+ label: 'Data Grid',
+ children: [
+ { id: 'grid-community', label: '@mui/x-data-grid' },
+ { id: 'grid-pro', label: '@mui/x-data-grid-pro' },
+ { id: 'grid-premium', label: '@mui/x-data-grid-premium' },
+ ],
+ },
+ {
+ id: 'pickers',
+ label: 'Date and Time Pickers',
+ children: [
+ { id: 'pickers-community', label: '@mui/x-date-pickers' },
+ { id: 'pickers-pro', label: '@mui/x-date-pickers-pro' },
+ ],
+ },
+];
+
+export default function IndentationAtItemLevel() {
+ return (
+
Learn how to customize the Tree Item component.
+ +## Basics + +### Change nested item's indentation + +Use the `itemChildrenIndentation` prop to change the indentation of the nested items. +By default, a nested item is indented by `12px` from its parent item. + +{{"demo": "ItemChildrenIndentationProp.js"}} + +:::success +This feature is compatible with both the `TreeItem` and `TreeItem2` components +If you are using a custom Tree Item component, and you want to override the padding, +then apply the following padding to your `groupTransition` element: + +```ts +const CustomTreeItem2GroupTransition = styled(TreeItem2GroupTransition)(({ theme }) => ({ + // ...other styles + paddingLeft: `var(--TreeView-itemChildrenIndentation)`, +} +``` + +If you are using the `indentationAtItemLevel` prop, then instead apply the following padding to your `content` element: + +```ts +const CustomTreeItem2Content = styled(TreeItem2Content)(({ theme }) => ({ + // ...other styles + paddingLeft: + `calc(${theme.spacing(1)} + var(--TreeView-itemChildrenIndentation) * var(--TreeView-itemDepth))`, +} +``` + +::: + +### Apply the nested item's indentation at the item level + +By default, the indentation of nested items is applied by the `groupTransition` slot of its parent (i.e.: the DOM element that wraps all the children of a given item). +This approach is not compatible with upcoming features like the reordering of items using drag & drop. + +To apply the indentation at the item level (i.e.: have each item responsible for setting its own indentation using the `padding-left` CSS property on its `content` slot), +you can use the `indentationAtItemLevel` experimental feature. +It will become the default behavior in the next major version of the Tree View component. + +{{"demo": "IndentationAtItemLevel.js"}} + +:::success +This feature is compatible with both the `TreeItem` and `TreeItem2` components and with the `itemChildrenIndentation` prop. +If you are using a custom Tree Item component, and you want to override the padding, +then apply the following padding to your `content` element: + +```ts +const CustomTreeItem2Content = styled(TreeItem2Content)(({ theme }) => ({ + // ...other styles + paddingLeft: + `calc(${theme.spacing(1)} + var(--TreeView-itemChildrenIndentation) * var(--TreeView-itemDepth))`, +} +``` + +::: diff --git a/docs/pages/x/api/tree-view/rich-tree-view.json b/docs/pages/x/api/tree-view/rich-tree-view.json index bc08974346195..7da4e28d56f04 100644 --- a/docs/pages/x/api/tree-view/rich-tree-view.json +++ b/docs/pages/x/api/tree-view/rich-tree-view.json @@ -46,6 +46,10 @@ "returned": "boolean" } }, + "itemChildrenIndentation": { + "type": { "name": "union", "description": "numbertrue
if the item should be disabled."
}
},
+ "itemChildrenIndentation": {
+ "description": "Horizontal indentation between an item and its children. Examples: 24, "24px", "2rem", "2em"."
+ },
"multiSelect": {
"description": "If true
, ctrl
and shift
will trigger multiselect."
},
diff --git a/docs/translations/api-docs/tree-view/simple-tree-view/simple-tree-view.json b/docs/translations/api-docs/tree-view/simple-tree-view/simple-tree-view.json
index 2523d471b4e72..a12a983517785 100644
--- a/docs/translations/api-docs/tree-view/simple-tree-view/simple-tree-view.json
+++ b/docs/translations/api-docs/tree-view/simple-tree-view/simple-tree-view.json
@@ -28,6 +28,9 @@
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don't provide this prop. It falls back to a randomly generated id."
},
+ "itemChildrenIndentation": {
+ "description": "Horizontal indentation between an item and its children. Examples: 24, "24px", "2rem", "2em"."
+ },
"multiSelect": {
"description": "If true
, ctrl
and shift
will trigger multiselect."
},
diff --git a/docs/translations/api-docs/tree-view/tree-view/tree-view.json b/docs/translations/api-docs/tree-view/tree-view/tree-view.json
index 2e1fed84729f8..c29df21217338 100644
--- a/docs/translations/api-docs/tree-view/tree-view/tree-view.json
+++ b/docs/translations/api-docs/tree-view/tree-view/tree-view.json
@@ -28,6 +28,9 @@
"id": {
"description": "This prop is used to help implement the accessibility logic. If you don't provide this prop. It falls back to a randomly generated id."
},
+ "itemChildrenIndentation": {
+ "description": "Horizontal indentation between an item and its children. Examples: 24, "24px", "2rem", "2em"."
+ },
"multiSelect": {
"description": "If true
, ctrl
and shift
will trigger multiselect."
},
diff --git a/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx b/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx
index 7a3ea33fbf288..15cea0fe567f1 100644
--- a/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx
+++ b/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx
@@ -232,6 +232,12 @@ RichTreeView.propTypes = {
* @returns {boolean} `true` if the item should be disabled.
*/
isItemDisabled: PropTypes.func,
+ /**
+ * Horizontal indentation between an item and its children.
+ * Examples: 24, "24px", "2rem", "2em".
+ * @default 12px
+ */
+ itemChildrenIndentation: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
items: PropTypes.array.isRequired,
/**
* If `true`, `ctrl` and `shift` will trigger multiselect.
diff --git a/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx b/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx
index d25cb79422364..297792cd511cf 100644
--- a/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx
+++ b/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx
@@ -174,6 +174,12 @@ SimpleTreeView.propTypes = {
* If you don't provide this prop. It falls back to a randomly generated id.
*/
id: PropTypes.string,
+ /**
+ * Horizontal indentation between an item and its children.
+ * Examples: 24, "24px", "2rem", "2em".
+ * @default 12px
+ */
+ itemChildrenIndentation: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* If `true`, `ctrl` and `shift` will trigger multiselect.
* @default false
diff --git a/packages/x-tree-view/src/TreeItem/TreeItem.tsx b/packages/x-tree-view/src/TreeItem/TreeItem.tsx
index fdf9820fd0d67..a330de1af8d98 100644
--- a/packages/x-tree-view/src/TreeItem/TreeItem.tsx
+++ b/packages/x-tree-view/src/TreeItem/TreeItem.tsx
@@ -139,7 +139,7 @@ const StyledTreeItemContent = styled(TreeItemContent, {
{
props: { indentationAtItemLevel: true },
style: {
- paddingLeft: `calc(${theme.spacing(1)} + 12px * var(--TreeView-itemDepth))`,
+ paddingLeft: `calc(${theme.spacing(1)} + var(--TreeView-itemChildrenIndentation) * var(--TreeView-itemDepth))`,
},
},
],
@@ -153,7 +153,7 @@ const TreeItemGroup = styled(Collapse, {
})({
margin: 0,
padding: 0,
- paddingLeft: 12,
+ paddingLeft: 'var(--TreeView-itemChildrenIndentation)',
variants: [
{
props: { indentationAtItemLevel: true },
diff --git a/packages/x-tree-view/src/TreeItem2/TreeItem2.tsx b/packages/x-tree-view/src/TreeItem2/TreeItem2.tsx
index 572d07a5dbaf9..fd905cda2caa3 100644
--- a/packages/x-tree-view/src/TreeItem2/TreeItem2.tsx
+++ b/packages/x-tree-view/src/TreeItem2/TreeItem2.tsx
@@ -56,7 +56,7 @@ export const TreeItem2Content = styled('div', {
{
props: { indentationAtItemLevel: true },
style: {
- paddingLeft: `calc(${theme.spacing(1)} + 12px * var(--TreeView-itemDepth))`,
+ paddingLeft: `calc(${theme.spacing(1)} + var(--TreeView-itemChildrenIndentation) * var(--TreeView-itemDepth))`,
},
},
{
@@ -141,7 +141,7 @@ export const TreeItem2GroupTransition = styled(Collapse, {
})<{ indentationAtItemLevel?: true }>({
margin: 0,
padding: 0,
- paddingLeft: 12,
+ paddingLeft: 'var(--TreeView-itemChildrenIndentation)',
variants: [
{
props: { indentationAtItemLevel: true },
diff --git a/packages/x-tree-view/src/TreeView/TreeView.tsx b/packages/x-tree-view/src/TreeView/TreeView.tsx
index 71a155acd522f..b6944f2df05aa 100644
--- a/packages/x-tree-view/src/TreeView/TreeView.tsx
+++ b/packages/x-tree-view/src/TreeView/TreeView.tsx
@@ -150,6 +150,12 @@ TreeView.propTypes = {
* If you don't provide this prop. It falls back to a randomly generated id.
*/
id: PropTypes.string,
+ /**
+ * Horizontal indentation between an item and its children.
+ * Examples: 24, "24px", "2rem", "2em".
+ * @default 12px
+ */
+ itemChildrenIndentation: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* If `true`, `ctrl` and `shift` will trigger multiselect.
* @default false
diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.tsx b/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.tsx
index c704fd57fe513..c2a77e35bd972 100644
--- a/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.tsx
+++ b/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.tsx
@@ -222,6 +222,14 @@ export const useTreeViewItems: TreeViewPlugin