File tree Expand file tree Collapse file tree 3 files changed +52
-22
lines changed Expand file tree Collapse file tree 3 files changed +52
-22
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable no-console */
2
2
import React from 'react' ;
3
- import Select , { Option , OptGroup } from 'rc-select' ;
3
+ import Select from 'rc-select' ;
4
4
import '../../assets/index.less' ;
5
5
6
6
function onChange ( value , option ) {
@@ -16,27 +16,23 @@ const Test = () => (
16
16
defaultValue = "lucy"
17
17
style = { { width : 500 } }
18
18
onChange = { onChange }
19
- >
20
- < OptGroup label = "manager" >
21
- < Option value = "jack" test-prop = "jack-prop" >
22
- < b
23
- style = { {
24
- color : 'red' ,
25
- } }
26
- >
27
- jack
28
- </ b >
29
- </ Option >
30
- < Option value = "lucy" test-prop = "lucy-prop" >
31
- lucy
32
- </ Option >
33
- </ OptGroup >
34
- < OptGroup label = "engineer" >
35
- < Option value = "yiminghe" test-prop = "yiminghe-prop" >
36
- yiminghe
37
- </ Option >
38
- </ OptGroup >
39
- </ Select >
19
+ options = { [ {
20
+ label : 'manager' ,
21
+ options : [
22
+ { label : 'jack' , value : 'jack' } ,
23
+ { label : 'lucy' , value : 'lucy' }
24
+ ] ,
25
+ } , {
26
+ label : 'engineer' ,
27
+ options : [ { label : 'yiminghe' , value : 'yiminghe' } ]
28
+ } , {
29
+ label : 'bamboo' ,
30
+ options : undefined ,
31
+ } , {
32
+ label : 'mocha' ,
33
+ options : null ,
34
+ } ] }
35
+ />
40
36
</ div >
41
37
</ div >
42
38
) ;
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
51
51
} = fillFieldNames ( fieldNames , false ) ;
52
52
53
53
function dig ( list : OptionType [ ] , isGroupOption : boolean ) {
54
+ if ( ! Array . isArray ( list ) ) {
55
+ return ;
56
+ }
57
+
54
58
list . forEach ( ( data ) => {
55
59
if ( isGroupOption || ! ( fieldOptions in data ) ) {
56
60
const value = data [ fieldValue ] ;
Original file line number Diff line number Diff line change @@ -66,4 +66,34 @@ describe('Select.Group', () => {
66
66
expect ( wrapper . find ( '.rc-select-item-group' ) . prop ( 'title' ) ) . toBeUndefined ( ) ;
67
67
} ) ;
68
68
} ) ;
69
+
70
+ it ( 'group options exist undefined/null' , ( ) => {
71
+ const wrapper = mount (
72
+ < Select
73
+ open
74
+ options = { [
75
+ {
76
+ label : 'zombiej' ,
77
+ options : [
78
+ { label : 'jackson' , value : 'jackson' } ,
79
+ ] ,
80
+ } ,
81
+ {
82
+ label : 'bamboo' ,
83
+ options : undefined ,
84
+ } ,
85
+ {
86
+ label : 'mocha' ,
87
+ options : null ,
88
+ }
89
+ ] }
90
+ />
91
+ ) ;
92
+
93
+ expect ( wrapper . find ( '.rc-select-item-group' ) . length ) . toEqual ( 3 ) ;
94
+ expect ( wrapper . find ( '.rc-select-item-option' ) . length ) . toEqual ( 1 ) ;
95
+
96
+ expect ( wrapper . find ( '.rc-select-item' ) . at ( 2 ) . prop ( 'title' ) ) . toEqual ( 'bamboo' ) ;
97
+ expect ( wrapper . find ( '.rc-select-item' ) . at ( 3 ) . prop ( 'title' ) ) . toEqual ( 'mocha' ) ;
98
+ } )
69
99
} ) ;
You can’t perform that action at this time.
0 commit comments