Skip to content

Commit 1e97f5e

Browse files
author
luqin
authored
Merge pull request #27 from jooj123/patch/set-correct-target
Set correct target for onChange callback when label is not used
2 parents 11ec2e3 + f1546b1 commit 1e97f5e

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

dist/react-icheck.js

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-icheck.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/EnhancedSwitch.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ var EnhancedSwitch = (function (_React$Component) {
284284
checked: checked
285285
});
286286
}
287+
287288
if (this.props.onChange) {
288289
this.props.onChange(e, checked);
289290
}
@@ -321,8 +322,6 @@ var EnhancedSwitch = (function (_React$Component) {
321322
return;
322323
}
323324

324-
// let type = event.type;
325-
326325
var newChecked = !this.refs.checkbox.checked;
327326

328327
if (!('checked' in this.props)) {
@@ -334,7 +333,10 @@ var EnhancedSwitch = (function (_React$Component) {
334333

335334
event.preventDefault();
336335
event.stopPropagation();
337-
if (this.props.onChange && !this.props.label) {
336+
337+
if (this.props.onChange) {
338+
// make sure <ins /> element is not target
339+
event.target = this.refs.checkbox;
338340
this.props.onChange(event, newChecked);
339341
}
340342
}
@@ -454,7 +456,6 @@ var EnhancedSwitch = (function (_React$Component) {
454456
name: name,
455457
value: value,
456458
defaultChecked: props.defaultChecked,
457-
// checked: !!checked,
458459
onChange: this.handleChange.bind(this),
459460
onBlur: this.handleBlur.bind(this),
460461
onFocus: this.handleFocus.bind(this)

src/EnhancedSwitch.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class EnhancedSwitch extends React.Component {
235235
checked,
236236
});
237237
}
238+
238239
if (this.props.onChange) {
239240
this.props.onChange(e, checked);
240241
}
@@ -269,8 +270,6 @@ class EnhancedSwitch extends React.Component {
269270
return;
270271
}
271272

272-
// let type = event.type;
273-
274273
let newChecked = !this.refs.checkbox.checked;
275274

276275
if (!('checked' in this.props)) {
@@ -282,7 +281,10 @@ class EnhancedSwitch extends React.Component {
282281

283282
event.preventDefault();
284283
event.stopPropagation();
285-
if (this.props.onChange && !this.props.label) {
284+
285+
if (this.props.onChange) {
286+
// make sure <ins /> element is not target
287+
event.target = this.refs.checkbox;
286288
this.props.onChange(event, newChecked);
287289
}
288290
}
@@ -409,7 +411,6 @@ class EnhancedSwitch extends React.Component {
409411
name,
410412
value,
411413
defaultChecked: props.defaultChecked,
412-
// checked: !!checked,
413414
onChange: this.handleChange.bind(this),
414415
onBlur: this.handleBlur.bind(this),
415416
onFocus: this.handleFocus.bind(this),

0 commit comments

Comments
 (0)