@@ -2,14 +2,15 @@ import raf from 'raf';
2
2
import PropTypes from '../_util/vue-types' ;
3
3
import Menu from '../vc-menu' ;
4
4
import scrollIntoView from 'dom-scroll-into-view' ;
5
- import { getSelectKeys , preventDefaultEvent } from './util' ;
5
+ import { getSelectKeys , preventDefaultEvent , saveRef } from './util' ;
6
6
import { cloneElement } from '../_util/vnode' ;
7
7
import BaseMixin from '../_util/BaseMixin' ;
8
- import { getSlotOptions , getComponentFromProp , getListeners } from '../_util/props-util' ;
8
+ import { getSlotOptions , findDOMNode } from '../_util/props-util' ;
9
9
10
10
export default {
11
11
name : 'DropdownMenu' ,
12
12
mixins : [ BaseMixin ] ,
13
+ inheritAttrs : false ,
13
14
props : {
14
15
ariaId : PropTypes . string ,
15
16
defaultActiveFirstOption : PropTypes . bool ,
@@ -42,6 +43,7 @@ export default {
42
43
43
44
created ( ) {
44
45
this . rafInstance = null ;
46
+ this . saveMenuRef = saveRef ( this , 'menuRef' ) ;
45
47
this . lastInputValue = this . $props . inputValue ;
46
48
this . lastVisible = false ;
47
49
} ,
@@ -86,51 +88,36 @@ export default {
86
88
// Delay to scroll since current frame item position is not ready when pre view is by filter
87
89
// https://github.com/ant-design/ant-design/issues/11268#issuecomment-406634462
88
90
this . rafInstance = raf ( ( ) => {
89
- scrollIntoView ( itemComponent , this . $refs . menuRef . $el , scrollIntoViewOpts ) ;
91
+ scrollIntoView ( itemComponent , findDOMNode ( this . menuRef ) , scrollIntoViewOpts ) ;
90
92
} ) ;
91
93
} ,
92
94
93
95
renderMenu ( ) {
94
- const props = this . $props ;
96
+ const props = { ... this . $props , ... this . $attrs } ;
95
97
const {
96
98
menuItems,
99
+ menuItemSelectedIcon,
97
100
defaultActiveFirstOption,
98
- value,
99
101
prefixCls,
100
102
multiple,
103
+ onMenuSelect,
101
104
inputValue,
102
- firstActiveValue,
103
- dropdownMenuStyle,
104
105
backfillValue,
106
+ onMenuDeselect,
105
107
visible,
106
108
} = props ;
107
- const menuItemSelectedIcon = getComponentFromProp ( this , 'menuItemSelectedIcon' ) ;
108
- const { menuDeselect, menuSelect, popupScroll } = getListeners ( this ) ;
109
+ const firstActiveValue = this . firstActiveValue ;
109
110
if ( menuItems && menuItems . length ) {
110
- const selectedKeys = getSelectKeys ( menuItems , value ) ;
111
- const menuProps = {
112
- props : {
113
- multiple,
114
- itemIcon : multiple ? menuItemSelectedIcon : null ,
115
- selectedKeys,
116
- prefixCls : `${ prefixCls } -menu` ,
117
- } ,
118
- on : { } ,
119
- style : dropdownMenuStyle ,
120
- ref : 'menuRef' ,
121
- attrs : {
122
- role : 'listbox' ,
123
- } ,
124
- } ;
125
- if ( popupScroll ) {
126
- menuProps . on . scroll = popupScroll ;
127
- }
111
+ const menuProps = { } ;
128
112
if ( multiple ) {
129
- menuProps . on . deselect = menuDeselect ;
130
- menuProps . on . select = menuSelect ;
113
+ menuProps . onDeselect = onMenuDeselect ;
114
+ menuProps . onSelect = onMenuSelect ;
131
115
} else {
132
- menuProps . on . click = menuSelect ;
116
+ menuProps . onClick = onMenuSelect ;
133
117
}
118
+
119
+ const value = this . value ;
120
+ const selectedKeys = getSelectKeys ( menuItems , value ) ;
134
121
const activeKeyProps = { } ;
135
122
136
123
let defaultActiveFirst = defaultActiveFirstOption ;
@@ -155,20 +142,16 @@ export default {
155
142
) {
156
143
foundFirst = true ;
157
144
return cloneElement ( item , {
158
- directives : [
159
- {
160
- name : 'ant-ref' ,
161
- value : ref => {
162
- this . firstActiveItem = ref ;
163
- } ,
164
- } ,
165
- ] ,
145
+ ref : ref => {
146
+ this . firstActiveItem = ref ;
147
+ } ,
166
148
} ) ;
167
149
}
168
150
return item ;
169
151
} ;
170
152
171
153
clonedMenuItems = menuItems . map ( item => {
154
+ debugger ;
172
155
if ( getSlotOptions ( item ) . isMenuItemGroup ) {
173
156
const children = item . componentOptions . children . map ( clone ) ;
174
157
return cloneElement ( item , { children } ) ;
@@ -187,15 +170,29 @@ export default {
187
170
if ( inputValue !== this . lastInputValue && ( ! lastValue || lastValue !== backfillValue ) ) {
188
171
activeKeyProps . activeKey = '' ;
189
172
}
190
- menuProps . props = { ...activeKeyProps , ...menuProps . props , defaultActiveFirst } ;
191
- return < Menu { ...menuProps } > { clonedMenuItems } </ Menu > ;
173
+ return (
174
+ < Menu
175
+ ref = { this . saveMenuRef }
176
+ style = { this . dropdownMenuStyle }
177
+ defaultActiveFirst = { defaultActiveFirst }
178
+ role = "listbox"
179
+ itemIcon = { multiple ? menuItemSelectedIcon : null }
180
+ { ...activeKeyProps }
181
+ multiple = { multiple }
182
+ { ...menuProps }
183
+ selectedKeys = { selectedKeys }
184
+ prefixCls = { `${ prefixCls } -menu` }
185
+ >
186
+ { clonedMenuItems }
187
+ </ Menu >
188
+ ) ;
192
189
}
193
190
return null ;
194
191
} ,
195
192
} ,
196
193
render ( ) {
197
194
const renderMenu = this . renderMenu ( ) ;
198
- const { popupFocus , popupScroll } = getListeners ( this ) ;
195
+ const { onPopupFocus , onPopupScroll } = this . $attrs ;
199
196
return renderMenu ? (
200
197
< div
201
198
style = { {
@@ -204,10 +201,9 @@ export default {
204
201
} }
205
202
id = { this . $props . ariaId }
206
203
tabIndex = "-1"
207
- onFocus = { popupFocus }
204
+ onFocus = { onPopupFocus }
208
205
onMousedown = { preventDefaultEvent }
209
- onScroll = { popupScroll }
210
- ref = "menuContainer"
206
+ onScroll = { onPopupScroll }
211
207
>
212
208
{ renderMenu }
213
209
</ div >
0 commit comments