I have a MUI TreeView component with a nested mapping of Categories (parent) and Articles (Child). When I select a child, that child has styles applied to it based on "selected". When I click a parent, the previous child loses its "selected" styles.
How can I make a differentiation between "child selected" and "parent clicked(selected)".
I would prefer to do this all in CSS if possible. This is a Next.js app.
My CategoryItem CSS:
const StyledCategoryItemRoot = styled(TreeItem)(({ theme }) => ({
[`& .${treeItemClasses.content}`]: {
fontWeight: theme.typography.fontWeightBold,
marginBottom: 5,
paddingLeft: 0,
borderRadius: theme.shape.borderRadius,
'&.Mui-selected.Mui-focused, &:hover, &.Mui-selected:hover': {
backgroundColor:
theme.palette.mode === 'light'
? alpha('#ff9aff', 0.16)
: alpha('#2f506f', 0.24),
},
'&.Mui-selected, &.Mui-focused': {
backgroundColor: 'transparent',
},
},
}));
My ArticleItem CSS:
const StyledArticleItemRoot = styled(TreeItem)(({ theme, router, post }) => ({
color:
theme.palette.mode === 'light'
? theme.palette.grey[900]
: theme.palette.grey[500],
[`& .${treeItemClasses.content}`]: {
fontWeight: theme.typography.fontWeightBold,
paddingLeft: 0,
borderRadius: theme.shape.borderRadius,
transition: '.2s',
'&.Mui-selected:hover, &.Mui-selected.Mui-focused:hover, &:hover': {
color: theme.palette.mode === 'light' ? theme.palette.grey[800] : 'white',
},
'&.Mui-focused, &.Mui-selected, &.Mui-selected.Mui-focused': {
backgroundColor:
theme.palette.mode === 'light'
? alpha('#ff9aff', 0.16)
: alpha('#2f506f', 0.16),
color:
post.attributes.slug !== router.query.slug
? theme.palette.grey[500]
: theme.palette.mode === 'light'
? theme.palette.primary.main
: theme.palette.secondary.main,
},
},
}));