Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c9f57c

Browse filesBrowse files
committed
fix(Switch): uncontrolled mode with defaultChecked
1 parent de80629 commit 0c9f57c
Copy full SHA for 0c9f57c

File tree

Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed

‎src/Switch.js

Copy file name to clipboardExpand all lines: src/Switch.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const defaultProps = {
3333
outline: false,
3434
size: '',
3535
checked: false,
36-
defaultChecked: false,
37-
disabled: false,
38-
required: false,
36+
defaultChecked: undefined,
37+
disabled: undefined,
38+
required: undefined,
3939
type: 'checkbox',
4040
variant: '',
4141
dataOn: 'On',
@@ -49,6 +49,7 @@ class AppSwitch extends Component {
4949
this.handleKeyDown = this.handleKeyDown.bind(this);
5050
this.handleKeyUp = this.handleKeyUp.bind(this);
5151
this.state = {
52+
uncontrolled: !!this.props.defaultChecked,
5253
checked: this.props.defaultChecked || this.props.checked,
5354
selected: []
5455
};
@@ -82,7 +83,7 @@ class AppSwitch extends Component {
8283
}
8384

8485
componentDidUpdate(prevProps, prevState) {
85-
if (this.props.checked !== prevState.checked) {
86+
if (!this.state.uncontrolled && (this.props.checked !== prevState.checked)) {
8687
this.toggleState(this.props.checked)
8788
}
8889
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.