Skip to content

v2.5.2 #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(Switch): uncontrolled mode with defaultChecked
  • Loading branch information
xidedix committed Aug 1, 2019
commit 0c9f57cf10dfb7b84251bd1abf6766232aa7584d
9 changes: 5 additions & 4 deletions src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const defaultProps = {
outline: false,
size: '',
checked: false,
defaultChecked: false,
disabled: false,
required: false,
defaultChecked: undefined,
disabled: undefined,
required: undefined,
type: 'checkbox',
variant: '',
dataOn: 'On',
Expand All @@ -49,6 +49,7 @@ class AppSwitch extends Component {
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleKeyUp = this.handleKeyUp.bind(this);
this.state = {
uncontrolled: !!this.props.defaultChecked,
checked: this.props.defaultChecked || this.props.checked,
selected: []
};
Expand Down Expand Up @@ -82,7 +83,7 @@ class AppSwitch extends Component {
}

componentDidUpdate(prevProps, prevState) {
if (this.props.checked !== prevState.checked) {
if (!this.state.uncontrolled && (this.props.checked !== prevState.checked)) {
this.toggleState(this.props.checked)
}
}
Expand Down