Skip to content

Commit

Permalink
Merge pull request #49 from rsuite/fix-RadioGroup
Browse files Browse the repository at this point in the history
Fix event is not defined in the RadioGroup's onChange
  • Loading branch information
simonguo committed May 27, 2018
2 parents d31a459 + 60a44c0 commit 9b053bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -5,6 +5,7 @@ node_js:

env:
- BROWSER=ChromeCi
- BROWSER=Firefox

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion src/RadioGroup.js
Expand Up @@ -34,7 +34,7 @@ class RadioGroup extends React.Component<Props, State> {
return _.isUndefined(value) ? this.state.value : value;
}

handleChange = (nextValue: any, event: SyntheticInputEvent<*>) => {
handleChange = (nextValue: any, itemChecked: boolean, event: SyntheticInputEvent<*>) => {
const { onChange } = this.props;
this.setState({ value: nextValue });
onChange && onChange(nextValue, event);
Expand Down
21 changes: 21 additions & 0 deletions test/RadioGroupSpec.js
Expand Up @@ -93,6 +93,27 @@ describe('RadioGroup', () => {
ReactTestUtils.Simulate.change(radios[2].querySelector('input'));
});

it('Should call onChange callback and return correct parameters', done => {
const instance = ReactTestUtils.renderIntoDocument(
<RadioGroup
name="test"
onChange={(value, event) => {
if (value === 3 && event.target.name === 'test') {
done();
}
}}
>
<Radio value={1}>Test1</Radio>
<Radio value={2}>Test2</Radio>
<Radio value={3}>Test2</Radio>
<Radio value={4}>Test2</Radio>
</RadioGroup>
);

const radios = findDOMNode(instance).querySelectorAll('.rs-radio');
ReactTestUtils.Simulate.change(radios[2].querySelector('input'));
});

it('Should have a custom className', () => {
const instance = ReactTestUtils.renderIntoDocument(<RadioGroup className="custom" />);
assert.ok(findDOMNode(instance).className.match(/\bcustom\b/));
Expand Down

0 comments on commit 9b053bb

Please sign in to comment.