Skip to content

Commit

Permalink
Merge pull request alibaba-fusion#1608 from xuhong/hotfix/fix_checkbo…
Browse files Browse the repository at this point in the history
…x_value_lost

fix(Checkbox): pass value and name to input dom
  • Loading branch information
youluna authored Feb 27, 2020
2 parents 93fc311 + 3e8f2d9 commit c034d49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/checkbox/checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class Checkbox extends UIState {
onChange(e) {
const checked = e.target.checked;
const value = this.props.value;

if (this.disabled) {
return;
}
Expand Down Expand Up @@ -214,6 +215,8 @@ class Checkbox extends UIState {
rtl,
isPreview,
renderPreview,
value,
name,
...otherProps
} = this.props;
const checked = !!this.state.checked;
Expand All @@ -231,6 +234,8 @@ class Checkbox extends UIState {
<input
{...obj.pickOthers(Checkbox.propTypes, otherProps)}
id={id}
value={value}
name={name}
disabled={disabled}
checked={checked}
type="checkbox"
Expand Down
6 changes: 6 additions & 0 deletions test/checkbox/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ describe('Checkbox', () => {
wrapper.find('input').simulate('change');
assert(onChange.calledOnce);
});
it('should return the passed value', () => {
const onChange = sinon.spy();
const wrapper = mount(<Checkbox onChange={onChange} value="banana" />);
wrapper.find('input').simulate('change');
assert(onChange.getCalls()[0].args[1].target.value === 'banana');
});
it('should call `onMouseEnter`', () => {
const onMouseEnter = sinon.spy();
const wrapper1 = mount(<Checkbox onMouseEnter={onMouseEnter} />);
Expand Down

0 comments on commit c034d49

Please sign in to comment.