--- order: 2 title: zh-CN: 只展开当前父级菜单 en-US: Open current submenu only --- ## zh-CN 点击菜单,收起其他展开的所有菜单,保持菜单聚焦简洁。 ## en-US Click the menu and you will see that all the other menus gets collapsed to keep the entire menu compact. ````jsx import { Menu, Icon } from 'antd'; const SubMenu = Menu.SubMenu; class Sider extends React.Component { // submenu keys of first level rootSubmenuKeys = ['sub1', 'sub2', 'sub4']; state = { openKeys: ['sub1'], }; onOpenChange = (openKeys) => { const latestOpenKey = openKeys.find(key => this.state.openKeys.indexOf(key) === -1); if (this.rootSubmenuKeys.indexOf(latestOpenKey) === -1) { this.setState({ openKeys }); } else { this.setState({ openKeys: latestOpenKey ? [latestOpenKey] : [], }); } } render() { return ( Navigation One}> Option 1 Option 2 Option 3 Option 4 Navigation Two}> Option 5 Option 6 Option 7 Option 8 Navigation Three}> Option 9 Option 10 Option 11 Option 12 ); } } ReactDOM.render(, mountNode); ````