Skip to content

Commit

Permalink
fix: MenuItem with icon only will still have additional margin (#21925)
Browse files Browse the repository at this point in the history
* fix: MenuItem with icon only will still have additional margin

* update snapshot

* fix snapshot
  • Loading branch information
zombieJ committed Mar 6, 2020
1 parent 36c05dd commit e8876d5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7784,7 +7784,7 @@ exports[`ConfigProvider components Menu configProvider 1`] = `
class="config-menu-item-group-list"
>
<li
class="config-menu-item"
class="config-menu-item config-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
Expand Down Expand Up @@ -7838,7 +7838,7 @@ exports[`ConfigProvider components Menu normal 1`] = `
class="ant-menu-item-group-list"
>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
Expand Down Expand Up @@ -7892,7 +7892,7 @@ exports[`ConfigProvider components Menu prefixCls 1`] = `
class="prefix-Menu-item-group-list"
>
<li
class="prefix-Menu-item"
class="prefix-Menu-item prefix-Menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
Expand Down
3 changes: 3 additions & 0 deletions components/form/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ describe('Form', () => {
).toEqual("'name' is required");

await change(wrapper, 0, 'p');
await delay(100);
wrapper.update();

expect(
wrapper
.find('.ant-form-item-explain')
Expand Down
42 changes: 21 additions & 21 deletions components/layout/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ exports[`renders ./components/layout/demo/fixed.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 1
Expand All @@ -331,7 +331,7 @@ exports[`renders ./components/layout/demo/fixed.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
>
nav 2
Expand All @@ -356,7 +356,7 @@ exports[`renders ./components/layout/demo/fixed.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 3
Expand Down Expand Up @@ -1170,7 +1170,7 @@ exports[`renders ./components/layout/demo/side.md correctly 1`] = `
<div />
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:24px"
>
Expand Down Expand Up @@ -1315,7 +1315,7 @@ exports[`renders ./components/layout/demo/top.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 1
Expand All @@ -1340,7 +1340,7 @@ exports[`renders ./components/layout/demo/top.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
>
nav 2
Expand All @@ -1365,7 +1365,7 @@ exports[`renders ./components/layout/demo/top.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 3
Expand Down Expand Up @@ -1486,7 +1486,7 @@ exports[`renders ./components/layout/demo/top-side.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 1
Expand All @@ -1511,7 +1511,7 @@ exports[`renders ./components/layout/demo/top-side.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
>
nav 2
Expand All @@ -1536,7 +1536,7 @@ exports[`renders ./components/layout/demo/top-side.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 3
Expand Down Expand Up @@ -1668,28 +1668,28 @@ exports[`renders ./components/layout/demo/top-side.md correctly 1`] = `
role="menu"
>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
style="padding-left:48px"
>
option1
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
option2
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
option3
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
Expand Down Expand Up @@ -1832,7 +1832,7 @@ exports[`renders ./components/layout/demo/top-side-2.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 1
Expand All @@ -1857,7 +1857,7 @@ exports[`renders ./components/layout/demo/top-side-2.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
>
nav 2
Expand All @@ -1882,7 +1882,7 @@ exports[`renders ./components/layout/demo/top-side-2.md correctly 1`] = `
</div>
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
>
nav 3
Expand Down Expand Up @@ -1968,28 +1968,28 @@ exports[`renders ./components/layout/demo/top-side-2.md correctly 1`] = `
role="menu"
>
<li
class="ant-menu-item ant-menu-item-selected"
class="ant-menu-item ant-menu-item-only-child ant-menu-item-selected"
role="menuitem"
style="padding-left:48px"
>
option1
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
option2
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
option3
</li>
<li
class="ant-menu-item"
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
>
Expand Down
13 changes: 11 additions & 2 deletions components/menu/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react';
import { Item } from 'rc-menu';
import toArray from 'rc-util/lib/Children/toArray';
import classNames from 'classnames';
import { ClickParam } from '.';
import MenuContext, { MenuContextProps } from './MenuContext';
import Tooltip, { TooltipProps } from '../tooltip';
Expand Down Expand Up @@ -36,7 +38,7 @@ export default class MenuItem extends React.Component<MenuItemProps> {
};

renderItem = ({ siderCollapsed }: SiderContextProps) => {
const { level, children, rootPrefixCls } = this.props;
const { level, className, children, rootPrefixCls } = this.props;
const { title, ...rest } = this.props;

return (
Expand All @@ -58,7 +60,14 @@ export default class MenuItem extends React.Component<MenuItemProps> {
placement={direction === 'rtl' ? 'left' : 'right'}
overlayClassName={`${rootPrefixCls}-inline-collapsed-tooltip`}
>
<Item {...rest} title={title} ref={this.saveMenuItem} />
<Item
{...rest}
className={classNames(className, {
[`${rootPrefixCls}-item-only-child`]: toArray(children).length === 1,
})}
title={title}
ref={this.saveMenuItem}
/>
</Tooltip>
);
}}
Expand Down
Loading

0 comments on commit e8876d5

Please sign in to comment.