1
+ import { provide , inject } from 'vue' ;
1
2
import warning from '../_util/warning' ;
2
3
import omit from 'omit.js' ;
3
4
import PropTypes from '../_util/vue-types' ;
4
5
import { Select as VcSelect , Option , OptGroup } from '../vc-select' ;
5
6
import { ConfigConsumerProps } from '../config-provider' ;
6
7
import {
7
- getComponentFromProp ,
8
+ getComponent ,
8
9
getOptionProps ,
9
10
filterEmpty ,
10
11
isValidElement ,
11
- getListeners ,
12
+ getSlot ,
12
13
} from '../_util/props-util' ;
13
14
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined' ;
14
15
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled' ;
15
16
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined' ;
16
17
import DownOutlined from '@ant-design/icons-vue/DownOutlined' ;
17
18
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined' ;
18
19
import { cloneElement } from '../_util/vnode' ;
19
- import Base from '../base' ;
20
20
21
21
const AbstractSelectProps = ( ) => ( {
22
22
prefixCls : PropTypes . string ,
@@ -107,19 +107,13 @@ const Select = {
107
107
choiceTransitionName : PropTypes . string . def ( 'zoom' ) ,
108
108
} ,
109
109
propTypes : SelectPropTypes ,
110
- model : {
111
- prop : 'value' ,
112
- event : 'change' ,
113
- } ,
114
- provide ( ) {
110
+ setup ( ) {
115
111
return {
116
- savePopupRef : this . savePopupRef ,
112
+ configProvider : inject ( 'configProvider' , ConfigConsumerProps ) ,
117
113
} ;
118
114
} ,
119
- inject : {
120
- configProvider : { default : ( ) => ConfigConsumerProps } ,
121
- } ,
122
115
created ( ) {
116
+ provide ( 'savePopupRef' , this . savePopupRef ) ;
123
117
warning (
124
118
this . $props . mode !== 'combobox' ,
125
119
'Select' ,
@@ -130,15 +124,14 @@ const Select = {
130
124
} ,
131
125
methods : {
132
126
getNotFoundContent ( renderEmpty ) {
133
- const h = this . $createElement ;
134
- const notFoundContent = getComponentFromProp ( this , 'notFoundContent' ) ;
127
+ const notFoundContent = getComponent ( this , 'notFoundContent' ) ;
135
128
if ( notFoundContent !== undefined ) {
136
129
return notFoundContent ;
137
130
}
138
131
if ( this . isCombobox ( ) ) {
139
132
return null ;
140
133
}
141
- return renderEmpty ( h , 'Select' ) ;
134
+ return renderEmpty ( 'Select' ) ;
142
135
} ,
143
136
savePopupRef ( ref ) {
144
137
this . popupRef = ref ;
@@ -157,7 +150,7 @@ const Select = {
157
150
158
151
renderSuffixIcon ( prefixCls ) {
159
152
const { loading } = this . $props ;
160
- let suffixIcon = getComponentFromProp ( this , 'suffixIcon' ) ;
153
+ let suffixIcon = getComponent ( this , 'suffixIcon' ) ;
161
154
suffixIcon = Array . isArray ( suffixIcon ) ? suffixIcon [ 0 ] : suffixIcon ;
162
155
if ( suffixIcon ) {
163
156
return isValidElement ( suffixIcon )
@@ -180,17 +173,18 @@ const Select = {
180
173
showArrow,
181
174
...restProps
182
175
} = getOptionProps ( this ) ;
176
+ const { class : className } = this . $attrs ;
183
177
184
178
const getPrefixCls = this . configProvider . getPrefixCls ;
185
179
const renderEmpty = this . configProvider . renderEmpty ;
186
180
const prefixCls = getPrefixCls ( 'select' , customizePrefixCls ) ;
187
181
188
182
const { getPopupContainer : getContextPopupContainer } = this . configProvider ;
189
- let removeIcon = getComponentFromProp ( this , 'removeIcon' ) ;
183
+ let removeIcon = getComponent ( this , 'removeIcon' ) ;
190
184
removeIcon = Array . isArray ( removeIcon ) ? removeIcon [ 0 ] : removeIcon ;
191
- let clearIcon = getComponentFromProp ( this , 'clearIcon' ) ;
185
+ let clearIcon = getComponent ( this , 'clearIcon' ) ;
192
186
clearIcon = Array . isArray ( clearIcon ) ? clearIcon [ 0 ] : clearIcon ;
193
- let menuItemSelectedIcon = getComponentFromProp ( this , 'menuItemSelectedIcon' ) ;
187
+ let menuItemSelectedIcon = getComponent ( this , 'menuItemSelectedIcon' ) ;
194
188
menuItemSelectedIcon = Array . isArray ( menuItemSelectedIcon )
195
189
? menuItemSelectedIcon [ 0 ]
196
190
: menuItemSelectedIcon ;
@@ -203,6 +197,7 @@ const Select = {
203
197
] ) ;
204
198
205
199
const cls = {
200
+ [ className ] : className ,
206
201
[ `${ prefixCls } -lg` ] : size === 'large' ,
207
202
[ `${ prefixCls } -sm` ] : size === 'small' ,
208
203
[ `${ prefixCls } -show-arrow` ] : showArrow ,
@@ -235,34 +230,32 @@ const Select = {
235
230
: menuItemSelectedIcon ) ) || < CheckOutlined class = { `${ prefixCls } -selected-icon` } /> ;
236
231
237
232
const selectProps = {
238
- props : {
239
- inputIcon : this . renderSuffixIcon ( prefixCls ) ,
240
- removeIcon : finalRemoveIcon ,
241
- clearIcon : finalClearIcon ,
242
- menuItemSelectedIcon : finalMenuItemSelectedIcon ,
243
- showArrow,
244
- ...rest ,
245
- ...modeConfig ,
246
- prefixCls,
247
- optionLabelProp : optionLabelProp || 'children' ,
248
- notFoundContent : this . getNotFoundContent ( renderEmpty ) ,
249
- maxTagPlaceholder : getComponentFromProp ( this , 'maxTagPlaceholder' ) ,
250
- placeholder : getComponentFromProp ( this , 'placeholder' ) ,
251
- children : options
252
- ? options . map ( option => {
253
- const { key, label = option . title , on, class : cls , style, ...restOption } = option ;
254
- return (
255
- < Option key = { key } { ...{ props : restOption , on, class : cls , style } } >
256
- { label }
257
- </ Option >
258
- ) ;
259
- } )
260
- : filterEmpty ( this . $slots . default ) ,
261
- __propsSymbol__ : Symbol ( ) ,
262
- dropdownRender : getComponentFromProp ( this , 'dropdownRender' , { } , false ) ,
263
- getPopupContainer : getPopupContainer || getContextPopupContainer ,
264
- } ,
265
- on : getListeners ( this ) ,
233
+ inputIcon : this . renderSuffixIcon ( prefixCls ) ,
234
+ removeIcon : finalRemoveIcon ,
235
+ clearIcon : finalClearIcon ,
236
+ menuItemSelectedIcon : finalMenuItemSelectedIcon ,
237
+ showArrow,
238
+ ...rest ,
239
+ ...modeConfig ,
240
+ prefixCls,
241
+ optionLabelProp : optionLabelProp || 'children' ,
242
+ notFoundContent : this . getNotFoundContent ( renderEmpty ) ,
243
+ maxTagPlaceholder : getComponent ( this , 'maxTagPlaceholder' ) ,
244
+ placeholder : getComponent ( this , 'placeholder' ) ,
245
+ children : options
246
+ ? options . map ( option => {
247
+ const { key, label = option . title , on, class : cls , style, ...restOption } = option ;
248
+ return (
249
+ < Option key = { key } { ...{ on, class : cls , style, ...restOption } } >
250
+ { label }
251
+ </ Option >
252
+ ) ;
253
+ } )
254
+ : filterEmpty ( getSlot ( this ) ) ,
255
+ __propsSymbol__ : Symbol ( ) ,
256
+ dropdownRender : getComponent ( this , 'dropdownRender' , { } , false ) ,
257
+ getPopupContainer : getPopupContainer || getContextPopupContainer ,
258
+ ...this . $attrs ,
266
259
class : cls ,
267
260
ref : 'vcSelect' ,
268
261
} ;
@@ -271,11 +264,9 @@ const Select = {
271
264
} ;
272
265
273
266
/* istanbul ignore next */
274
- Select . install = function ( Vue ) {
275
- Vue . use ( Base ) ;
276
- Vue . component ( Select . name , Select ) ;
277
- Vue . component ( Select . Option . name , Select . Option ) ;
278
- Vue . component ( Select . OptGroup . name , Select . OptGroup ) ;
267
+ Select . install = function ( app ) {
268
+ app . component ( Select . name , Select ) ;
269
+ app . component ( Select . Option . name , Select . Option ) ;
270
+ app . component ( Select . OptGroup . name , Select . OptGroup ) ;
279
271
} ;
280
-
281
272
export default Select ;
0 commit comments