--- order: 2 title: zh-CN: 只展开当前父级菜单 en-US: Open current submenu only --- ## zh-CN 点击菜单,收起其他展开的所有菜单,保持菜单聚焦简洁。 > 该用法要求 antd@2.0+ ## en-US Click the menu and you will see that all the other menus gets collapsed to keep the entire menu compact. > This demo is for antd@2.0+. ````jsx import { Menu, Icon } from 'antd'; const SubMenu = Menu.SubMenu; const Sider = React.createClass({ getInitialState() { return { current: '1', openKeys: [], }; }, handleClick(e) { console.log('click ', 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) }); }, getKeyPath(key) { const map = { sub1: ['sub1'], sub2: ['sub2'], sub3: ['sub2', 'sub3'], sub4: ['sub4'], }; return map[key] || []; }, render() { return (
); }, }); ReactDOM.render(