我想设置一个主/详细视图,并<List>在左侧,<Drawer>右侧.
如何<ListItem/>突出显示最后选定的停留时间?
我正在使用material-ui @ next
Jul*_*ont 12
你应该使用MenuItem而不是ListItem.如文档中所述:
这
MenuItem是一个包装ListItem有一些额外的样式.
其中一个附加样式是selected选项,您可以使用selectedprop 设置:
<MenuItem button selected>
<ListItemIcon>
<FolderIcon />
</ListItemIcon>
<ListItemText primary="Archives" />
</MenuItem>
Run Code Online (Sandbox Code Playgroud)
以下是state用于跟踪和更新最近点击的项目的概念证明:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import List, { ListItemIcon, ListItemText } from 'material-ui/List';
import { MenuItem } from 'material-ui/Menu';
import InboxIcon from 'material-ui-icons/Inbox';
import DraftsIcon from 'material-ui-icons/Drafts';
import FolderIcon from 'material-ui-icons/Folder';
const styles = theme => ({
root: {
width: '100%',
maxWidth: 360,
backgroundColor: theme.palette.background.paper,
},
});
class SimpleList extends React.Component {
constructor(props) {
super(props);
this.state = { selected: null };
}
updateSelected(selectedIndex) {
this.setState({ selected: selectedIndex });
}
render() {
const { classes } = this.props;
const { selected } = this.state;
return (
<div className={classes.root}>
<List>
<MenuItem button onClick={() => this.updateSelected(0)} selected={selected === 0}>
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText primary="Inbox" />
</MenuItem>
<MenuItem button onClick={() => this.updateSelected(1)} selected={selected === 1}>
<ListItemIcon>
<DraftsIcon />
</ListItemIcon>
<ListItemText primary="Drafts" />
</MenuItem>
<MenuItem button onClick={() => this.updateSelected(2)} selected={selected === 2}>
<ListItemIcon>
<FolderIcon />
</ListItemIcon>
<ListItemText primary="Archives" />
</MenuItem>
</List>
</div>
);
}
}
SimpleList.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleList);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5472 次 |
| 最近记录: |