Skip to content

Commit 4927668

Browse files
helfi92mbrookes
authored andcommitted
[ListItemText] Fix primary={0} display (#11686)
* Display 0's with ListItemText * 🌹
1 parent 64b4dac commit 4927668

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/material-ui/src/ListItemText/ListItemText.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function ListItemText(props, context) {
4747
} = props;
4848
const { dense } = context;
4949

50-
let primary = primaryProp || children;
51-
if (primary && !disableTypography) {
50+
let primary = primaryProp != null ? primaryProp : children;
51+
if (primary != null && !disableTypography) {
5252
primary = (
5353
<Typography
5454
variant="subheading"
@@ -61,7 +61,7 @@ function ListItemText(props, context) {
6161
}
6262

6363
let secondary = secondaryProp;
64-
if (secondary && !disableTypography) {
64+
if (secondary != null && !disableTypography) {
6565
secondary = (
6666
<Typography
6767
variant="body1"

packages/material-ui/src/ListItemText/ListItemText.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ describe('<ListItemText />', () => {
6363
const wrapper = shallow(<ListItemText>{primary}</ListItemText>);
6464
assert.strictEqual(wrapper.contains(primary), true, 'should find the node');
6565
});
66+
67+
it('should read 0 as primary', () => {
68+
const wrapper = shallow(<ListItemText primary={0} />);
69+
assert.strictEqual(wrapper.childAt(0).type(), Typography);
70+
});
6671
});
6772

6873
describe('prop: secondary', () => {
@@ -91,6 +96,11 @@ describe('<ListItemText />', () => {
9196
const wrapper = shallow(<ListItemText secondary={secondary} />);
9297
assert.strictEqual(wrapper.contains(secondary), true, 'should find the node');
9398
});
99+
100+
it('should read 0 as secondary', () => {
101+
const wrapper = shallow(<ListItemText secondary={0} />);
102+
assert.strictEqual(wrapper.childAt(0).type(), Typography);
103+
});
94104
});
95105

96106
describe('prop: disableTypography', () => {

0 commit comments

Comments
 (0)