Skip to content

Commit f90a747

Browse files
guanputao1991123
authored andcommitted
fix(Checkbox): group didn't honor children's indeternimated state
1 parent 602b267 commit f90a747

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/checkbox/checkbox.jsx

+12-14
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,21 @@ class Checkbox extends UIState {
9494
super(props);
9595

9696
let checked, indeterminate;
97-
if (context.__group__) {
98-
indeterminate = false;
99-
checked = isChecked(context.selectedValue, props.value);
100-
} else {
101-
if ('checked' in props) {
102-
checked = props.checked;
103-
} else {
104-
checked = props.defaultChecked;
105-
}
10697

107-
if ('indeterminate' in props) {
108-
indeterminate = props.indeterminate;
109-
} else {
110-
indeterminate = props.defaultIndeterminate;
111-
}
98+
if ('checked' in props) {
99+
checked = props.checked;
100+
} else {
101+
checked = props.defaultChecked;
112102
}
113103

104+
if ('indeterminate' in props) {
105+
indeterminate = props.indeterminate;
106+
} else {
107+
indeterminate = props.defaultIndeterminate;
108+
}
109+
if (context.__group__) {
110+
checked = isChecked(context.selectedValue, props.value);
111+
}
114112
this.state = {
115113
checked,
116114
indeterminate

test/checkbox/group-spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,15 @@ describe('Checkbox.Group', () => {
142142
assert.deepEqual(wrapper.dive().state().value, [1]);
143143
});
144144
});
145+
146+
describe('should respect children\'s indeternimate state', () => {
147+
it('should support value === 0', () => {
148+
149+
const wrapper1 = mount(<CheckboxGroup ><Checkbox defaultIndeterminate={true} >1</Checkbox></CheckboxGroup>);
150+
const wrapper2 = mount(<CheckboxGroup ><Checkbox indeterminate={true} >1</Checkbox></CheckboxGroup>);
151+
152+
assert(wrapper1.find('.indeterminate').length === 1);
153+
assert(wrapper2.find('.indeterminate').length === 1);
154+
});
155+
});
145156
});

0 commit comments

Comments
 (0)