@@ -9,7 +9,7 @@ import PropTypes from '../_util/vue-types';
9
9
import { initDefaultProps } from '../_util/props-util' ;
10
10
import useId from '../vc-select/hooks/useId' ;
11
11
import useMergedState from '../_util/hooks/useMergedState' ;
12
- import { fillFieldNames , toPathKey , toPathKeys } from './utils/commonUtil' ;
12
+ import { fillFieldNames , toPathKey , toPathKeys , SHOW_PARENT , SHOW_CHILD } from './utils/commonUtil' ;
13
13
import useEntities from './hooks/useEntities' ;
14
14
import useSearchConfig from './hooks/useSearchConfig' ;
15
15
import useSearchOptions from './hooks/useSearchOptions' ;
@@ -23,6 +23,7 @@ import { BaseSelect } from '../vc-select';
23
23
import devWarning from '../vc-util/devWarning' ;
24
24
import useMaxLevel from '../vc-tree/useMaxLevel' ;
25
25
26
+ export { SHOW_PARENT , SHOW_CHILD } ;
26
27
export interface ShowSearchType < OptionType extends BaseOptionType = DefaultOptionType > {
27
28
filter ?: ( inputValue : string , options : OptionType [ ] , fieldNames : FieldNames ) => boolean ;
28
29
render ?: ( arg ?: {
@@ -49,6 +50,7 @@ export interface InternalFieldNames extends Required<FieldNames> {
49
50
export type SingleValueType = ( string | number ) [ ] ;
50
51
51
52
export type ValueType = SingleValueType | SingleValueType [ ] ;
53
+ export type ShowCheckedStrategy = typeof SHOW_PARENT | typeof SHOW_CHILD ;
52
54
53
55
export interface BaseOptionType {
54
56
disabled ?: boolean ;
@@ -73,14 +75,11 @@ function baseCascaderProps<OptionType extends BaseOptionType = DefaultOptionType
73
75
value : { type : [ String , Number , Array ] as PropType < ValueType > } ,
74
76
defaultValue : { type : [ String , Number , Array ] as PropType < ValueType > } ,
75
77
changeOnSelect : { type : Boolean , default : undefined } ,
76
- onChange : Function as PropType <
77
- ( value : ValueType , selectedOptions ?: OptionType [ ] | OptionType [ ] [ ] ) => void
78
- > ,
79
78
displayRender : Function as PropType <
80
79
( opt : { labels : string [ ] ; selectedOptions ?: OptionType [ ] } ) => any
81
80
> ,
82
81
checkable : { type : Boolean , default : undefined } ,
83
-
82
+ showCheckedStrategy : { type : String as PropType < ShowCheckedStrategy > , default : SHOW_PARENT } ,
84
83
// Search
85
84
showSearch : {
86
85
type : [ Boolean , Object ] as PropType < boolean | ShowSearchType < OptionType > > ,
@@ -184,7 +183,7 @@ function toRawValues(value: ValueType): SingleValueType[] {
184
183
return value ;
185
184
}
186
185
187
- return value . length === 0 ? [ ] : [ value ] ;
186
+ return ( value . length === 0 ? [ ] : [ value ] ) . map ( val => ( Array . isArray ( val ) ? val : [ val ] ) ) ;
188
187
}
189
188
190
189
export default defineComponent ( {
@@ -215,10 +214,10 @@ export default defineComponent({
215
214
216
215
/** Convert path key back to value format */
217
216
const getValueByKeyPath = ( pathKeys : Key [ ] ) : SingleValueType [ ] => {
218
- const ketPathEntities = pathKeyEntities . value ;
217
+ const keyPathEntities = pathKeyEntities . value ;
219
218
220
219
return pathKeys . map ( pathKey => {
221
- const { nodes } = ketPathEntities [ pathKey ] ;
220
+ const { nodes } = keyPathEntities [ pathKey ] ;
222
221
223
222
return nodes . map ( node => node [ mergedFieldNames . value . value ] ) ;
224
223
} ) ;
@@ -275,12 +274,12 @@ export default defineComponent({
275
274
}
276
275
277
276
const keyPathValues = toPathKeys ( existValues ) ;
278
- const ketPathEntities = pathKeyEntities . value ;
277
+ const keyPathEntities = pathKeyEntities . value ;
279
278
280
279
const { checkedKeys, halfCheckedKeys } = conductCheck (
281
280
keyPathValues ,
282
281
true ,
283
- ketPathEntities ,
282
+ keyPathEntities ,
284
283
maxLevel . value ,
285
284
levelEntities . value ,
286
285
) ;
@@ -295,7 +294,11 @@ export default defineComponent({
295
294
296
295
const deDuplicatedValues = computed ( ( ) => {
297
296
const checkedKeys = toPathKeys ( checkedValues . value ) ;
298
- const deduplicateKeys = formatStrategyValues ( checkedKeys , pathKeyEntities . value ) ;
297
+ const deduplicateKeys = formatStrategyValues (
298
+ checkedKeys ,
299
+ pathKeyEntities . value ,
300
+ props . showCheckedStrategy ,
301
+ ) ;
299
302
return [ ...missingCheckedValues . value , ...getValueByKeyPath ( deduplicateKeys ) ] ;
300
303
} ) ;
301
304
@@ -330,6 +333,7 @@ export default defineComponent({
330
333
331
334
// =========================== Select ===========================
332
335
const onInternalSelect = ( valuePath : SingleValueType ) => {
336
+ setSearchValue ( '' ) ;
333
337
if ( ! multiple . value ) {
334
338
triggerChange ( valuePath ) ;
335
339
} else {
@@ -379,7 +383,11 @@ export default defineComponent({
379
383
}
380
384
381
385
// Roll up to parent level keys
382
- const deDuplicatedKeys = formatStrategyValues ( checkedKeys , pathKeyEntities . value ) ;
386
+ const deDuplicatedKeys = formatStrategyValues (
387
+ checkedKeys ,
388
+ pathKeyEntities . value ,
389
+ props . showCheckedStrategy ,
390
+ ) ;
383
391
nextCheckedValues = getValueByKeyPath ( deDuplicatedKeys ) ;
384
392
}
385
393
@@ -537,7 +545,7 @@ export default defineComponent({
537
545
return ( ) => {
538
546
const emptyOptions = ! ( mergedSearchValue . value ? searchOptions . value : mergedOptions . value )
539
547
. length ;
540
-
548
+ const { dropdownMatchSelectWidth = false } = props ;
541
549
const dropdownStyle : CSSProperties =
542
550
// Search to match width
543
551
( mergedSearchValue . value && mergedSearchConfig . value . matchInputWidth ) ||
@@ -555,7 +563,7 @@ export default defineComponent({
555
563
ref = { selectRef }
556
564
id = { mergedId }
557
565
prefixCls = { props . prefixCls }
558
- dropdownMatchSelectWidth = { false }
566
+ dropdownMatchSelectWidth = { dropdownMatchSelectWidth }
559
567
dropdownStyle = { { ...mergedDropdownStyle . value , ...dropdownStyle } }
560
568
// Value
561
569
displayValues = { displayValues . value }
0 commit comments