1
+ import { TransitionGroup } from 'vue' ;
1
2
import KeyCode from '../_util/KeyCode' ;
2
3
import PropTypes from '../_util/vue-types' ;
3
4
import classnames from 'classnames' ;
@@ -8,13 +9,10 @@ import Option from './Option';
8
9
import OptGroup from './OptGroup' ;
9
10
import {
10
11
hasProp ,
11
- getSlotOptions ,
12
12
getPropsData ,
13
13
getValueByProp as getValue ,
14
14
getComponent ,
15
15
getEvents ,
16
- getClass ,
17
- getAttrs ,
18
16
getOptionProps ,
19
17
} from '../_util/props-util' ;
20
18
import getTransitionProps from '../_util/getTransitionProps' ;
@@ -106,10 +104,6 @@ const Select = {
106
104
// onDeselect: noop,
107
105
// onInputKeydown: noop,
108
106
} ,
109
- // model: {
110
- // prop: 'value',
111
- // event: 'change',
112
- // },
113
107
created ( ) {
114
108
this . saveInputRef = saveRef ( this , 'inputRef' ) ;
115
109
this . saveInputMirrorRef = saveRef ( this , 'inputMirrorRef' ) ;
@@ -175,7 +169,7 @@ const Select = {
175
169
__propsSymbol__ ( ) {
176
170
Object . assign ( this . $data , this . getDerivedState ( getOptionProps ( this ) , this . $data ) ) ;
177
171
} ,
178
- '$data. _inputValue' ( val ) {
172
+ _inputValue ( val ) {
179
173
this . $data . _mirrorInputValue = val ;
180
174
} ,
181
175
} ,
@@ -232,8 +226,8 @@ const Select = {
232
226
if ( ! child . data || child . data . slot !== undefined ) {
233
227
return ;
234
228
}
235
- if ( getSlotOptions ( child ) . isSelectOptGroup ) {
236
- this . getOptionsFromChildren ( child . componentOptions . children , options ) ;
229
+ if ( child . type ? .isSelectOptGroup ) {
230
+ this . getOptionsFromChildren ( child . children ?. default ( ) , options ) ;
237
231
} else {
238
232
options . push ( child ) ;
239
233
}
@@ -787,32 +781,31 @@ const Select = {
787
781
_getInputElement ( ) {
788
782
const props = this . $props ;
789
783
const { _inputValue : inputValue , _mirrorInputValue } = this . $data ;
790
- const attrs = getAttrs ( this ) ;
784
+ const attrs = this . $attrs ;
791
785
const defaultInput = < input id = { attrs . id } autoComplete = "off" /> ;
792
786
793
787
const inputElement = props . getInputElement ? props . getInputElement ( ) : defaultInput ;
794
- const inputCls = classnames ( getClass ( inputElement ) , {
788
+ const inputCls = classnames ( inputElement . class , {
795
789
[ `${ props . prefixCls } -search__field` ] : true ,
796
790
} ) ;
797
791
const inputEvents = getEvents ( inputElement ) ;
798
792
// https://github.com/ant-design/ant-design/issues/4992#issuecomment-281542159
799
793
// Add space to the end of the inputValue as the width measurement tolerance
800
- inputElement . data = inputElement . data || { } ;
801
794
return (
802
795
< div class = { `${ props . prefixCls } -search__field__wrap` } onClick = { this . inputClick } >
803
796
{ cloneElement ( inputElement , {
804
797
disabled : props . disabled ,
805
798
value : inputValue ,
806
- ...( inputElement . data . attrs || { } ) ,
799
+ ...( inputElement . props || { } ) ,
807
800
disabled : props . disabled ,
808
801
value : inputValue ,
809
802
class : inputCls ,
810
803
ref : this . saveInputRef ,
811
- directives : [
812
- {
813
- name : 'ant-input' ,
814
- } ,
815
- ] ,
804
+ // directives: [
805
+ // {
806
+ // name: 'ant-input',
807
+ // },
808
+ // ],
816
809
onInput : this . onInputChange ,
817
810
onKeydown : chaining (
818
811
this . onInputKeydown ,
@@ -1099,6 +1092,7 @@ const Select = {
1099
1092
const vls = this . getVLForOnChange ( value ) ;
1100
1093
const options = this . getOptionsBySingleValue ( value ) ;
1101
1094
this . _valueOptions = options ;
1095
+ this . $emit ( 'update:value' , vls ) ;
1102
1096
this . $emit ( 'change' , vls , isMultipleOrTags ( this . $props ) ? options : options [ 0 ] ) ;
1103
1097
} ,
1104
1098
@@ -1186,16 +1180,11 @@ const Select = {
1186
1180
const { _inputValue : inputValue } = this . $data ;
1187
1181
const tags = props . tags ;
1188
1182
children . forEach ( child => {
1189
- const type = child . type ;
1190
- warning (
1191
- typeof type === 'object' && type . isSelectOption ,
1192
- 'the children of `Select` should be `Select.Option` or `Select.OptGroup`, ' +
1193
- `instead of \`${ getSlotOptions ( child ) . name || getSlotOptions ( child ) } \`.` ,
1194
- ) ;
1195
- if ( typeof type !== 'object' || ! type . isSelectOption ) {
1183
+ if ( ! child ) {
1196
1184
return ;
1197
1185
}
1198
- if ( type . isSelectOptGroup ) {
1186
+ const type = child . type ;
1187
+ if ( type ?. isSelectOptGroup ) {
1199
1188
let label = getComponent ( child , 'label' ) ;
1200
1189
let key = child . key ;
1201
1190
if ( ! key && typeof label === 'string' ) {
@@ -1211,14 +1200,14 @@ const Select = {
1211
1200
const childValueSub = getValuePropValue ( subChild ) || subChild . key ;
1212
1201
return (
1213
1202
< MenuItem key = { childValueSub } value = { childValueSub } { ...subChild . props } >
1214
- { subChild . children ?. default ( ) }
1203
+ { ... ( subChild . children ?. default ( ) ) }
1215
1204
</ MenuItem >
1216
1205
) ;
1217
1206
} ) ;
1218
1207
1219
1208
sel . push (
1220
1209
< MenuItemGroup key = { key } title = { label } class = { child . props ?. class } >
1221
- { innerItems }
1210
+ { ... innerItems }
1222
1211
</ MenuItemGroup > ,
1223
1212
) ;
1224
1213
@@ -1232,14 +1221,18 @@ const Select = {
1232
1221
if ( innerItems . length ) {
1233
1222
sel . push (
1234
1223
< MenuItemGroup key = { key } title = { label } { ...child . props } >
1235
- { innerItems }
1224
+ { ... innerItems }
1236
1225
</ MenuItemGroup > ,
1237
1226
) ;
1238
1227
}
1239
1228
}
1240
1229
1241
1230
return ;
1242
1231
}
1232
+ warning (
1233
+ typeof type === 'object' && type . isSelectOption ,
1234
+ 'the children of `Select` should be `Select.Option` or `Select.OptGroup`, ' ,
1235
+ ) ;
1243
1236
1244
1237
const childValue = getValuePropValue ( child ) ;
1245
1238
@@ -1416,10 +1409,10 @@ const Select = {
1416
1409
if ( isMultipleOrTags ( props ) && choiceTransitionName ) {
1417
1410
const transitionProps = getTransitionProps ( choiceTransitionName , {
1418
1411
tag : 'ul' ,
1419
- afterLeave : this . onChoiceAnimationLeave ,
1412
+ onAfterLeave : this . onChoiceAnimationLeave ,
1420
1413
} ) ;
1421
1414
innerNode = (
1422
- < transition-group { ...transitionProps } > { selectedValueNodes } </ transition-group >
1415
+ < TransitionGroup { ...transitionProps } > { selectedValueNodes } </ TransitionGroup >
1423
1416
) ;
1424
1417
} else {
1425
1418
innerNode = < ul > { selectedValueNodes } </ ul > ;
0 commit comments