Skip to content

Commit 8933cc5

Browse files
committed
feat: menu add title
1 parent 7b5fb53 commit 8933cc5

File tree

6 files changed

+59
-23
lines changed

6 files changed

+59
-23
lines changed

components/menu/MenuItem.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getOptionProps } from '../_util/props-util'
44
import Tooltip from '../tooltip'
55
function noop () {}
66
export default {
7+
inheritAttrs: false,
78
props: itemProps,
89
name: 'MenuItem',
910
inject: {
@@ -17,18 +18,27 @@ export default {
1718
},
1819
render (h) {
1920
const props = getOptionProps(this)
21+
const { level, title, rootPrefixCls } = props
2022
const { getInlineCollapsed, $slots, $attrs: attrs, $listeners } = this
2123
const inlineCollapsed = getInlineCollapsed()
24+
let titleNode
25+
if (inlineCollapsed) {
26+
titleNode = title || (level === 1 ? $slots.default : '')
27+
}
28+
2229
const itemProps = {
23-
props,
30+
props: {
31+
...props,
32+
title: inlineCollapsed ? null : title,
33+
},
2434
attrs,
2535
on: $listeners,
2636
}
2737
const toolTipProps = {
2838
props: {
29-
title: inlineCollapsed && props.level === 1 ? $slots.default : '',
39+
title: titleNode,
3040
placement: 'right',
31-
overlayClassName: `${props.rootPrefixCls}-inline-collapsed-tooltip`,
41+
overlayClassName: `${rootPrefixCls}-inline-collapsed-tooltip`,
3242
},
3343
}
3444
return (

components/menu/__tests__/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,32 @@ describe('Menu', () => {
455455
}, 500)
456456
})
457457
})
458+
459+
it('inline title', async () => {
460+
const wrapper = mount({
461+
render () {
462+
return (
463+
<Menu mode='inline' inlineCollapsed>
464+
<Menu.Item key='1' title='bamboo lucky'>
465+
<Icon type='pie-chart' />
466+
<span>
467+
Option 1
468+
<img
469+
style={{ width: 20 }}
470+
alt='test'
471+
src='https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg'
472+
/>
473+
</span>
474+
</Menu.Item>
475+
</Menu>
476+
)
477+
},
478+
}, { sync: false, attachToDocument: true })
479+
480+
wrapper.find('.ant-menu-item').trigger('mouseenter')
481+
await asyncExpect(() => {
482+
const text = $$('.ant-tooltip-inner')[0].textContent
483+
expect(text).toBe('bamboo lucky')
484+
}, 500)
485+
})
458486
})

components/menu/demo/inline-collapsed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ export default {
6767
},
6868
}
6969
</script>
70-
```
70+
```

components/menu/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
| ----- | ----------- | ---- | ------------- |
4747
| disabled | whether menu item is disabled or not | boolean | false |
4848
| key | unique id of the menu item | string | |
49+
| title | set display title for collapsed item | string | |
4950

5051
### Menu.SubMenu
5152

components/menu/index.jsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Menu = {
4545
mixins: [BaseMixin],
4646
inject: {
4747
layoutSiderContext: { default: {}},
48+
configProvider: { default: {}},
4849
},
4950
model: {
5051
prop: 'selectedKeys',
@@ -176,26 +177,19 @@ const Menu = {
176177
const { openAnimation, openTransitionName } = this.$props
177178
let menuOpenAnimation = openAnimation || openTransitionName
178179
if (openAnimation === undefined && openTransitionName === undefined) {
179-
switch (menuMode) {
180-
case 'horizontal':
181-
menuOpenAnimation = 'slide-up'
182-
break
183-
case 'vertical':
184-
case 'vertical-left':
185-
case 'vertical-right':
180+
if (menuMode === 'horizontal') {
181+
menuOpenAnimation = 'slide-up'
182+
} else if (menuMode === 'inline') {
183+
menuOpenAnimation = { on: animation }
184+
} else {
186185
// When mode switch from inline
187186
// submenu should hide without animation
188-
if (this.switchingModeFromInline) {
189-
menuOpenAnimation = ''
190-
this.switchingModeFromInline = false
191-
} else {
192-
menuOpenAnimation = 'zoom-big'
193-
}
194-
break
195-
case 'inline':
196-
menuOpenAnimation = { on: animation }
197-
break
198-
default:
187+
if (this.switchingModeFromInline) {
188+
menuOpenAnimation = ''
189+
this.switchingModeFromInline = false
190+
} else {
191+
menuOpenAnimation = 'zoom-big'
192+
}
199193
}
200194
}
201195
return menuOpenAnimation
@@ -204,7 +198,8 @@ const Menu = {
204198
render () {
205199
const { layoutSiderContext, $slots, $listeners } = this
206200
const { collapsedWidth } = layoutSiderContext
207-
const { prefixCls, theme } = this.$props
201+
const { getPopupContainer: getContextPopupContainer } = this.configProvider
202+
const { prefixCls, theme, getPopupContainer } = this.$props
208203
const menuMode = this.getRealMenuMode()
209204
const menuOpenAnimation = this.getMenuOpenAnimation(menuMode)
210205

@@ -216,6 +211,7 @@ const Menu = {
216211
const menuProps = {
217212
props: {
218213
...omit(this.$props, ['inlineCollapsed']),
214+
getPopupContainer: getPopupContainer || getContextPopupContainer,
219215
openKeys: this.sOpenKeys,
220216
mode: menuMode,
221217
},

components/menu/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
| --- | --- | --- | --- |
4545
| disabled | 是否禁用 | boolean | false |
4646
| key | item 的唯一标志 | string | |
47+
| title | 设置收缩时展示的悬浮标题 | string | |
4748

4849
### Menu.SubMenu
4950

0 commit comments

Comments
 (0)