Skip to content

Commit

Permalink
fix(list): Support null as a child element for ListItem (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
gugu authored and Matt Goo committed Jan 23, 2019
1 parent 2f215c5 commit bf487d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/list/ListItem.tsx
Expand Up @@ -137,7 +137,7 @@ export default class ListItem<T extends {} = HTMLElement> extends React.Componen
}

renderChild = (child: React.ReactChild) => {
if (typeof child === 'string' || typeof child === 'number') {
if (typeof child === 'string' || typeof child === 'number' || child === null) {
return child;
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/list/ListItem.test.tsx
Expand Up @@ -74,6 +74,16 @@ test('renders a list item with default tag', () => {
assert.equal(wrapper.type(), 'li');
});

test('renders a list item with text content', () => {
const wrapper = shallow(<ListItem>Test</ListItem>);
assert.equal(wrapper.type(), 'li');
});

test('renders a list item with null as a child', () => {
const wrapper = shallow(<ListItem><div>Test</div>{null}</ListItem>);
assert.equal(wrapper.type(), 'li');
});

test('renders a list item with an anchor tag', () => {
const wrapper = shallow(<ListItem tag='a'><div>Test</div></ListItem>);
assert.equal(wrapper.type(), 'a');
Expand Down

0 comments on commit bf487d7

Please sign in to comment.