1
1
import PropTypes from '../_util/vue-types' ;
2
2
import { getComponent , getSlot } from '../_util/props-util' ;
3
3
import { menuAllProps } from './util' ;
4
- import { defineComponent } from 'vue' ;
5
-
4
+ import { defineComponent , inject } from 'vue' ;
5
+ import classNames from '../_util/classNames' ;
6
+ const injectExtraPropsKey = 'ANT_MENU_PROVIDER_PROPS_KEY' ;
6
7
const MenuItemGroup = {
7
8
name : 'MenuItemGroup' ,
8
9
inheritAttrs : false ,
10
+ setup ( ) {
11
+ return {
12
+ injectExtraProps : inject ( injectExtraPropsKey , ( ) => ( { } ) ) ,
13
+ } ;
14
+ } ,
9
15
props : {
10
16
renderMenuItem : PropTypes . func ,
11
17
index : PropTypes . number ,
@@ -18,12 +24,12 @@ const MenuItemGroup = {
18
24
isMenuItemGroup : true ,
19
25
methods : {
20
26
renderInnerMenuItem ( item ) {
21
- const { renderMenuItem, index, subMenuKey } = this . $props ;
27
+ const { renderMenuItem, index, subMenuKey } = { ... this . $props , ... this . injectExtraProps } ;
22
28
return renderMenuItem ( item , index , subMenuKey ) ;
23
29
} ,
24
30
} ,
25
31
render ( ) {
26
- const props = { ...this . $props , ...this . $attrs } ;
32
+ const props = { ...this . $props , ...this . injectExtraProps , ... this . $attrs } ;
27
33
const { class : cls = '' , rootPrefixCls, title } = props ;
28
34
const titleClassName = `${ rootPrefixCls } -item-group-title` ;
29
35
const listClassName = `${ rootPrefixCls } -item-group-list` ;
@@ -32,7 +38,7 @@ const MenuItemGroup = {
32
38
delete props . onClick ;
33
39
const children = getSlot ( this ) ;
34
40
return (
35
- < li { ...props } class = { ` ${ cls } ${ rootPrefixCls } -item-group`} >
41
+ < li { ...props } class = { classNames ( cls , ` ${ rootPrefixCls } -item-group`) } >
36
42
< div class = { titleClassName } title = { typeof title === 'string' ? title : undefined } >
37
43
{ getComponent ( this , 'title' ) }
38
44
</ div >
0 commit comments