Forum Discussion
Any idea how to deselect element when it is in a Button Set?
When you guys think about "selected" state only as a radio buttons or tabs or something like that - both of your answers are "yes". But when you are thinking out of the box... ;)
I'm using selected state sometimes to show additional information on click (I know this can be done using layers, but it doesn't always make sense or interfere with another mechanism or simply you can use nice animation on entering/leaving selected state without additional hassle. It also can be done with hover, but that's not mobile friendly.).
Anyway after a couple of hours I finally came up with minimum-trigger solution. Attaching for anyone who wants to use something like that in their project.
The idea is simple. Check if two variables are true, if yes, select "placebo" button so it will automatically "unselect" current selected element.
1. Make sure variable gets resetted every time you click "normal" button. This was tricky but came out as simple solution of changing Variable on every status change to "selected" (and while you click on already selected button, the variable is not affected).
2. Set 1st variable to true on first click.
3. Set 2nd variable to true on second click to trigger move animation for supporting element.
4. Set placebo element to selected when move animation ends and reset both variables.