Skip to main content
Francois_Jordaan1
New Participant
November 21, 2023
Solved

How do I set a variable when clicking a component, while also changing its variant?

I have a checkbox component that changes to a “checked” variant when clicked. When I click on an instance of this component, I want to set a variable. But when I add the “on click” interaction to set the variable, it overrides the component interaction, so the checkbox doesn’t get checked anymore.

Is this possible to do in Figma?

This topic has been closed for replies.
Francois_Jordaan1
New Participant
November 22, 2023

It looks like I can use the “While pressing” trigger to retain the component interaction, and also set the variable. I don’t know why this works, but it seems to solve my problem.

4 replies

Francois_Jordaan1
New Participant
November 21, 2023

There is an imperfect solution. I can add an extra “Change to” action on click, and change it to the “Checked” variant. This works, although it forces me to replicate an interaction that already exists on the component, only to set a variable. It also means I cannot click on it again to un-check the checkbox.

MaxZuman
November 21, 2023

set the variable change on “onMouseUp” trigger next to onClick

Francois_Jordaan1
New Participant
November 22, 2023

@MaxZuman That doesn’t work, unfortunately. It still deactivates the inherited component interaction, so the checkbox doesn’t get checked.

Francois_Jordaan1
Francois_Jordaan1AuthorSolution
New Participant
November 22, 2023

It looks like I can use the “While pressing” trigger to retain the component interaction, and also set the variable. I don’t know why this works, but it seems to solve my problem.