Skip to content

Commit

Permalink
Merge pull request #105 from bcrumbs/dev
Browse files Browse the repository at this point in the history
1.1.3: default values for checkbox and toggle
  • Loading branch information
sergeimonakhov committed Jun 21, 2018
2 parents d92a4da + fc61fcd commit 0b1c480
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/reactackle-checkbox/src/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export default class Checkbox extends Component {
checked: this.props.checked,
});
}
const isDefaultValueChanged =
nextProps.defaultChecked !== this.props.defaultChecked;

if (isDefaultValueChanged) {
this.setState({ checked: nextProps.defaultChecked });
}
}

get disabled() {
Expand Down
9 changes: 9 additions & 0 deletions packages/reactackle-toggle-button/src/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export default class ToggleButton extends Component {
this._handleBlur = this._handleBlur.bind(this);
}

componentWillReceiveProps(nextProps) {
const isDefaultValueChanged =
nextProps.defaultChecked !== this.props.defaultChecked;

if (isDefaultValueChanged) {
this.setState({ checked: nextProps.defaultChecked });
}
}

_handleChange(event) {
const checked = event.target.checked;
this.props.onChange({
Expand Down

0 comments on commit 0b1c480

Please sign in to comment.