File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* eslint-disable no-console */
22import React from 'react' ;
3- import Select , { Option , OptGroup } from 'rc-select' ;
3+ import Select from 'rc-select' ;
44import '../../assets/index.less' ;
55
66function onChange ( value , option ) {
@@ -16,27 +16,23 @@ const Test = () => (
1616 defaultValue = "lucy"
1717 style = { { width : 500 } }
1818 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+ />
4036 </ div >
4137 </ div >
4238) ;
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
5151 } = fillFieldNames ( fieldNames , false ) ;
5252
5353 function dig ( list : OptionType [ ] , isGroupOption : boolean ) {
54+ if ( ! Array . isArray ( list ) ) {
55+ return ;
56+ }
57+
5458 list . forEach ( ( data ) => {
5559 if ( isGroupOption || ! ( fieldOptions in data ) ) {
5660 const value = data [ fieldValue ] ;
Original file line number Diff line number Diff line change @@ -66,4 +66,34 @@ describe('Select.Group', () => {
6666 expect ( wrapper . find ( '.rc-select-item-group' ) . prop ( 'title' ) ) . toBeUndefined ( ) ;
6767 } ) ;
6868 } ) ;
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+ } )
6999} ) ;
You can’t perform that action at this time.
0 commit comments