-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix(button): fix prop types for button #1473
Conversation
🚀 Deployed on https://pr-1473--dhis2-ui.netlify.app |
Passing run #3401 ↗︎
Details:
Review all test suite changes for PR #1473 ↗︎ |
9199aaf
to
9e9ba33
Compare
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.
LGTM!
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 good -- suggested a comment since it's a complex type, and for the poor souls without git lens 😁
export type ButtonProps = BaseButtonProps & | ||
Omit<React.ComponentPropsWithoutRef<'button'>, keyof BaseButtonProps> |
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.
export type ButtonProps = BaseButtonProps & | |
Omit<React.ComponentPropsWithoutRef<'button'>, keyof BaseButtonProps> | |
// For prop types we don't define, use native HTML button props | |
// See https://github.com/dhis2/ui/pull/1473 | |
export type ButtonProps = BaseButtonProps & | |
Omit<React.ComponentPropsWithoutRef<'button'>, keyof BaseButtonProps> |
Description
I don't think we should extend
HTML
-elements directly. In some cases liketabIndex
we're actually using a conflicting type, which causes type-errors in our types.tabIndex
should really be anumber
(that's what the html type is), but that would be breaking due to our prop-types etc.So instead of ButtonProps extending the
HTMLButtonElement
, I'm using type intersection with theComponentPropsWithoutRef<'button'>
without the keys forButtonProps
, to avoid conflicts.I also split this in two types types because eg.
export interface ButtonProps extends Omit<React.ComponentPropsWithoutRef<'button'>, keyof ButtonProps>
) wouldn't work because of circular references.See https://github.com/typescript-cheatsheets/react/blob/main/docs/advanced/patterns_by_usecase.md#wrappingmirroring, and expand "Why not ComponentProps or IntrinsicElements or [Element]HTMLAttributes or HTMLProps or HTMLAttributes?" for why we're using
ComponentPropsWithoutRef
, as opposed to the other prop-types.