fix: Menu custom icon style (#27983)

* fix: Menu custom icon style

close #27973

* fix snapshot
This commit is contained in:
偏右 2020-11-25 14:31:51 +08:00 committed by GitHub
parent fc4592bc06
commit 05a82f2d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 101 additions and 99 deletions

View File

@ -148,7 +148,7 @@ exports[`renders ./components/layout/demo/custom-trigger.md correctly 1`] = `
>
<span
aria-label="user"
class="anticon anticon-user"
class="anticon anticon-user ant-menu-item-icon"
role="img"
>
<svg
@ -176,7 +176,7 @@ exports[`renders ./components/layout/demo/custom-trigger.md correctly 1`] = `
>
<span
aria-label="video-camera"
class="anticon anticon-video-camera"
class="anticon anticon-video-camera ant-menu-item-icon"
role="img"
>
<svg
@ -204,7 +204,7 @@ exports[`renders ./components/layout/demo/custom-trigger.md correctly 1`] = `
>
<span
aria-label="upload"
class="anticon anticon-upload"
class="anticon anticon-upload ant-menu-item-icon"
role="img"
>
<svg
@ -463,7 +463,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="user"
class="anticon anticon-user"
class="anticon anticon-user ant-menu-item-icon"
role="img"
>
<svg
@ -491,7 +491,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="video-camera"
class="anticon anticon-video-camera"
class="anticon anticon-video-camera ant-menu-item-icon"
role="img"
>
<svg
@ -519,7 +519,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="upload"
class="anticon anticon-upload"
class="anticon anticon-upload ant-menu-item-icon"
role="img"
>
<svg
@ -547,7 +547,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="bar-chart"
class="anticon anticon-bar-chart"
class="anticon anticon-bar-chart ant-menu-item-icon"
role="img"
>
<svg
@ -575,7 +575,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="cloud"
class="anticon anticon-cloud"
class="anticon anticon-cloud ant-menu-item-icon"
role="img"
>
<svg
@ -603,7 +603,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="appstore"
class="anticon anticon-appstore"
class="anticon anticon-appstore ant-menu-item-icon"
role="img"
>
<svg
@ -631,7 +631,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="team"
class="anticon anticon-team"
class="anticon anticon-team ant-menu-item-icon"
role="img"
>
<svg
@ -659,7 +659,7 @@ exports[`renders ./components/layout/demo/fixed-sider.md correctly 1`] = `
>
<span
aria-label="shop"
class="anticon anticon-shop"
class="anticon anticon-shop ant-menu-item-icon"
role="img"
>
<svg
@ -831,7 +831,7 @@ exports[`renders ./components/layout/demo/responsive.md correctly 1`] = `
>
<span
aria-label="user"
class="anticon anticon-user"
class="anticon anticon-user ant-menu-item-icon"
role="img"
>
<svg
@ -859,7 +859,7 @@ exports[`renders ./components/layout/demo/responsive.md correctly 1`] = `
>
<span
aria-label="video-camera"
class="anticon anticon-video-camera"
class="anticon anticon-video-camera ant-menu-item-icon"
role="img"
>
<svg
@ -887,7 +887,7 @@ exports[`renders ./components/layout/demo/responsive.md correctly 1`] = `
>
<span
aria-label="upload"
class="anticon anticon-upload"
class="anticon anticon-upload ant-menu-item-icon"
role="img"
>
<svg
@ -915,7 +915,7 @@ exports[`renders ./components/layout/demo/responsive.md correctly 1`] = `
>
<span
aria-label="user"
class="anticon anticon-user"
class="anticon anticon-user ant-menu-item-icon"
role="img"
>
<svg
@ -993,7 +993,7 @@ exports[`renders ./components/layout/demo/side.md correctly 1`] = `
>
<span
aria-label="pie-chart"
class="anticon anticon-pie-chart"
class="anticon anticon-pie-chart ant-menu-item-icon"
role="img"
>
<svg
@ -1021,7 +1021,7 @@ exports[`renders ./components/layout/demo/side.md correctly 1`] = `
>
<span
aria-label="desktop"
class="anticon anticon-desktop"
class="anticon anticon-desktop ant-menu-item-icon"
role="img"
>
<svg
@ -1127,7 +1127,7 @@ exports[`renders ./components/layout/demo/side.md correctly 1`] = `
>
<span
aria-label="file"
class="anticon anticon-file"
class="anticon anticon-file ant-menu-item-icon"
role="img"
>
<svg

View File

@ -5,7 +5,7 @@ import classNames from 'classnames';
import MenuContext, { MenuContextProps } from './MenuContext';
import Tooltip, { TooltipProps } from '../tooltip';
import { SiderContext, SiderContextProps } from '../layout/Sider';
import { isValidElement } from '../_util/reactNode';
import { isValidElement, cloneElement } from '../_util/reactNode';
export interface MenuItemProps extends Omit<RcMenuItemProps, 'title'> {
icon?: React.ReactNode;
@ -73,7 +73,12 @@ export default class MenuItem extends React.Component<MenuItemProps> {
)}
title={title}
>
{icon}
{cloneElement(icon, {
className: classNames(
isValidElement(icon) ? icon.props?.className : '',
`${rootPrefixCls}-item-icon`,
),
})}
{this.renderItemChildren(inlineCollapsed)}
</Item>
</Tooltip>

View File

@ -30,7 +30,7 @@ exports[`renders ./components/menu/demo/horizontal.md correctly 1`] = `
>
<span
aria-label="mail"
class="anticon anticon-mail"
class="anticon anticon-mail ant-menu-item-icon"
role="img"
>
<svg
@ -77,7 +77,7 @@ exports[`renders ./components/menu/demo/horizontal.md correctly 1`] = `
>
<span
aria-label="appstore"
class="anticon anticon-appstore"
class="anticon anticon-appstore ant-menu-item-icon"
role="img"
>
<svg
@ -225,29 +225,27 @@ exports[`renders ./components/menu/demo/inline.md correctly 1`] = `
role="button"
style="padding-left:24px"
>
<span>
<span
aria-label="mail"
class="anticon anticon-mail"
role="img"
<span
aria-label="mail"
class="anticon anticon-mail"
role="img"
>
<svg
aria-hidden="true"
data-icon="mail"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<svg
aria-hidden="true"
data-icon="mail"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 110.8V792H136V270.8l-27.6-21.5 39.3-50.5 42.8 33.3h643.1l42.8-33.3 39.3 50.5-27.7 21.5zM833.6 232L512 482 190.4 232l-42.8-33.3-39.3 50.5 27.6 21.5 341.6 265.6a55.99 55.99 0 0068.7 0L888 270.8l27.6-21.5-39.3-50.5-42.7 33.2z"
/>
</svg>
</span>
<span>
Navigation One
</span>
<path
d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 110.8V792H136V270.8l-27.6-21.5 39.3-50.5 42.8 33.3h643.1l42.8-33.3 39.3 50.5-27.7 21.5zM833.6 232L512 482 190.4 232l-42.8-33.3-39.3 50.5 27.6 21.5 341.6 265.6a55.99 55.99 0 0068.7 0L888 270.8l27.6-21.5-39.3-50.5-42.7 33.2z"
/>
</svg>
</span>
<span>
Navigation One
</span>
<i
class="ant-menu-submenu-arrow"
@ -366,29 +364,27 @@ exports[`renders ./components/menu/demo/inline.md correctly 1`] = `
role="button"
style="padding-left:24px"
>
<span>
<span
aria-label="setting"
class="anticon anticon-setting"
role="img"
<span
aria-label="setting"
class="anticon anticon-setting"
role="img"
>
<svg
aria-hidden="true"
data-icon="setting"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<svg
aria-hidden="true"
data-icon="setting"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M924.8 625.7l-65.5-56c3.1-19 4.7-38.4 4.7-57.8s-1.6-38.8-4.7-57.8l65.5-56a32.03 32.03 0 009.3-35.2l-.9-2.6a443.74 443.74 0 00-79.7-137.9l-1.8-2.1a32.12 32.12 0 00-35.1-9.5l-81.3 28.9c-30-24.6-63.5-44-99.7-57.6l-15.7-85a32.05 32.05 0 00-25.8-25.7l-2.7-.5c-52.1-9.4-106.9-9.4-159 0l-2.7.5a32.05 32.05 0 00-25.8 25.7l-15.8 85.4a351.86 351.86 0 00-99 57.4l-81.9-29.1a32 32 0 00-35.1 9.5l-1.8 2.1a446.02 446.02 0 00-79.7 137.9l-.9 2.6c-4.5 12.5-.8 26.5 9.3 35.2l66.3 56.6c-3.1 18.8-4.6 38-4.6 57.1 0 19.2 1.5 38.4 4.6 57.1L99 625.5a32.03 32.03 0 00-9.3 35.2l.9 2.6c18.1 50.4 44.9 96.9 79.7 137.9l1.8 2.1a32.12 32.12 0 0035.1 9.5l81.9-29.1c29.8 24.5 63.1 43.9 99 57.4l15.8 85.4a32.05 32.05 0 0025.8 25.7l2.7.5a449.4 449.4 0 00159 0l2.7-.5a32.05 32.05 0 0025.8-25.7l15.7-85a350 350 0 0099.7-57.6l81.3 28.9a32 32 0 0035.1-9.5l1.8-2.1c34.8-41.1 61.6-87.5 79.7-137.9l.9-2.6c4.5-12.3.8-26.3-9.3-35zM788.3 465.9c2.5 15.1 3.8 30.6 3.8 46.1s-1.3 31-3.8 46.1l-6.6 40.1 74.7 63.9a370.03 370.03 0 01-42.6 73.6L721 702.8l-31.4 25.8c-23.9 19.6-50.5 35-79.3 45.8l-38.1 14.3-17.9 97a377.5 377.5 0 01-85 0l-17.9-97.2-37.8-14.5c-28.5-10.8-55-26.2-78.7-45.7l-31.4-25.9-93.4 33.2c-17-22.9-31.2-47.6-42.6-73.6l75.5-64.5-6.5-40c-2.4-14.9-3.7-30.3-3.7-45.5 0-15.3 1.2-30.6 3.7-45.5l6.5-40-75.5-64.5c11.3-26.1 25.6-50.7 42.6-73.6l93.4 33.2 31.4-25.9c23.7-19.5 50.2-34.9 78.7-45.7l37.9-14.3 17.9-97.2c28.1-3.2 56.8-3.2 85 0l17.9 97 38.1 14.3c28.7 10.8 55.4 26.2 79.3 45.8l31.4 25.8 92.8-32.9c17 22.9 31.2 47.6 42.6 73.6L781.8 426l6.5 39.9zM512 326c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176zm79.2 255.2A111.6 111.6 0 01512 614c-29.9 0-58-11.7-79.2-32.8A111.6 111.6 0 01400 502c0-29.9 11.7-58 32.8-79.2C454 401.6 482.1 390 512 390c29.9 0 58 11.6 79.2 32.8A111.6 111.6 0 01624 502c0 29.9-11.7 58-32.8 79.2z"
/>
</svg>
</span>
<span>
Navigation Three
</span>
<path
d="M924.8 625.7l-65.5-56c3.1-19 4.7-38.4 4.7-57.8s-1.6-38.8-4.7-57.8l65.5-56a32.03 32.03 0 009.3-35.2l-.9-2.6a443.74 443.74 0 00-79.7-137.9l-1.8-2.1a32.12 32.12 0 00-35.1-9.5l-81.3 28.9c-30-24.6-63.5-44-99.7-57.6l-15.7-85a32.05 32.05 0 00-25.8-25.7l-2.7-.5c-52.1-9.4-106.9-9.4-159 0l-2.7.5a32.05 32.05 0 00-25.8 25.7l-15.8 85.4a351.86 351.86 0 00-99 57.4l-81.9-29.1a32 32 0 00-35.1 9.5l-1.8 2.1a446.02 446.02 0 00-79.7 137.9l-.9 2.6c-4.5 12.5-.8 26.5 9.3 35.2l66.3 56.6c-3.1 18.8-4.6 38-4.6 57.1 0 19.2 1.5 38.4 4.6 57.1L99 625.5a32.03 32.03 0 00-9.3 35.2l.9 2.6c18.1 50.4 44.9 96.9 79.7 137.9l1.8 2.1a32.12 32.12 0 0035.1 9.5l81.9-29.1c29.8 24.5 63.1 43.9 99 57.4l15.8 85.4a32.05 32.05 0 0025.8 25.7l2.7.5a449.4 449.4 0 00159 0l2.7-.5a32.05 32.05 0 0025.8-25.7l15.7-85a350 350 0 0099.7-57.6l81.3 28.9a32 32 0 0035.1-9.5l1.8-2.1c34.8-41.1 61.6-87.5 79.7-137.9l.9-2.6c4.5-12.3.8-26.3-9.3-35zM788.3 465.9c2.5 15.1 3.8 30.6 3.8 46.1s-1.3 31-3.8 46.1l-6.6 40.1 74.7 63.9a370.03 370.03 0 01-42.6 73.6L721 702.8l-31.4 25.8c-23.9 19.6-50.5 35-79.3 45.8l-38.1 14.3-17.9 97a377.5 377.5 0 01-85 0l-17.9-97.2-37.8-14.5c-28.5-10.8-55-26.2-78.7-45.7l-31.4-25.9-93.4 33.2c-17-22.9-31.2-47.6-42.6-73.6l75.5-64.5-6.5-40c-2.4-14.9-3.7-30.3-3.7-45.5 0-15.3 1.2-30.6 3.7-45.5l6.5-40-75.5-64.5c11.3-26.1 25.6-50.7 42.6-73.6l93.4 33.2 31.4-25.9c23.7-19.5 50.2-34.9 78.7-45.7l37.9-14.3 17.9-97.2c28.1-3.2 56.8-3.2 85 0l17.9 97 38.1 14.3c28.7 10.8 55.4 26.2 79.3 45.8l31.4 25.8 92.8-32.9c17 22.9 31.2 47.6 42.6 73.6L781.8 426l6.5 39.9zM512 326c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176zm79.2 255.2A111.6 111.6 0 01512 614c-29.9 0-58-11.7-79.2-32.8A111.6 111.6 0 01400 502c0-29.9 11.7-58 32.8-79.2C454 401.6 482.1 390 512 390c29.9 0 58 11.6 79.2 32.8A111.6 111.6 0 01624 502c0 29.9-11.7 58-32.8 79.2z"
/>
</svg>
</span>
<span>
Navigation Three
</span>
<i
class="ant-menu-submenu-arrow"
@ -439,7 +435,7 @@ exports[`renders ./components/menu/demo/inline-collapsed.md correctly 1`] = `
>
<span
aria-label="pie-chart"
class="anticon anticon-pie-chart"
class="anticon anticon-pie-chart ant-menu-item-icon"
role="img"
>
<svg
@ -467,7 +463,7 @@ exports[`renders ./components/menu/demo/inline-collapsed.md correctly 1`] = `
>
<span
aria-label="desktop"
class="anticon anticon-desktop"
class="anticon anticon-desktop ant-menu-item-icon"
role="img"
>
<svg
@ -495,7 +491,7 @@ exports[`renders ./components/menu/demo/inline-collapsed.md correctly 1`] = `
>
<span
aria-label="container"
class="anticon anticon-container"
class="anticon anticon-container ant-menu-item-icon"
role="img"
>
<svg
@ -1048,7 +1044,7 @@ Array [
>
<span
aria-label="mail"
class="anticon anticon-mail"
class="anticon anticon-mail ant-menu-item-icon"
role="img"
>
<svg
@ -1076,7 +1072,7 @@ Array [
>
<span
aria-label="calendar"
class="anticon anticon-calendar"
class="anticon anticon-calendar ant-menu-item-icon"
role="img"
>
<svg
@ -1221,7 +1217,7 @@ Array [
>
<span
aria-label="link"
class="anticon anticon-link"
class="anticon anticon-link ant-menu-item-icon"
role="img"
>
<svg

View File

@ -11,7 +11,7 @@ exports[`Menu Menu.Item with icon children auto wrap span 1`] = `
>
<span
aria-label="mail"
class="anticon anticon-mail"
class="anticon anticon-mail ant-menu-item-icon"
role="img"
>
<svg
@ -38,7 +38,7 @@ exports[`Menu Menu.Item with icon children auto wrap span 1`] = `
>
<span
aria-label="mail"
class="anticon anticon-mail"
class="anticon anticon-mail ant-menu-item-icon"
role="img"
>
<svg
@ -187,7 +187,7 @@ exports[`Menu should controlled collapse work 1`] = `
>
<span
aria-label="pie-chart"
class="anticon anticon-pie-chart"
class="anticon anticon-pie-chart ant-menu-item-icon"
role="img"
>
<svg
@ -223,7 +223,7 @@ exports[`Menu should controlled collapse work 2`] = `
>
<span
aria-label="pie-chart"
class="anticon anticon-pie-chart"
class="anticon anticon-pie-chart ant-menu-item-icon"
role="img"
>
<svg

View File

@ -39,7 +39,11 @@ class App extends React.Component {
<Menu.Item key="app" disabled icon={<AppstoreOutlined />}>
Navigation Two
</Menu.Item>
<SubMenu key="SubMenu" icon={<SettingOutlined />} title="Navigation Three - Submenu">
<SubMenu
key="SubMenu"
icon={<SettingOutlined />}
title="Navigation Three - Submenu"
>
<Menu.ItemGroup title="Item 1">
<Menu.Item key="setting:1">Option 1</Menu.Item>
<Menu.Item key="setting:2">Option 2</Menu.Item>

View File

@ -33,15 +33,7 @@ class Sider extends React.Component {
defaultOpenKeys={['sub1']}
mode="inline"
>
<SubMenu
key="sub1"
title={
<span>
<MailOutlined />
<span>Navigation One</span>
</span>
}
>
<SubMenu key="sub1" icon={<MailOutlined />} title="Navigation One">
<Menu.ItemGroup key="g1" title="Item 1">
<Menu.Item key="1">Option 1</Menu.Item>
<Menu.Item key="2">Option 2</Menu.Item>
@ -59,15 +51,7 @@ class Sider extends React.Component {
<Menu.Item key="8">Option 8</Menu.Item>
</SubMenu>
</SubMenu>
<SubMenu
key="sub4"
title={
<span>
<SettingOutlined />
<span>Navigation Three</span>
</span>
}
>
<SubMenu key="sub4" icon={<SettingOutlined />} title="Navigation Three">
<Menu.Item key="9">Option 9</Menu.Item>
<Menu.Item key="10">Option 10</Menu.Item>
<Menu.Item key="11">Option 11</Menu.Item>

View File

@ -118,11 +118,14 @@
> span > a:hover {
color: @menu-dark-highlight-color;
}
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
color: @menu-dark-selected-item-icon-color;
}
.@{iconfont-css-prefix} + span {
color: @menu-dark-selected-item-text-color;
+ span {
color: @menu-dark-selected-item-text-color;
}
}
}

View File

@ -185,6 +185,8 @@
cursor: pointer;
transition: color 0.3s @ease-in-out, border-color 0.3s @ease-in-out,
background 0.3s @ease-in-out, padding 0.15s @ease-in-out;
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
min-width: 14px;
margin-right: @menu-icon-margin-right;
@ -197,7 +199,8 @@
}
&.@{menu-prefix-cls}-item-only-child {
> .@{iconfont-css-prefix} {
> .@{iconfont-css-prefix},
> .@{menu-prefix-cls}-item-icon {
margin-right: 0;
}
}
@ -488,6 +491,8 @@
.@{menu-prefix-cls}-submenu-arrow {
display: none;
}
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
margin: 0;
font-size: @menu-icon-size-lg;
@ -500,12 +505,15 @@
}
}
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
display: inline-block;
}
&-tooltip {
pointer-events: none;
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
display: none;
}

View File

@ -43,6 +43,7 @@
&-item,
&-submenu-title {
.@{menu-prefix-cls}-item-icon,
.@{iconfont-css-prefix} {
.@{menu-prefix-cls}-rtl & {
margin-right: auto;
@ -51,6 +52,7 @@
}
&.@{menu-prefix-cls}-item-only-child {
> .@{menu-prefix-cls}-item-icon,
> .@{iconfont-css-prefix} {
.@{menu-prefix-cls}-rtl & {
margin-left: 0;