File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,21 @@ describe('MenuOptions', () => {
2727 } ) ;
2828 } ) ;
2929
30+ it ( 'should accept optional (null) options' , ( ) => {
31+ const option = false ;
32+ const { output } = render (
33+ < MenuOptions >
34+ < MenuOption />
35+ { option ? < MenuOption /> : null }
36+ < MenuOption />
37+ </ MenuOptions >
38+ ) ;
39+ expect ( output . type ) . toEqual ( View ) ;
40+ const children = output . props . children ;
41+ expect ( children . length ) . toEqual ( 2 ) ;
42+ } ) ;
43+
44+
3045 it ( "should prioritize option's onSelect handler" , ( ) => {
3146 const onSelect = ( ) => 0 ;
3247 const onSelectOption = ( ) => 1 ;
Original file line number Diff line number Diff line change @@ -4,10 +4,13 @@ import { View } from 'react-native';
44const MenuOptions = ( { style, children, onSelect, customStyles } ) => (
55 < View style = { [ customStyles . optionsWrapper , style ] } >
66 {
7- React . Children . map ( children , c => React . cloneElement ( c , {
8- onSelect : c . props . onSelect || onSelect ,
9- customStyles : Object . keys ( c . props . customStyles || { } ) . length ? c . props . customStyles : customStyles
10- } ) )
7+ React . Children . map ( children , c =>
8+ React . isValidElement ( c ) ?
9+ React . cloneElement ( c , {
10+ onSelect : c . props . onSelect || onSelect ,
11+ customStyles : Object . keys ( c . props . customStyles || { } ) . length ? c . props . customStyles : customStyles
12+ } ) : c
13+ )
1114 }
1215 </ View >
1316) ;
You can’t perform that action at this time.
0 commit comments