Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/List/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,12 @@ class ListItem extends Component {
</NestedList>
) : undefined;

const hasCheckbox = leftCheckbox || rightToggle;
const simpleLabel = !primaryTogglesNestedList && (leftCheckbox || rightToggle);

return (
<div>
{
hasCheckbox ? this.createLabelElement(styles, contentChildren, other) :
simpleLabel ? this.createLabelElement(styles, contentChildren, other) :
disabled ? this.createDisabledElement(styles, contentChildren, other) : (
<EnhancedButton
containerElement={'span'}
Expand Down
39 changes: 39 additions & 0 deletions src/List/ListItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,45 @@ describe('<ListItem />', () => {
assert.strictEqual(wrapper.find(`.${testClass}`).length, 1, 'should have a div with the test class');
});

describe('props: primaryTogglesNestedList', () => {
it('should toggle nested list when true', () => {
const wrapper = shallowWithContext(
<ListItem
leftCheckbox={<div />}
primaryText="Item text"
primaryTogglesNestedList={true}
nestedItems={[
<ListItem key={1} primaryText="Nested item text" />,
]}
/>
);
const primaryTextButton = wrapper.find('EnhancedButton');

assert.strictEqual(wrapper.find(NestedList).props().open, false);

primaryTextButton.simulate('touchTap', {stopPropagation: () => {}});
assert.strictEqual(wrapper.find(NestedList).props().open, true);

primaryTextButton.simulate('touchTap', {stopPropagation: () => {}});
assert.strictEqual(wrapper.find(NestedList).props().open, false);
});

it('should not render primary text button when false', () => {
const wrapper = shallowWithContext(
<ListItem
leftCheckbox={<div />}
primaryText="Item text"
primaryTogglesNestedList={false}
nestedItems={[
<ListItem key={1} primaryText="Nested item text" />,
]}
/>
);

assert.strictEqual(wrapper.filter('EnhancedButton').length, 0);
});
});

describe('props: open', () => {
it('should initially open nested list', () => {
const wrapper = shallowWithContext(
Expand Down