-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
scope: tree viewChanges related to the tree view. This includes TreeView, TreeItem.Changes related to the tree view. This includes TreeView, TreeItem.
Description
@michelengelen Thanks, it kind of works. The items now display radio buttons and they behave correctly when selected. However, I noticed that if a child item is checked, the parent switches from a radio button to a tri-state checkbox. This feels a bit inconsistent visually, as the UI starts mixing radio buttons and checkboxes.
Originally posted by @Lure5134 in #18073
example code:
import * as React from 'react';
import Box from '@mui/material/Box';
import RadioButtonUncheckedIcon from '@mui/icons-material/RadioButtonUnchecked';
import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked';
import { RichTreeView } from '@mui/x-tree-view/RichTreeView';
import { TreeItem, TreeItemProps, TreeItemSlotProps } from '@mui/x-tree-view/TreeItem';
import { MUI_X_PRODUCTS } from './products';
const CustomTreeItem = React.forwardRef(function CustomTreeItem(
props: TreeItemProps,
ref: React.Ref<HTMLLIElement>,
) {
return (
<TreeItem
{...props}
ref={ref}
slotProps={
{
checkbox: {
size: 'small',
icon: <RadioButtonUncheckedIcon />,
checkedIcon: <RadioButtonCheckedIcon />,
},
} as TreeItemSlotProps
}
/>
);
});
export default function CheckboxSlotProps() {
return (
<Box sx={{ minHeight: 200, minWidth: 350 }}>
<RichTreeView
defaultExpandedItems={['grid', 'pickers']}
checkboxSelection
items={MUI_X_PRODUCTS}
slots={{ item: CustomTreeItem }}
selectionPropagation={{ parents: false, descendants: false }}
/>
</Box>
);
}Metadata
Metadata
Assignees
Labels
scope: tree viewChanges related to the tree view. This includes TreeView, TreeItem.Changes related to the tree view. This includes TreeView, TreeItem.