Skip to content

Commit

Permalink
fix(Checkbox): group didn't honor children's indeternimated state
Browse files Browse the repository at this point in the history
  • Loading branch information
guanpu authored and tao1991123 committed Jan 30, 2019
1 parent 602b267 commit f90a747
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/checkbox/checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,21 @@ class Checkbox extends UIState {
super(props);

let checked, indeterminate;
if (context.__group__) {
indeterminate = false;
checked = isChecked(context.selectedValue, props.value);
} else {
if ('checked' in props) {
checked = props.checked;
} else {
checked = props.defaultChecked;
}

if ('indeterminate' in props) {
indeterminate = props.indeterminate;
} else {
indeterminate = props.defaultIndeterminate;
}
if ('checked' in props) {
checked = props.checked;
} else {
checked = props.defaultChecked;
}

if ('indeterminate' in props) {
indeterminate = props.indeterminate;
} else {
indeterminate = props.defaultIndeterminate;
}
if (context.__group__) {
checked = isChecked(context.selectedValue, props.value);
}
this.state = {
checked,
indeterminate
Expand Down
11 changes: 11 additions & 0 deletions test/checkbox/group-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ describe('Checkbox.Group', () => {
assert.deepEqual(wrapper.dive().state().value, [1]);
});
});

describe('should respect children\'s indeternimate state', () => {
it('should support value === 0', () => {

const wrapper1 = mount(<CheckboxGroup ><Checkbox defaultIndeterminate={true} >1</Checkbox></CheckboxGroup>);
const wrapper2 = mount(<CheckboxGroup ><Checkbox indeterminate={true} >1</Checkbox></CheckboxGroup>);

assert(wrapper1.find('.indeterminate').length === 1);
assert(wrapper2.find('.indeterminate').length === 1);
});
});
});

0 comments on commit f90a747

Please sign in to comment.