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

Icons passed to Button component must be wrapped in a div for proper styling #18581

Closed
lmossman opened this issue Oct 28, 2022 · 4 comments · Fixed by #22176
Closed

Icons passed to Button component must be wrapped in a div for proper styling #18581

lmossman opened this issue Oct 28, 2022 · 4 comments · Fixed by #22176
Assignees
Labels

Comments

@lmossman
Copy link
Contributor

Tell us about the problem you're trying to solve

When providing both an icon to the Button component, and a label (as a child), the Button component does not always successfully apply the desired class names to the icon inside of the button.

However, if the icon is wrapped in a <div> before being passed to the Button, the styles are properly applied.

For example, we are currently doing this div-wrapping hack in the ConnectionStatusTab component:

icon={
<div className={styles.iconRotate}>
<RotateIcon />
</div>
}

To demonstrate what this does, here is what the button and its styles look like currently on prod, with the icon wrapped in a div:
Screen Shot 2022-10-27 at 5 43 54 PM

And here is what the button and styles look like when the icon is NOT wrapped in a div:
Screen Shot 2022-10-27 at 5 42 25 PM
As you can see, the Button_buttonIcon_..., Button_positionLeft_..., and Button_withLabel_... styles are not being applied to the <svg> element, which messes up the formatting

Describe the solution you’d like

This may be happening because we are using React.cloneElement to create the button icon here:

React.cloneElement(icon, {
className: classNames(styles.buttonIcon, {
[styles.positionLeft]: true,
[styles.isRegularIcon]: true,
[styles.withLabel]: Boolean(children),
}),
})}

And, it may only happen with specific icon elements like <svg>, which may have trouble having those styles applied.

One solution could be to always wrap the cloned element in a <div>, and apply the icon styles to that div instead, though this may cause us to end up with unnecessary <div> nesting.

@octavia-squidington-iv
Copy link

cc @airbytehq/frontend

@edmundito
Copy link
Contributor

@lmossman Just looking into this to see if I should fix it but when I look at all the usages, the only icon that is having trouble is the rotate icon. Maybe this is something specific with the Rotate Icon itself? (or maybe we haven't caught it with the other custom icons?)

@lmossman
Copy link
Contributor Author

Interesting. I thought it would be a problem with all icons, but if not then maybe we should try to understand what specifically about the rotate icon is causing the problem

@teallarson
Copy link
Contributor

teallarson commented Jan 4, 2023

@edmundito I am seeing this with other custom icons as well, but not with FontAwesome icons.

To test it out, I went to a page that had a button with correct classNames (I looked at AllSourcesPage) and swapped out the icon with a custom one from our repo (I tried PencilIco, RotateIcon, and ModificationIcon) and the icon classnames were no longer being passed down from the Button component.

Interesting that for some reason they get properly applied to the svg element for FA but not for our custom ones.

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 a pull request may close this issue.

5 participants