Skip to content

Commit 5ae7425

Browse files
Merge pull request #4988 from rafaelsales/master
[ListItem] Fix primaryTogglesNestedList not working with checkbox #4753
2 parents 66d7f15 + 40e90c6 commit 5ae7425

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/List/ListItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,12 @@ class ListItem extends Component {
641641
</NestedList>
642642
) : undefined;
643643

644-
const hasCheckbox = leftCheckbox || rightToggle;
644+
const simpleLabel = !primaryTogglesNestedList && (leftCheckbox || rightToggle);
645645

646646
return (
647647
<div>
648648
{
649-
hasCheckbox ? this.createLabelElement(styles, contentChildren, other) :
649+
simpleLabel ? this.createLabelElement(styles, contentChildren, other) :
650650
disabled ? this.createDisabledElement(styles, contentChildren, other) : (
651651
<EnhancedButton
652652
containerElement={'span'}

src/List/ListItem.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,45 @@ describe('<ListItem />', () => {
7575
assert.strictEqual(wrapper.find(`.${testClass}`).length, 1, 'should have a div with the test class');
7676
});
7777

78+
describe('props: primaryTogglesNestedList', () => {
79+
it('should toggle nested list when true', () => {
80+
const wrapper = shallowWithContext(
81+
<ListItem
82+
leftCheckbox={<div />}
83+
primaryText="Item text"
84+
primaryTogglesNestedList={true}
85+
nestedItems={[
86+
<ListItem key={1} primaryText="Nested item text" />,
87+
]}
88+
/>
89+
);
90+
const primaryTextButton = wrapper.find('EnhancedButton');
91+
92+
assert.strictEqual(wrapper.find(NestedList).props().open, false);
93+
94+
primaryTextButton.simulate('touchTap', {stopPropagation: () => {}});
95+
assert.strictEqual(wrapper.find(NestedList).props().open, true);
96+
97+
primaryTextButton.simulate('touchTap', {stopPropagation: () => {}});
98+
assert.strictEqual(wrapper.find(NestedList).props().open, false);
99+
});
100+
101+
it('should not render primary text button when false', () => {
102+
const wrapper = shallowWithContext(
103+
<ListItem
104+
leftCheckbox={<div />}
105+
primaryText="Item text"
106+
primaryTogglesNestedList={false}
107+
nestedItems={[
108+
<ListItem key={1} primaryText="Nested item text" />,
109+
]}
110+
/>
111+
);
112+
113+
assert.strictEqual(wrapper.filter('EnhancedButton').length, 0);
114+
});
115+
});
116+
78117
describe('props: open', () => {
79118
it('should initially open nested list', () => {
80119
const wrapper = shallowWithContext(

0 commit comments

Comments
 (0)