| 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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import * as React from 'react'; | ||
| import styles from '@patternfly/react-styles/css/components/Dropdown/dropdown'; | ||
| import { css } from '@patternfly/react-styles'; | ||
| import { Checkbox } from '../Checkbox'; | ||
| import { Omit } from '../../helpers/typeUtils'; | ||
|
|
||
| export interface DropdownToggleCheckboxProps extends Omit<React.HTMLProps<HTMLInputElement>, 'type' | 'onChange' | 'disabled' | 'checked'> { | ||
| export interface DropdownToggleCheckboxProps | ||
| extends Omit<React.HTMLProps<HTMLInputElement>, 'type' | 'onChange' | 'disabled' | 'checked'> { | ||
| /** Additional classes added to the DropdownToggleCheckbox */ | ||
| className?: string; | ||
| /** Flag to show if the checkbox selection is valid or invalid */ | ||
| Expand All | @@ -30,17 +32,20 @@ export class DropdownToggleCheckbox extends React.Component<DropdownToggleCheckb | |
| className: '', | ||
| isValid: true, | ||
| isDisabled: false, | ||
| isChecked: null as boolean | null, | ||
| checked: null as boolean | null, | ||
| onChange: () => undefined as any | ||
| }; | ||
|
|
||
| handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| this.props.onChange(event.currentTarget.checked, event); | ||
| handleChange = (checked: boolean, event: React.FormEvent<HTMLInputElement>) => { | ||
| this.props.onChange((event.target as HTMLInputElement).checked, event); | ||
| } | ||
|
|
||
| calculateChecked = () => { | ||
| const { isChecked, checked } = this.props; | ||
| return isChecked !== undefined ? isChecked : checked; | ||
| } | ||
|
|
||
| render() { | ||
| const { className, onChange, isValid, isDisabled, isChecked, checked, children, ...props } = this.props; | ||
| const { className, onChange, isValid, isDisabled, isChecked, ref, checked, children, ...props } = this.props; | ||
| const text = children && <span | ||
| className={css(styles.dropdownToggleText, className)} | ||
| aria-hidden="true" | ||
| Expand All | @@ -50,13 +55,13 @@ export class DropdownToggleCheckbox extends React.Component<DropdownToggleCheckb | |
| </span>; | ||
| return ( | ||
| <label className={css(styles.dropdownToggleCheck, className)} htmlFor={props.id}> | ||
| <input | ||
| <Checkbox | ||
| {...props} | ||
| type="checkbox" | ||
| onChange={this.handleChange} | ||
| {...(this.calculateChecked() !== undefined) && { onChange: this.handleChange }} | ||
| ref={ref as any} | ||
|
Comment thread
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 QualityAnybody knows something better to use here?
Sorry, something went wrong.
All reactions
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 QualityWhy do you have to pass the ref here? It will be passed automatically with {...props} with the correct type.
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 QualityIt's because TS does not recognized the ref correctly in here. I tried casting it to expected and it failed. This was the only solution that didn't thre any error.
Sorry, something went wrong.
All reactions
|
||
| aria-invalid={!isValid} | ||
| disabled={isDisabled} | ||
| defaultChecked={isChecked || checked} | ||
| isDisabled={isDisabled} | ||
| isChecked={this.calculateChecked()} | ||
| /> | ||
| {text} | ||
| </label> | ||
| Expand Down | ||
| 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 QualityI had to remove this test because jest is not playing nicely with mount and currentTarget enzymejs/enzyme#218.
I had to use mount because checkbox is now in Checkbox component.
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 QualityI've run into this same issue (I think also with Checkbox). My solution was to change handleChange in Checkbox.tsx from:
to:
If Checkbox doesn't break, feel free to try that.
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 QualityI think we should open a high-priority issue to add this test back if we aren't willing to address it in the scope of this PR.
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 QualityYeah, that came up in head as well, I didn't wanted to change the original Checkbox though because it's not part of this PR. But I'll probably change it to use target instead of currentTarget.
I could also change handleChange of this component to use target instead of currentTarget which is probably a bit safer.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.