--- 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 (
); } } ReactDOM.render(