[Bug]: Carbon 11 Button's renderIcon does not position correctly for functions
See original GitHub issuePackage
Browser
Firefox
Package version
v11
React version
v18
Description
With Carbon 11, you can pass in a size to an icon such that instead of doing this in v10
import { Add24 } from '@carbon/icons-react';
you can do this in v11
import { Add } from '@carbon/react/icons';
...
<Add size={24} />
So here is my issue, before I could pass a Icon object into the renderIcon
of a Button
component as such
<Button renderIcon={Add24} />
But if we wanted to use the new carbon 11 way passing in a size as such, you have to use a function for this to work
<Button renderIcon={() => <Add size={24}>} />
Now I noticed these two different ways the icon position is off.
Using an object (passing in something like Add24
)
Passing in a function (() => <Add size={24}>
)
The pos is off. I know we can just import bot hAdd
and Add24
to solvethis , but wanted to ask if I was doing something wrong or if this was ab ug?
CodeSandbox example
N/A
Steps to reproduce
See Description
Code of Conduct
- I agree to follow this project’s Code of Conduct
- I checked the current issues for duplicate problems
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top Results From Across the Web
When using latest carbon-icons, ghost button does not render ...
Hi, we updated to the latest carbon components / icons, and we're having problems with our ghost button icons, the background color seems...
Read more >Icon usage - Carbon Design System
Icons are visual symbols used to represent ideas, objects, or actions. They communicate messages at a glance, afford interactivity, and draw attention to ......
Read more >office-ui-fabric-react/CHANGELOG.md - UNPKG
28, - Dropdown: Fix bug where it was not programatically possible to focus on Dropdown ... 197, - DetailsList: Assign button role to...
Read more >Display Bug: Buttons with Icon and/or Menu - Mockups 3
I discovered a display bug in the button control when used with an icon and/or a menu after importing some symbols I'd made...
Read more >In React ES6, why does the input field lose focus after typing a ...
it is because you are rendering the form in a function inside render(). Every time your state/prop change, the function returns a new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, this worked. I also learned that, even with the
size
prop, it doesn’t matter. It appears with a function rendering an icon with a fixed size prop gets ignored and the icon gets set to the size of what the component chooses.if a function is used, the props appears to be needed as you said.
can this be added in docs somewhere? maybe storybook? I seen others with this issue and no where does it mention passing in props as the functions call back for the
renderIcon prop
. I feel this would help others, but with that said, my issue has been resolved, thanks @rwibm !@TannerS This is due to missing classes on the SVG element, it can be fixed by passing the props to the function component, like this:
renderIcon={props => <Add size={24} {…props}/>}