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) { handleClick(e) {
console.log('click ', e); console.log('Clicked: ', e);
this.setState({ current: e.key }); this.setState({ current: e.key });
}, },
onOpenChange(openKeys) { onOpenChange(openKeys) {
const latestOpenKey = openKeys.find(key => !(this.state.openKeys.indexOf(key) > -1)); const state = this.state;
this.setState({ openKeys: this.getKeyPath(latestOpenKey) }); 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 = { const map = {
sub1: ['sub1'], sub3: ['sub2'],
sub2: ['sub2'],
sub3: ['sub2', 'sub3'],
sub4: ['sub4'],
}; };
return map[key] || []; return map[key] || [];
}, },

Loading…
Cancel
Save