Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ListItemText] Fix primary={0} display #11686

Merged
merged 2 commits into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/material-ui/src/ListItemText/ListItemText.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ function ListItemText(props, context) {
} = props;
const { dense } = context;

let primary = primaryProp || children;
if (primary && !disableTypography) {
const hasPrimary = primaryProp || primaryProp === 0;
let primary = hasPrimary ? primaryProp : children;

if (hasPrimary && !disableTypography) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since hasPrimary is only true for primaryProp, this presumably won't work for children

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

primary = (
<Typography
variant="subheading"
Expand All @@ -60,8 +62,10 @@ function ListItemText(props, context) {
);
}

const hasSecondary = secondaryProp || secondaryProp === 0;
let secondary = secondaryProp;
if (secondary && !disableTypography) {

if (hasSecondary && !disableTypography) {
secondary = (
<Typography
variant="body1"
Expand Down
12 changes: 12 additions & 0 deletions packages/material-ui/src/ListItemText/ListItemText.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe('<ListItemText />', () => {
const wrapper = shallow(<ListItemText>{primary}</ListItemText>);
assert.strictEqual(wrapper.contains(primary), true, 'should find the node');
});

it('should read 0 as primary', () => {
const wrapper = shallow(<ListItemText primary={0} />);

assert.strictEqual(wrapper.childAt(0).type(), Typography);
});
});

describe('prop: secondary', () => {
Expand Down Expand Up @@ -91,6 +97,12 @@ describe('<ListItemText />', () => {
const wrapper = shallow(<ListItemText secondary={secondary} />);
assert.strictEqual(wrapper.contains(secondary), true, 'should find the node');
});

it('should read 0 as secondary', () => {
const wrapper = shallow(<ListItemText secondary={0} />);

assert.strictEqual(wrapper.childAt(0).type(), Typography);
});
});

describe('prop: disableTypography', () => {
Expand Down