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