--- order: 99 title: zh-CN: 自定义触发器 Debug en-US: Custom trigger debug debug: true --- ## zh-CN 修改内容前,请尝试此 Demo 查看样式是否抖动。 ```jsx import { Layout, Menu } from 'antd'; import { TeamOutlined, UserOutlined, FileOutlined, DesktopOutlined, PieChartOutlined, MenuUnfoldOutlined, MenuFoldOutlined, } from '@ant-design/icons'; const { Header, Sider, Content } = Layout; const { SubMenu } = Menu; class SiderDemo extends React.Component { state = { collapsed: true, }; toggle = () => { this.setState({ collapsed: !this.state.collapsed, }); }; render() { return (
}> Option 1 }> Option 2 } title="User"> Tom Bill Alex } title="Team"> Team 1 Team 2 } />
{React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, { className: 'trigger', onClick: this.toggle, })}
Content
); } } ReactDOM.render(, mountNode); ``` ```css #components-layout-demo-custom-trigger .trigger { font-size: 18px; line-height: 64px; padding: 0 24px; cursor: pointer; transition: color 0.3s; } #components-layout-demo-custom-trigger .trigger:hover { color: #1890ff; } #components-layout-demo-custom-trigger .logo { height: 32px; background: rgba(255, 255, 255, 0.2); margin: 16px; } .site-layout-background { background: #fff; } ```