2017-06-30 18:08:30 +08:00
|
|
|
---
|
|
|
|
order: 2
|
|
|
|
title:
|
|
|
|
zh-CN: 缩起内嵌菜单
|
|
|
|
en-US: Collapsed inline menu
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
内嵌菜单可以被缩起/展开。
|
|
|
|
|
2017-09-15 21:37:17 +08:00
|
|
|
你可以在 [Layout](/components/layout/#components-layout-demo-side) 里查看侧边布局结合的完整示例。
|
|
|
|
|
2017-06-30 18:08:30 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Inline menu could be collapsed.
|
|
|
|
|
2017-09-15 21:37:17 +08:00
|
|
|
Here is [a complete demo](/components/layout/#components-layout-demo-side) with sider layout.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Menu, Button } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import {
|
|
|
|
AppstoreOutlined,
|
|
|
|
MenuUnfoldOutlined,
|
|
|
|
MenuFoldOutlined,
|
|
|
|
PieChartOutlined,
|
|
|
|
DesktopOutlined,
|
2020-03-11 12:31:53 +08:00
|
|
|
ContainerOutlined,
|
2019-11-28 12:34:33 +08:00
|
|
|
MailOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-06-19 19:09:08 +08:00
|
|
|
const { SubMenu } = Menu;
|
2017-06-30 18:08:30 +08:00
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
|
|
|
collapsed: false,
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-06-30 18:08:30 +08:00
|
|
|
toggleCollapsed = () => {
|
|
|
|
this.setState({
|
|
|
|
collapsed: !this.state.collapsed,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-06-30 18:08:30 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2017-11-06 21:28:51 +08:00
|
|
|
<div style={{ width: 256 }}>
|
2017-06-30 18:08:30 +08:00
|
|
|
<Button type="primary" onClick={this.toggleCollapsed} style={{ marginBottom: 16 }}>
|
2019-11-28 12:34:33 +08:00
|
|
|
{React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined)}
|
2017-06-30 18:08:30 +08:00
|
|
|
</Button>
|
|
|
|
<Menu
|
|
|
|
defaultSelectedKeys={['1']}
|
|
|
|
defaultOpenKeys={['sub1']}
|
|
|
|
mode="inline"
|
|
|
|
theme="dark"
|
|
|
|
inlineCollapsed={this.state.collapsed}
|
|
|
|
>
|
|
|
|
<Menu.Item key="1">
|
2019-11-28 12:34:33 +08:00
|
|
|
<PieChartOutlined />
|
2017-06-30 18:08:30 +08:00
|
|
|
<span>Option 1</span>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="2">
|
2019-11-28 12:34:33 +08:00
|
|
|
<DesktopOutlined />
|
2017-06-30 18:08:30 +08:00
|
|
|
<span>Option 2</span>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="3">
|
2020-03-11 12:31:53 +08:00
|
|
|
<ContainerOutlined />
|
2017-06-30 18:08:30 +08:00
|
|
|
<span>Option 3</span>
|
|
|
|
</Menu.Item>
|
2019-05-07 14:57:32 +08:00
|
|
|
<SubMenu
|
|
|
|
key="sub1"
|
|
|
|
title={
|
|
|
|
<span>
|
2019-11-28 12:34:33 +08:00
|
|
|
<MailOutlined />
|
2019-05-07 14:57:32 +08:00
|
|
|
<span>Navigation One</span>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
2017-06-30 18:08:30 +08:00
|
|
|
<Menu.Item key="5">Option 5</Menu.Item>
|
|
|
|
<Menu.Item key="6">Option 6</Menu.Item>
|
|
|
|
<Menu.Item key="7">Option 7</Menu.Item>
|
|
|
|
<Menu.Item key="8">Option 8</Menu.Item>
|
|
|
|
</SubMenu>
|
2019-05-07 14:57:32 +08:00
|
|
|
<SubMenu
|
|
|
|
key="sub2"
|
|
|
|
title={
|
|
|
|
<span>
|
2019-11-28 12:34:33 +08:00
|
|
|
<AppstoreOutlined />
|
2019-05-07 14:57:32 +08:00
|
|
|
<span>Navigation Two</span>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
2017-06-30 18:08:30 +08:00
|
|
|
<Menu.Item key="9">Option 9</Menu.Item>
|
|
|
|
<Menu.Item key="10">Option 10</Menu.Item>
|
|
|
|
<SubMenu key="sub3" title="Submenu">
|
|
|
|
<Menu.Item key="11">Option 11</Menu.Item>
|
|
|
|
<Menu.Item key="12">Option 12</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|