mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
docs: update menu demo
This commit is contained in:
parent
a3962d5869
commit
d8ea555ee8
@ -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…
Reference in New Issue
Block a user