Browse Source

docs: update menu demo

pull/3736/head
Benjy Cui 8 years ago
parent
commit
d8ea555ee8
  1. 23
      components/menu/demo/sider-current.md

23
components/menu/demo/sider-current.md

@ -29,19 +29,26 @@ const Sider = React.createClass({
};
},
handleClick(e) {
console.log('click ', e);
console.log('Clicked: ', e);
this.setState({ current: e.key });
},
onOpenChange(openKeys) {
const latestOpenKey = openKeys.find(key => !(this.state.openKeys.indexOf(key) > -1));
this.setState({ openKeys: this.getKeyPath(latestOpenKey) });
const state = this.state;
const latestOpenKey = openKeys.find(key => !(state.openKeys.indexOf(key) > -1));
const latestCloseKey = state.openKeys.find(key => !(openKeys.indexOf(key) > -1));
let nextOpenKeys = [];
if (latestOpenKey) {
nextOpenKeys = this.getAncestorKeys(latestOpenKey).concat(latestOpenKey);
}
if (latestCloseKey) {
nextOpenKeys = this.getAncestorKeys(latestCloseKey);
}
this.setState({ openKeys: nextOpenKeys });
},
getKeyPath(key) {
getAncestorKeys(key) {
const map = {
sub1: ['sub1'],
sub2: ['sub2'],
sub3: ['sub2', 'sub3'],
sub4: ['sub4'],
sub3: ['sub2'],
};
return map[key] || [];
},

Loading…
Cancel
Save