Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit bf487d7

Browse files
guguMatt Goo
authored and
Matt Goo
committed
fix(list): Support null as a child element for ListItem (#584)
1 parent 2f215c5 commit bf487d7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: packages/list/ListItem.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default class ListItem<T extends {} = HTMLElement> extends React.Componen
137137
}
138138

139139
renderChild = (child: React.ReactChild) => {
140-
if (typeof child === 'string' || typeof child === 'number') {
140+
if (typeof child === 'string' || typeof child === 'number' || child === null) {
141141
return child;
142142
}
143143

Diff for: test/unit/list/ListItem.test.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ test('renders a list item with default tag', () => {
7474
assert.equal(wrapper.type(), 'li');
7575
});
7676

77+
test('renders a list item with text content', () => {
78+
const wrapper = shallow(<ListItem>Test</ListItem>);
79+
assert.equal(wrapper.type(), 'li');
80+
});
81+
82+
test('renders a list item with null as a child', () => {
83+
const wrapper = shallow(<ListItem><div>Test</div>{null}</ListItem>);
84+
assert.equal(wrapper.type(), 'li');
85+
});
86+
7787
test('renders a list item with an anchor tag', () => {
7888
const wrapper = shallow(<ListItem tag='a'><div>Test</div></ListItem>);
7989
assert.equal(wrapper.type(), 'a');

0 commit comments

Comments
 (0)