-
Notifications
You must be signed in to change notification settings - Fork 66
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
LG-2719 | LG-3260: refactor Button to use InferredPolymorphic instead of Box #2695
Conversation
🦋 Changeset detectedLatest commit: 2eb02b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: +26 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
forwardRef, | ||
) { | ||
const { darkMode } = useDarkMode(darkModeProp); | ||
export const Button = InferredPolymorphic<ButtonProps, 'button'>( |
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.
We should export a prop type that is also wrapped in InferredPolymorphic. Similar to splitButton. This way, if consumers need to extend the type, it will include the inferred polymorphic props.
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.
done!
onClick: isInteractive | ||
? onClick | ||
: (e: React.MouseEvent) => e.preventDefault(), | ||
href: isInteractive ? rest.href : undefined, |
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 think this href is being overwritten by the ...rest
below it. Do we need this line?
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.
huh.. that wasn't changed in this PR 😅 I'll take a look and see if we can axe it
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 can't destructure href
from the rest object to allow passing it to useInferredPolymorphic
, but I moved this below the ...rest
, so it should actually be working now
({ children, ...props }: ButtonProps, ref) => ( | ||
<Button {...props} ref={ref}> | ||
<Button {...props} as="button" ref={ref}> |
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.
curious: why do we need to pass the as
prop if we are passing button
here: const { Component } = useInferredPolymorphic(as, rest, 'button');
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.
Paired with Adam on this, and it should be correct now without needing to specify the as
prop
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.
what was the issue?
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 was a typescript issue. It wasn't able to calculate what the element would be which would cause the ref
to have a type error
type CustomConfirmButtonProps = Omit<BaseButtonProps, 'variant' | 'onClick'> & | ||
CustomButtonOnClick; | ||
type CustomCancelButtonProps = Omit<ButtonProps, 'onClick' | 'children'> & | ||
type CustomCancelButtonProps = Omit<BaseButtonProps, 'onClick' | 'children'> & |
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.
Confirmed that primary consumers' ConfirmationModal
instances don't currently specify as
or href
as keys in these object props: https://github.com/search?q=(org:10gen+OR+org:evergreen-ci+OR+org:mongodb+OR+org:mongodb-js+OR+org:mongodb-labs+OR+org:wiredtiger)+AND+%22%3CConfirmationModal%22+AND+(confirmButtonProps%3D+OR+cancelButtonProps%3D)+AND+(as:+OR+href:)&type=code
@@ -35,7 +35,7 @@ export type InlineMessageFeedbackProps = Required< | |||
/** | |||
* Override props for the submit Button | |||
*/ | |||
submitButtonProps?: ButtonProps; | |||
submitButtonProps?: 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.
Confirmed that primary consumers' InlineMessageFeedback
instances don't currently specify as
or href
as keys in these object props: https://github.com/search?q=(org:10gen+OR+org:evergreen-ci+OR+org:mongodb+OR+org:mongodb-js+OR+org:mongodb-labs+OR+org:wiredtiger)+AND+%22%3CInlineMessageFeedback%22+AND+(submitButtonProps%3D+OR+cancelButtonProps%3D)+AND+(%22as:%22+OR+%22href:%22)&type=code
type ButtonPropsOmittingVariant = Omit<BaseButtonProps, 'variant'>; | ||
type ButtonPropsWithRequiredChildren = Required< | ||
Pick<BaseButtonProps, 'children'> | ||
>; |
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.
Confirmed that primary consumers' FormFooter
instances don't currently specify as
or href
as keys in these object props: https://github.com/search?q=(org:10gen+OR+org:evergreen-ci+OR+org:mongodb+OR+org:mongodb-js+OR+org:mongodb-labs+OR+org:wiredtiger)+AND+%22%3CFormFooter%22+AND+(primaryButtonProps%3D+OR+backButtonProps%3D+OR+cancelButtonProps%3D)+AND+(%22as:%22+OR+%22href:%22)&type=code
forwardRef, | ||
) { | ||
const { darkMode } = useDarkMode(darkModeProp); | ||
export const Button = InferredPolymorphic<ButtonProps, 'button'>( |
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.
done!
onClick: isInteractive | ||
? onClick | ||
: (e: React.MouseEvent) => e.preventDefault(), | ||
href: isInteractive ? rest.href : undefined, |
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 can't destructure href
from the rest object to allow passing it to useInferredPolymorphic
, but I moved this below the ...rest
, so it should actually be working now
({ children, ...props }: ButtonProps, ref) => ( | ||
<Button {...props} ref={ref}> | ||
<Button {...props} as="button" ref={ref}> |
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.
Paired with Adam on this, and it should be correct now without needing to specify the as
prop
as?: 'a'; | ||
} & ComponentPropsWithRef<'a'>; | ||
|
||
/** | ||
* Union of {@link AnchorLikeProps} and {@link InheritedProps} | ||
*/ | ||
export type InheritedExplicitAnchorLikeProps<TAsProp extends AnchorLike> = { | ||
/** | ||
* |
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.
This is blank
✍️ Proposed changes
Button
now usesInferredPolymorphic
instead ofBox
<button>
🎟 Jira ticket: LG-2719 | LG-3260
✅ Checklist
For bug fixes, new features & breaking changes
pnpm changeset
and documented my changes🧪 How to test changes
Button
live example, addhref
text and toggle ondisabled
. No browser error relating todisabled
element incompatibility should appear