-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat(icon-button): support as
#1164
Conversation
@@ -0,0 +1,11 @@ | |||
import isPropValid from '@emotion/is-prop-valid'; |
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 used internally by emotion
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's great!
{...props} | ||
as="a" | ||
href="https://www.kanyetothe.com" | ||
target="_BLANK" |
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.
if we don't support passing all valid props, then using regular "external" links would be super annoying.
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 nice.
return ( | ||
<AccessibleButton | ||
buttonAttributes={buttonAttributes} | ||
as={props.as} | ||
buttonAttributes={attributes} |
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 have a concern about forwarding all props, given we already "reimplement" some of the HTML props:
- It is possible to pass both the props
disabled
andisDisabled
to a component, and in this case, because theAccessibleButton
spreads thebuttonAttributes
prop after theisDisabled
prop is assigned todisabled
, which means the native html prop will override theisDisabled
one. Same for all other props that we manually assign before thebuttonAttributes
spread. Is this an intended behaviour?
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 don't get it. You mean if the user passed in disabled={true}
and isDisabled={false}
?
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.
Kind of feels like a play stupid games win stupid prizes situation.
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.
Oh nice catch!
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 would you prefer to happen? I guess we could add a prop-type warning if a user passes both?
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.
Yeah, it shouldn't happen, but it can lead to weird bugs that are hard to track.
It's more a question of: should we worry about it, and can we do something to mitigate this?
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 would just ignore it. The plan is to deprecate all the isDisabled
, etc stuff right?
If someone writes the code
<IconButton disabled={true} isDisabled={false} />
and it passes pull request, then we deserve the bugs.
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.
Yeah, it totally makes sense to deprecate the isDisabled
and others as the next step.
It could happen accidentally after some layers of abstraction, but I also wouldn't worry about it too much, as for now we're still supposed to use the explicit props that are documented.
I'm OK with keeping it as it is, as long as we're aware and we hopefully deprecate those redundant props soon 😇.
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.
Having two "sources of truth" is a bad idea. 😄
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.
One could have like a prop-zipper or something so that always one has precedence. However, I think it's a super nice theoretical catch but given the scale we are the practical implications can be negated.
Summary
Adds support for
as
to theIconButton
.Also supports prop forwarding to
IconButton
andSecondaryButton
. Without this, it would not be possible to useanchor
tags.Closes #1162