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(react): iconButtons have reiterate classNames #15626

Conversation

kuri-sun
Copy link
Contributor

@kuri-sun kuri-sun commented Jan 29, 2024

Closes #15459

Icon buttons have duplicate classNames in their button HTML element because of the circular dependency.

Changelog

New

  • ButtonBase.tsx

Changed

  • Button.tsx
  • index.tsx (IconButton folder)

Testing / Reviewing

To avoid the circular dependency, introduced a new ButtonBase.

[OLD]
Button > IconButton > Button <--- This is the cause of "circular dependency".
[NEW]
Button > IconButton > ButtonBase

In IconButton, we used to import the Button component once again since we needed to rely on the logic(i.e. generating some classNames, ...etc.) that resides in Button.tsx.
However, this logic in Button.tsx is seperatable. Upon investigation, I noticed that the logic was a mixture of the logic for the Button component(not hasIconOnly) and the IconButton component. So, by splitting this logic up and creating a new ButtonBase component to migrate the Button component's logic from Button.tsx.

Here is a brief explanation for this.
Button.tsx … If-else condition for deciding whether the Button component or IconButton component.
ButtonBase.tsx … The Button component's logic exists
IconButton.tsx … Export the IconButton component

So in a nutshell, Extracted a logic for the Button component into ButtonBase.tsx from Button.tsx to leave Button.tsx file's responsibility only deciding whether the Button component or IconButton component.

As a pic below, we successfully removed duplicated classNames from the Button component. Also, the circular dependency during the build as well!(#14399)
Screenshot 2024-01-28 at 1 23 00 PM (2)

@kuri-sun kuri-sun requested a review from a team as a code owner January 29, 2024 08:31
Copy link

netlify bot commented Jan 29, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b219071
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65f7a429440bde0008564079
😎 Deploy Preview https://deploy-preview-15626--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kuri-sun
Copy link
Contributor Author

Sorry I have to update this PR, I will let you know if it's ready! Thank you!

@kuri-sun
Copy link
Contributor Author

I updated the PR, so it's ready! Thank you for your review!

Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

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

LGTM! I like the solution to fix the circular dependency issue. 🚀

Let's wait for another dev to review it!

@kuri-sun
Copy link
Contributor Author

Thanks for the review, @guidari! 😄

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this! This change will impact Storybook's ability to autogenerate the component API tables.

Right now the defaults for Button are not coming through: https://deploy-preview-15626--v11-carbon-react.netlify.app/?path=/docs/components-button--overview#component-api

image

We won't want to add BaseButton to the table because it's not exported. I'm not sure how best to fix this without specifying the default for every prop in the storybook args/argTypes.

@alisonjoseph alisonjoseph self-assigned this Mar 13, 2024
@kuri-sun
Copy link
Contributor Author

Sorry everyone! I had a long break so I didn't have time to look at this one!
Sure, @tay1orjones!
I will renew this with taking Storybook into consideration!
Thank you for your patience! 😄

@kuri-sun
Copy link
Contributor Author

kuri-sun commented Mar 18, 2024

Thanks for taking a look at this! This change will impact Storybook's ability to autogenerate the component API tables.

Right now the defaults for Button are not coming through: https://deploy-preview-15626--v11-carbon-react.netlify.app/?path=/docs/components-button--overview#component-api

image

We won't want to add BaseButton to the table because it's not exported. I'm not sure how best to fix this without specifying the default for every prop in the storybook args/argTypes.

Hi @tay1orjones!,
I just checked the component table and as far as I saw, I don't think any changes are detected between the current Button component's props table and this branch's Button component's props table.

Here I attached the preview of this branch's Button components' props table. Please take a look. Thanks!

Screenshot 2024-03-18 at 11 12 00 AM Screenshot 2024-03-18 at 11 12 08 AM Screenshot 2024-03-18 at 11 12 30 AM Screenshot 2024-03-18 at 11 12 44 AM

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

This LGTM, @tay1orjones are you still seeing an issue with prop table?

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Didn't realize the defaults were broken in prod too. We can fix them in a different issue/PR. Thanks!

@tay1orjones tay1orjones added this pull request to the merge queue Mar 27, 2024
Merged via the queue into carbon-design-system:main with commit e4626be Mar 27, 2024
20 checks passed
@carbon-automation
Copy link
Contributor

Hey there! v11.54.0 was just released that references this issue/PR.

preetibansalui pushed a commit to tay1orjones/carbon that referenced this pull request Apr 24, 2024
…em#15626)

* fix(react): iconButtons have reiterate classNames

* fix(react): wrong alignment with button icon only and danger--ghost kind

* fix(react): iconButtons have reiterate className

---------

Co-authored-by: TJ Egan <tw15egan@gmail.com>
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Bug]: IconButtons have reiterate classNames in a button HTML element.
6 participants