Skip to main content
Question

Can variables be used to select variants within nested component instances?


Martyn_Bowis

Can variables reliably be used to select which variant is used for a component when the instance is nested within another component instance?

E.g.

Screen

  • Header
    – Logo (variant = BrandA)

Screen

  • Header
    – Logo (variant = BrandB)

I am finding that using a variable to set which variant is to be used for an instance that is nested does not reliably load.

Or does it only fail when there are mode conflicts, and if so, how to resolve mode conflicts? Have tried following this reference without success yet:

Figma Learn - Help Center

Any ideas @Gleb , @tank666 or anyone else?

Thanks,
Martyn

This topic has been closed for comments

7 replies

Raphael_M
  • Power Member
  • 361 replies
  • July 31, 2024

I’ve tested it with modes and variables in the example you’ve given and it works properly.


But i’m not quite sure what you mean.


Martyn_Bowis
  • Author
  • New Participant
  • 29 replies
  • July 31, 2024

Hey @Raphael_M, what you showed used boolean variables, and works for that simple use case.

What about for a more complex usecase where there are more than 2 brands (and booleans only cater for two options, true and false)?

E.g. Five brands (A, B, C, D and E):

Screen

  • Header
    – Logo (variant = BrandA)

Screen

  • Header
    – Logo (variant = BrandB)

Screen

  • Header
    – Logo (variant = BrandC)

Screen

  • Header
    – Logo (variant = BrandD)

Screen

  • Header
    – Logo (variant = BrandE)

Perhaps the issue I am facing is that string variables cannot set variants, only boolean variables can set variants?


Raphael_M
  • Power Member
  • 361 replies
  • July 31, 2024

That is still possible.

You can even use it on prototyping
image


Martyn_Bowis
  • Author
  • New Participant
  • 29 replies
  • July 31, 2024

Hey @Raphael_M , here is an even simpler summary video showing the core problem:

Variables cannot set variants for instances that come from libraries.


Raphael_M
  • Power Member
  • 361 replies
  • July 31, 2024

Since you’re using regenerate all instances, that means that it is an unusual behavior. It probably has something to do with your complex nesting that involves multiple files or it doesn’t load the function for the mode upon the start of the app, so it has to be manually updated using the regenerate all instances command.

I haven’t really thought of using modes to control the variants on the wf though


Martyn_Bowis
  • Author
  • New Participant
  • 29 replies
  • August 1, 2024

Is there a way to use the API to call the Regenerate all instances method?

Be great if Figma would make regenerating all instances an option for when files load.

And if not, then to be able to call that method using the Figma Plugin API to do it


Aqsa2
  • 3 replies
  • August 1, 2024

I hope i got the right answer.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings