我是该框架的新手,我的目标是当我单击侧栏中的菜单项之一时显示颜色。如果我们单击表格组件,则表格名称和图标应变为白色。谁能帮助我如何在单击菜单项时更改颜色?
这是代码:
class Sidebar extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedIndex: 0
};
}
handleListItemClick = (event, index) => {
this.setState({
selectedIndex: index
});
};
render() {
const { className, classes, onSidebarOpen, ...rest } = this.props;
return (
<div className={classes.root}>
<Drawer
className={classes.drawer}
variant="permanent"
classes={{
paper: classes.drawerPaper
}}
>
<div className={classes.toolbar} />
<List>
{["table", "organisation"].map((item, index) => {
const Icon = itemsConfig[item].icon;
return (
<ListItem
component={Link}
to={itemsConfig[item].link}
selected={index === this.state.selectedIndex}
onClick={event => this.handleListItemClick(event, index)}
button
key={item}
>
<ListItemIcon>
<Icon />
</ListItemIcon>
<ListItemText primary={itemsConfig[item].text} />
</ListItem>
);
})}
</List>
</Drawer>
</div>
);
}
}
export default withStyles(styles)(Sidebar);
qq_遁去的一_1
相关分类