Sider收缩文字不隐藏
- antd inlineCollapsed收缩时文字不隐藏,自定义菜单图标时收起菜单文字不隐藏问题
- 隐藏是通过.anticon+span找到的
- antd3x解决:在自定义图标外面加一个
<span class="anticon"></span>
<Menu
theme="dark"
mode="inline"
defaultSelectedKeys={['1']}
>
<Menu.Item key="1">
<span class="anticon">
<Icon type="user" />
<span>nav 1</span>
</span>
</Menu.Item>
<Menu.Item key="2">
<Icon type="upload" />
<span>nav 2</span>
</Menu.Item>
</Menu>
antd4x Sider文档 https://ant.design/components/layout-cn
import React, { useState } from 'react'
import { Layout, Menu } from 'antd'
import {
UserOutlined, UploadOutlined,
} from '@ant-design/icons'
const { Header, Sider, Content } = Layout
function ProLayout() {
const [collapsed, setCollapsed] = useState[false]
return(
<Sider
trigger={null}
collapsible
collapsed={() => setCollapsed(state => !state)}
>
<div className="logo" />
<Menu
theme="dark"
mode="inline"
defaultSelectedKeys={['1']}
>
<Menu.Item key="1" icon={<UserOutlined />}>
nav 1
</Menu.Item>
<Menu.Item key="3" icon={<UploadOutlined />}>
nav 2
</Menu.Item>
</Menu>
</Sider>
)
}
Sider布局报错
index.js:2177 Warning: [antd: Menu] inlineCollapsed
not control Menu under Sider. Should set collapsed
on Sider instead.