Add control openKeys in Popup Menu

This commit is contained in:
afc163 2016-05-06 18:07:23 +08:00
parent 3c6c0d63a8
commit 3d3cc5f7a3
2 changed files with 15 additions and 10 deletions

View File

@ -13,13 +13,13 @@ const MenuItemGroup = Menu.ItemGroup;
const App = React.createClass({
getInitialState() {
return {
current: 'mail'
current: 'mail',
};
},
handleClick(e) {
console.log('click ', e);
this.setState({
current: e.key
current: e.key,
});
},
render() {

View File

@ -21,7 +21,7 @@ export default class Menu extends React.Component {
constructor(props) {
super(props);
this.state = {
openKeys: []
openKeys: ('openKeys' in props) ? props.openKeys : [],
};
}
componentWillReceiveProps(nextProps) {
@ -29,23 +29,28 @@ export default class Menu extends React.Component {
nextProps.mode !== 'inline') {
this.switchModeFromInline = true;
}
if ('openKeys' in nextProps) {
this.setState({ openKeys: nextProps.openKeys });
}
}
handleClick = (e) => {
this.setState({
openKeys: []
openKeys: [],
});
this.props.onClick(e);
}
handleOpenKeys = (e) => {
this.setState({
openKeys: e.openKeys
});
const { openKeys } = e;
if (!('openKeys' in this.props)) {
this.setState({ openKeys });
}
this.props.onOpen(e);
}
handleCloseKeys = (e) => {
this.setState({
openKeys: e.openKeys
});
const { openKeys } = e;
if (!('openKeys' in this.props)) {
this.setState({ openKeys });
}
this.props.onClose(e);
}
render() {