-
Notifications
You must be signed in to change notification settings - Fork 358
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
chore(Switch): convert Switch to TypeScript #2311
Conversation
PatternFly-React preview: https://patternfly-react-pr-2311.surge.sh |
packages/patternfly-4/react-core/src/components/Switch/Switch.tsx
Outdated
Show resolved
Hide resolved
/** A callback for when the Switch selection changes. (isChecked, event) => {} */ | ||
onChange: PropTypes.func, | ||
onChange?(checked: boolean, event: FormEvent<HTMLInputElement>): void; |
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.
Use an arrow function so the docs pick this up properly. Like `onChange?: (checked: boolean, event: FormEvent) => void;
packages/patternfly-4/react-core/src/components/Switch/Switch.tsx
Outdated
Show resolved
Hide resolved
'aria-label': '' | ||
}; | ||
export class Switch extends React.Component<SwitchProps> { | ||
id = ''; |
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.
Remove this class attribute
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.
Not sure what the purpose of this id is ... is it suppose to be the same as props.id?
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.
it instantiates the id when it is generated. And there is no id prop set.
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.
Shouldn't it instantiate it as a defaultProp to getUniqueId()
?
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.
I am not sure. Does it work differently in TS than JS. In JS if you set defaultProp to getUniqueId, if you had more hat one Switch on the page the id's would all be the same? That is why we had it in the constructor before.
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.
Looks like it will set it for all of the name to be the same based off the time. Leave it in the constructor.
packages/patternfly-4/react-core/src/components/Switch/Switch.tsx
Outdated
Show resolved
Hide resolved
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.
Wondering what was the use case for that separate class attribute ID.
'aria-label': '' | ||
}; | ||
export class Switch extends React.Component<SwitchProps> { | ||
id = ''; |
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.
Not sure what the purpose of this id is ... is it suppose to be the same as props.id?
'aria-label': '' | ||
}; | ||
export class Switch extends React.Component<SwitchProps> { | ||
id = ''; |
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.
Looks like it will set it for all of the name to be the same based off the time. Leave it in the constructor.
#2019
What:
Additional issues: