FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(Radio): fix warning from undefined starting params by kmcfaul · Pull Request #2292 · patternfly/patternfly-react · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .tsx  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import styles from '@patternfly/react-styles/css/components/Radio/radio';
import { css, getModifier } from '@patternfly/react-styles';
import { Omit } from '../../helpers/typeUtils';

export interface RadioProps extends Omit<React.HTMLProps<HTMLInputElement>, 'disabled' | 'label' | 'onChange' | 'type'> {
export interface RadioProps
extends Omit<React.HTMLProps<HTMLInputElement>, 'disabled' | 'label' | 'onChange' | 'type'> {
/** Additional classes added to the radio. */
className?: string;
/** Id of the radio. */
Expand All @@ -28,8 +29,9 @@ export class Radio extends React.Component<RadioProps> {
static defaultProps = {
className: '',
isDisabled: false,
isValid: true
}
isValid: true,
onChange: Function.prototype
};

constructor(props: RadioProps) {
super(props);
Expand All @@ -41,7 +43,7 @@ export class Radio extends React.Component<RadioProps> {

handleChange = (event: React.FormEvent<HTMLInputElement>) => {
this.props.onChange(event.currentTarget.checked, event);
}
};

render() {
const {
Expand All @@ -60,17 +62,20 @@ export class Radio extends React.Component<RadioProps> {
<div className={css(styles.radio, className)}>
<input
{...props}
aria-label={label ? undefined : ariaLabel}
className={css(styles.radioInput)}
type="radio"
onChange={this.handleChange}
aria-invalid={!isValid}
disabled={isDisabled}
checked={checked || isChecked}
defaultChecked={isChecked ? undefined : defaultChecked}
{...!isChecked && { defaultChecked }}

Copy link
Copy Markdown
Contributor

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 Quality

defaultChecked is an attribute passed to input? what does it do?

Copy link
Copy Markdown
Contributor Author

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 Quality

I think it's required for the uncontrolled version of radio. The undefined was throwing a console error.

{...!label && { 'aria-label': ariaLabel }}
/>
{label && (
<label className={css(styles.radioLabel, getModifier(styles, isDisabled && 'disabled' as any))} htmlFor={props.id}>
<label
className={css(styles.radioLabel, getModifier(styles, isDisabled && ('disabled' as any)))}
htmlFor={props.id}
>
{label}
</label>
)}
Expand Down

Back | FazBrowse Home | New Git URL