diff --git a/components/layout/__tests__/index.test.js b/components/layout/__tests__/index.test.js
index 4157e94f32..878f717436 100644
--- a/components/layout/__tests__/index.test.js
+++ b/components/layout/__tests__/index.test.js
@@ -1,6 +1,8 @@
import React from 'react';
import { mount, render } from 'enzyme';
import Layout from '..';
+import Icon from '../../icon';
+import Menu from '../../menu';
const { Sider, Content } = Layout;
@@ -104,6 +106,36 @@ describe('Layout', () => {
);
expect(wrapper.find('.ant-layout').hasClass('ant-layout-has-sider')).toBe(false);
});
+
+ it('render correct with Tooltip', () => {
+ jest.useFakeTimers();
+ const wrapper = mount(
+
+
+ ,
+ );
+
+ wrapper.find('.ant-menu-item').simulate('mouseenter');
+ jest.runAllTimers();
+ wrapper.update();
+ expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
+ wrapper.find('.ant-menu-item').simulate('mouseout');
+ jest.runAllTimers();
+ wrapper.update();
+
+ wrapper.setProps({ collapsed: true });
+ wrapper.find('.ant-menu-item').simulate('mouseenter');
+ jest.runAllTimers();
+ wrapper.update();
+ expect(wrapper.find('.ant-tooltip-inner').length).toBeTruthy();
+
+ jest.useRealTimers();
+ });
});
describe('Sider onBreakpoint', () => {
diff --git a/components/menu/MenuItem.tsx b/components/menu/MenuItem.tsx
index abc3a06310..f09cef532c 100644
--- a/components/menu/MenuItem.tsx
+++ b/components/menu/MenuItem.tsx
@@ -1,7 +1,9 @@
import * as React from 'react';
import { Item } from 'rc-menu';
-import Tooltip from '../tooltip';
import { ClickParam } from '.';
+import { MenuContext, MenuContextProps } from './';
+import Tooltip from '../tooltip';
+import { SiderContext, SiderContextProps } from '../layout/Sider';
export interface MenuItemProps {
rootPrefixCls?: string;
@@ -28,17 +30,33 @@ export default class MenuItem extends React.Component {
this.menuItem = menuItem;
};
- render() {
- const { rootPrefixCls, title, ...rest } = this.props;
+ renderItem = ({ siderCollapsed }: SiderContextProps) => {
+ const { level, children, rootPrefixCls } = this.props;
+ const { title, ...rest } = this.props;
return (
-
-
-
+
+ {({ inlineCollapsed }: MenuContextProps) => {
+ let titleNode = title || (level === 1 ? children : '');
+ if (!siderCollapsed && !inlineCollapsed) {
+ titleNode = null;
+ }
+
+ return (
+
+
+
+ );
+ }}
+
);
+ };
+
+ render() {
+ return {this.renderItem};
}
}
diff --git a/components/menu/__tests__/index.test.js b/components/menu/__tests__/index.test.js
index f8c0698c01..33eaa8b6c9 100644
--- a/components/menu/__tests__/index.test.js
+++ b/components/menu/__tests__/index.test.js
@@ -494,6 +494,8 @@ describe('Menu', () => {
const text = wrapper.find('.ant-tooltip-inner').text();
expect(text).toBe('bamboo lucky');
+
+ jest.useRealTimers();
});
it('render correctly when using with Layout.Sider', () => {
@@ -608,4 +610,24 @@ describe('Menu', () => {
expect(wrapper.render()).toMatchSnapshot();
});
+
+ it('not title if not collapsed', () => {
+ jest.useFakeTimers();
+ const wrapper = mount(
+ ,
+ );
+
+ wrapper.find('.ant-menu-item').simulate('mouseenter');
+ jest.runAllTimers();
+ wrapper.update();
+
+ expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
+
+ jest.useRealTimers();
+ });
});