Skip to content
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

Merged
merged 3 commits into from
May 27, 2024
Merged

Conversation

Birkbjo
Copy link
Member

@Birkbjo Birkbjo commented Apr 15, 2024

Description

I don't think we should extend HTML-elements directly. In some cases like tabIndex we're actually using a conflicting type, which causes type-errors in our types.
tabIndex should really be a number (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 the ComponentPropsWithoutRef<'button'> without the keys for ButtonProps, 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.

@Birkbjo Birkbjo requested a review from a team as a code owner April 15, 2024 15:50
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Apr 15, 2024

🚀 Deployed on https://pr-1473--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify April 15, 2024 15:54 Inactive
Copy link

cypress bot commented Apr 15, 2024

Passing run #3401 ↗︎

0 584 0 0 Flakiness 0

Details:

Merge pull request #1473 from dhis2/fix/button-prop-types
Project: ui Commit: 46f302c931
Status: Passed Duration: 08:53 💡
Started: May 27, 2024 1:27 PM Ended: May 27, 2024 1:36 PM

Review all test suite changes for PR #1473 ↗︎

@Birkbjo Birkbjo force-pushed the fix/button-prop-types branch from 9199aaf to 9e9ba33 Compare April 15, 2024 16:07
@dhis2-bot dhis2-bot temporarily deployed to netlify April 15, 2024 16:11 Inactive
Copy link

@eirikhaugstulen eirikhaugstulen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dhis2-bot dhis2-bot temporarily deployed to netlify May 16, 2024 11:19 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify May 22, 2024 08:21 Inactive
Copy link
Contributor

@KaiVandivier KaiVandivier left a 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 😁

Comment on lines +105 to +106
export type ButtonProps = BaseButtonProps &
Omit<React.ComponentPropsWithoutRef<'button'>, keyof BaseButtonProps>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>

@Chisomchima Chisomchima merged commit 46f302c into master May 27, 2024
15 checks passed
@Chisomchima Chisomchima deleted the fix/button-prop-types branch May 27, 2024 13:20
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 9.4.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants