| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -6,6 +6,7 @@ propComponents: ['Checkbox'] | |
| --- | ||
|
|
||
| import { Checkbox } from '@patternfly/react-core'; | ||
| import './checkbox.scss'; | ||
|
|
||
| ## Controlled checkbox | ||
| ```js | ||
| Expand All | @@ -17,7 +18,9 @@ class ControlledCheckbox extends React.Component { | |
| super(props); | ||
| this.state = { | ||
| check1: false, | ||
| check2: false | ||
| check2: false, | ||
| check3: false, | ||
| check4: false | ||
| }; | ||
| this.handleChange = (checked, event) => { | ||
| const target = event.target; | ||
| Expand All | @@ -27,25 +30,58 @@ class ControlledCheckbox extends React.Component { | |
| }; | ||
| } | ||
|
|
||
| componentDidUpdate(_prevProps, prevState) { | ||
| if (prevState.check1 !== this.state.check1 && this.state.check1 !== null) { | ||
| this.setState({ | ||
| check2: this.state.check1, | ||
| check3: this.state.check1, | ||
| }) | ||
| } | ||
|
|
||
| if (prevState.check2 !== this.state.check2 || prevState.check3 !== this.state.check3) { | ||
| this.setState({ | ||
| check1: (this.state.check2 && this.state.check3) || (this.state.check2 || this.state.check3 ? null : false) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <React.Fragment> | ||
| <Checkbox | ||
| label="Controlled CheckBox" | ||
| label="Parent CheckBox" | ||
| isChecked={this.state.check1} | ||
| onChange={this.handleChange} | ||
| aria-label="controlled checkbox example" | ||
| id="check-1" | ||
| name="check1" | ||
| /> | ||
| <Checkbox | ||
| label="Controlled CheckBox" | ||
| className="nested" | ||
| label="Child CheckBox 1" | ||
| isChecked={this.state.check2} | ||
| onChange={this.handleChange} | ||
| aria-label="controlled checkbox example" | ||
| id="check-2" | ||
| name="check2" | ||
| /> | ||
| <Checkbox | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitywould be good to wrap 2 checkboxes inside the checkbox and show the indeterminate state live. And can also get rid of several other duplicate examples
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYeah! That's a good point. I like it!
Sorry, something went wrong.
All reactions
|
||
| className="nested" | ||
| label="Child CheckBox 2" | ||
| isChecked={this.state.check3} | ||
| onChange={this.handleChange} | ||
| aria-label="controlled checkbox example" | ||
| id="check-3" | ||
| name="check3" | ||
| /> | ||
| <Checkbox | ||
| label="Controlled CheckBox" | ||
| isChecked={this.state.check4} | ||
| onChange={this.handleChange} | ||
| aria-label="controlled checkbox example" | ||
| id="check-4" | ||
| name="check4" | ||
| /> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .ws-preview { | ||
| & .pf-c-check.nested { | ||
| padding-left: var(--pf-global--spacer--md); | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhat's this ref needed for?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis prop is can't be set trough react prop for some reason [1]. However plain js api allows to set it trough element, so this ref is to access checkox element. It's probably because indeterminate is a flag and not real prop though.
[1] react/react#1798
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.