Skip to content

Commit 1d6c277

Browse files
committed
fix #9: allow optional (null) menu options
1 parent 64c9785 commit 1d6c277

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

__tests__/MenuOptions-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

src/MenuOptions.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { View } from 'react-native';
44
const 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
);

0 commit comments

Comments
 (0)