Skip to main content
Yuan_Chang
March 4, 2021
Question

How to preserve icon color override and size?

  • March 4, 2021
  • 25 replies
  • 16741 views

I have been trying to find a way to preserve the icon color override within my button component. As you can see here, I used the trick from Rogie (Perserve Icon Color Override) to apply union to the icon, and everything seems work.
Screen Shot 2021-03-04 at 8.24.52 AM

However, now when I swap an icon, the union makes it hard to control the icon size (even though all icons have a frame 24x24, the content inside are vary). It then affects the auto layout and size of the component. Therefore, I tried to add another frame to contain the union layer and set fixed size, but it still didn’t work at all.

With the old approach, which I have to change the color every time, it allows me to constrain the icon size within the button to be 16x16. I am wondering is there a better way to preserve both color override and icon size?

This topic has been closed for replies.

25 replies

tank666
March 4, 2021

What if only the icon was wrapped in a union, and not the entire component?
Screenshot_20210304-203030-01

You can see this file:

Figma
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
New Participant
March 16, 2021

Thanks @tank666 for your file.

I have two large libraries I’m managing for my team (one for icons, one for UI components) and was struggling to make icon colors work for both dark and light theme for several hours this afternoon. Here’s what worked for me:

  1. Do the Union trick from Rogie’s file: for me, I duplicate my expanded icon in place (cmd+d), then union the two dupes, delete one of them, rename the union item to something like “color_fix”, the icon vector itself to “Union”, and the frame containing it all to the name I want for the icon (e.g. “keyboard”). Convert this to a component if it isn’t one already.
  2. Make sure all the items are set to Scale for height and width
  3. Make sure no color styles are applied anywhere in the stack; just some generic black color or whatever
  4. Publish the icon library
  5. Accept the icon library updates in the UI components library
  6. In the UI components library have a component with two icons in it, one for light theme and one for dark
  7. Use those icon components throughout the UI components library file.
  8. Apply the colors you want to the light icon and dark icon (I applied the color on the level of the item labeled “color_fix”)

Doing all of that enabled me to actually see the icons scale correctly to several different sizes within different components and also reflect the correct color depending on which theme the UI component pertained to.

Yuan_Chang
March 17, 2021

Thanks for the advices above. I actually remade all of my buttons 😅 in order to fix the icon size. One thing I learned is that Rogie’s trick works, but it’s very important to set a frame for the icon first rather than having the union then create a frame to wrap it.

KubaA
March 24, 2021

I must say that this sounds like a workaround to a bug. Wondering if this will be fixed soon as it makes using variants and interactive components nearly pointless when there is an icon-placeholder

Update: problem fixed with naming each shape for each icon with the same name. Color override works properly now. There is no bug.

Timj
New Participant
March 30, 2021

Variant icon color not being static is definitely a bug. I’m totally against hacks like this as it complicates the components, I remember the Sketch icon masks I had to maintain.

New Participant
April 1, 2021

I don’t like hacks either, but I do like that my icons are now getting the right color for each theme, even when I override the icon selection for, say, a button. My update to this thread is that I now am no longer using an icon component with a dark and light version; I’m just letting the parent component (say, the button) do the color overriding and it seems to be working. I probably don’t need the icon container anymore, but I also don’t want to touch it because it’s working.

ash
August 3, 2021

thanks KubaA, this is definitely the best way to address preserving icon colors! 💯

Jakedeg
August 12, 2021

Seems like it will also work to use a modified version of Rogie’s trick where you put a union within each icon component rather than within the button component that contains the icon. I think I prefer that way, since they’re already framed, and I don’t have more nested components to click around in my button. I almost never have to dig deep into the icon component itself, so the union there is mostly out of sight, out of mind.

Tobias_R
August 20, 2021

This was 100% the answer. My team uses FontAwesome as glyphs… So we originally had every layer named the FontAwesome html (far fa-icon-name) so devs would know which icon to use exactly. Just had to copy/paste that into the Description instead and then rename all the layers to the same name: “Icon”. Works perfectly now!! Thanks so much 🙂

Menno_Weerepas
New Member
September 10, 2021

It’s all in the name. I just found out 🤦‍♂️. over 500 icons in our DS each one of them in a symbol 16 x 16 with a unique name off course. But the element inside could have different names like “vector”, “union”, “primary”, or whatever. Once I noticed that elements with the same name didn’t switch color I’ve named every element “vector” and it works. Now I have to change this hack back again 🤦‍♂️