--- 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 } from 'antd'; import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons'; const { SubMenu } = Menu; // submenu keys of first level const rootSubmenuKeys = ['sub1', 'sub2', 'sub4']; const Sider = () => { const [openKeys, setOpenKeys] = React.useState(['sub1']); const onOpenChange = keys => { const latestOpenKey = keys.find(key => openKeys.indexOf(key) === -1); if (rootSubmenuKeys.indexOf(latestOpenKey) === -1) { setOpenKeys(keys); } else { setOpenKeys(latestOpenKey ? [latestOpenKey] : []); } }; return ( } title="Navigation One"> Option 1 Option 2 Option 3 Option 4 } title="Navigation Two"> Option 5 Option 6 Option 7 Option 8 } title="Navigation Three"> Option 9 Option 10 Option 11 Option 12 ); }; ReactDOM.render(, mountNode); ```