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

feat(icon-button): support as #1164

Merged
merged 3 commits into from
Nov 7, 2019
Merged

feat(icon-button): support as #1164

merged 3 commits into from
Nov 7, 2019

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Nov 6, 2019

Summary

Adds support for as to the IconButton.

Also supports prop forwarding to IconButton and SecondaryButton. Without this, it would not be possible to use anchor tags.

Closes #1162

@montezume montezume requested a review from tdeekens November 6, 2019 15:24
@montezume montezume self-assigned this Nov 6, 2019
@montezume montezume requested a review from jonnybel November 6, 2019 15:24
@montezume montezume added the 🚀 Type: New Feature Something new label Nov 6, 2019
@@ -0,0 +1,11 @@
import isPropValid from '@emotion/is-prop-valid';
Copy link
Contributor Author

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

Copy link
Contributor

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"
Copy link
Contributor Author

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.

@montezume montezume requested a review from YahiaElTai November 6, 2019 15:29
Copy link
Contributor

@tdeekens tdeekens left a 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}
Copy link
Contributor

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 and isDisabled to a component, and in this case, because the AccessibleButton spreads the buttonAttributes prop after the isDisabled prop is assigned to disabled, which means the native html prop will override the isDisabled one. Same for all other props that we manually assign before the buttonAttributes spread. Is this an intended behaviour?

Copy link
Contributor Author

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}?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice catch!

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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 😇.

Copy link
Contributor Author

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. 😄

Copy link
Contributor

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.

@montezume montezume merged commit 032b198 into master Nov 7, 2019
@montezume montezume deleted the ml-break-more-buttons branch November 7, 2019 09:39
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.

add linkTo property on IconButton
3 participants