forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuItem.jsx
64 lines (63 loc) · 1.7 KB
/
MenuItem.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Item, itemProps } from '../vc-menu';
import { getOptionProps, getListeners } from '../_util/props-util';
import Tooltip from '../tooltip';
function noop() {}
export default {
name: 'MenuItem',
inheritAttrs: false,
props: itemProps,
inject: {
getInlineCollapsed: { default: () => noop },
layoutSiderContext: { default: () => ({}) },
},
isMenuItem: true,
methods: {
onKeyDown(e) {
this.$refs.menuItem.onKeyDown(e);
},
},
render() {
const props = getOptionProps(this);
const { level, title, rootPrefixCls } = props;
const { getInlineCollapsed, $slots, $attrs: attrs } = this;
const inlineCollapsed = getInlineCollapsed();
let tooltipTitle = title;
if (typeof title === 'undefined') {
tooltipTitle = level === 1 ? $slots.default : '';
} else if (title === false) {
tooltipTitle = '';
}
const tooltipProps = {
title: tooltipTitle,
};
const siderCollapsed = this.layoutSiderContext.sCollapsed;
if (!siderCollapsed && !inlineCollapsed) {
tooltipProps.title = null;
// Reset `visible` to fix control mode tooltip display not correct
// ref: https://github.com/ant-design/ant-design/issues/16742
tooltipProps.visible = false;
}
const itemProps = {
props: {
...props,
title,
},
attrs,
on: getListeners(this),
};
const toolTipProps = {
props: {
...tooltipProps,
placement: 'right',
overlayClassName: `${rootPrefixCls}-inline-collapsed-tooltip`,
},
};
return (
<Tooltip {...toolTipProps}>
<Item {...itemProps} ref="menuItem">
{$slots.default}
</Item>
</Tooltip>
);
},
};