Browse Source

feat: Menu.Item Tooltip could be hidden by title prop (#22202)

* feat: Menu.Item Tooltip could be hidden by title prop

close #11252

* handle title false situation
pull/22207/head
偏右 5 years ago
committed by GitHub
parent
commit
e9862c5bc3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      components/menu/MenuItem.tsx
  2. 37
      components/menu/__tests__/index.test.js

8
components/menu/MenuItem.tsx

@ -44,8 +44,14 @@ export default class MenuItem extends React.Component<MenuItemProps> {
return (
<MenuContext.Consumer>
{({ inlineCollapsed, direction }: MenuContextProps) => {
let tooltipTitle = title;
if (typeof title === 'undefined') {
tooltipTitle = level === 1 ? children : '';
} else if (title === false) {
tooltipTitle = '';
}
const tooltipProps: TooltipProps = {
title: title || (level === 1 ? children : ''),
title: tooltipTitle,
};
if (!siderCollapsed && !inlineCollapsed) {

37
components/menu/__tests__/index.test.js

@ -3,6 +3,7 @@ import { mount } from 'enzyme';
import Menu from '..';
import Icon from '../../icon';
import Layout from '../../layout';
import Tooltip from '../../tooltip';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { resetWarned } from '../../_util/warning';
@ -372,6 +373,42 @@ describe('Menu', () => {
).toBe(false);
});
it('inlineCollapsed Menu.Item Tooltip can be removed', () => {
const wrapper = mount(
<Menu
defaultOpenKeys={['not-existed']}
mode="inline"
inlineCollapsed
getPopupContainer={node => node.parentNode}
>
<Menu.Item key="menu1">
item
</Menu.Item>
<Menu.Item key="menu2" title="title">
item
</Menu.Item>
<Menu.Item key="menu3" title={undefined}>
item
</Menu.Item>
<Menu.Item key="menu4" title={null}>
item
</Menu.Item>
<Menu.Item key="menu5" title="">
item
</Menu.Item>
<Menu.Item key="menu6" title={false}>
item
</Menu.Item>
</Menu>,
);
expect(wrapper.find(Menu.Item).at(0).find(Tooltip).props().title).toBe('item');
expect(wrapper.find(Menu.Item).at(1).find(Tooltip).props().title).toBe('title');
expect(wrapper.find(Menu.Item).at(2).find(Tooltip).props().title).toBe('item');
expect(wrapper.find(Menu.Item).at(3).find(Tooltip).props().title).toBe(null);
expect(wrapper.find(Menu.Item).at(4).find(Tooltip).props().title).toBe('');
expect(wrapper.find(Menu.Item).at(4).find(Tooltip).props().title).toBe('');
});
describe('open submenu when click submenu title', () => {
beforeEach(() => {
jest.useFakeTimers();

Loading…
Cancel
Save