It seems that achieving the desired indentation effect with TreeView or TreeItem props directly is not possible. By omitting the defaultCollapseIcon
and defaultExpandIcon
props, you can remove icons altogether.
To customize the styling for the desired outcome, consider this example that demonstrates a TreeView without icons or indentation:
const StyledTreeView = styled(TreeView)`
.MuiTreeItem-group {
margin-left: 0;
}
`;
const StyledTreeItem = styled(TreeItem)`
.MuiTreeItem-iconContainer {
display: none;
}
`;
export default function App() {
return (
<StyledTreeView aria-label="tree">
<StyledTreeItem nodeId="1" label="Item 1">
<StyledTreeItem nodeId="2" label="Subitem 1-1" />
</StyledTreeItem>
<StyledTreeItem nodeId="5" label="Item 2">
<StyledTreeItem nodeId="10" label="Subitem 2-1" />
<StyledTreeItem nodeId="6" label="Subitem 2-2">
<StyledTreeItem nodeId="8" label="Subitem 2-2-1" />
</StyledTreeItem>
</StyledTreeItem>
</StyledTreeView>
);
}
The customized styling in TreeView removes indentation, while the style applied to StyledTreeItem removes any space designated for an icon.
Check out this sandbox featuring the TreeView design