From 6a2fba97e0f55d77394837b5b31cfe58467c4666 Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Tue, 22 May 2018 17:03:11 +0800 Subject: [PATCH] [IE only] Address an issue that the `change` event never fires for `indeterminate` input elements --- README.md | 4 +++- src/Checkbox.jsx | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 738da2a..d0d2d57 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,8 @@ checked | Boolean | | The checked state of the checkbox element. defaultChecked | Boolean | | The default checked state of the checkbox element. indeterminate | Boolean | | The indeterminate state of the checkbox element. defaultIndeterminate | Boolean | false | The default indeterminate state of the checkbox element. +onChange | Function(event) | | The callback function that is triggered when the state changes. +onClick | Function(event) | | The callback function that is triggered when the checkbox is clicked. #### CheckboxGroup @@ -157,7 +159,7 @@ disabled | Boolean | false | If true, the checkbox group will be displayed as di name | String | | Name for the input element group. value | any | | The value of the checkbox group. defaultValue | any | | The default value of the checkbox group. -onChange | Function | | Callback function that will be invoked when the value changes. +onChange | Function(value, event) | | The callback function that is triggered when the value changes. depth | Number | 1 | Limits the recursion depth when rendering checkboxes deeply inside a checkbox group. ### Class Properties diff --git a/src/Checkbox.jsx b/src/Checkbox.jsx index ee3c902..fe50454 100644 --- a/src/Checkbox.jsx +++ b/src/Checkbox.jsx @@ -19,7 +19,8 @@ class Checkbox extends PureComponent { defaultChecked: PropTypes.bool, indeterminate: PropTypes.bool, defaultIndeterminate: PropTypes.bool, - onChange: PropTypes.func + onChange: PropTypes.func, + onClick: PropTypes.func }; static defaultProps = { @@ -29,7 +30,7 @@ class Checkbox extends PureComponent { checkbox = null; - onChange = (event) => { + updateIndeterminateState = () => { if (typeof (this.props.indeterminate) !== 'undefined') { this.checkbox.indeterminate = !!this.props.indeterminate; } @@ -57,6 +58,7 @@ class Checkbox extends PureComponent { disabled, defaultIndeterminate, onChange = noop, + onClick = noop, // Default props className, @@ -90,9 +92,10 @@ class Checkbox extends PureComponent { styles.inputCheckbox )} style={inputStyle} - onChange={chainedFunction( - this.onChange, - onChange + onChange={onChange} + onClick={chainedFunction( + this.updateIndeterminateState, + onClick )} />