Forum Discussion
How do you create a toggle button?
I need to create a toggle button which opens a layer in a corner of the screen. I then want to use the same button to close the layer. How would I make a toggle button? I don't seem to be able to find any other thread on this topic.
- JudyNolletSuper Hero
How much stuff is on the layer? The easiest way to get that toggling may be to move the content from the layer into the Selected state of the button. A button with a Selected state will automatically toggle between Normal and Selected when it's clicked, so you wouldn't need any triggers (or layers).
- CarynWagnerCommunity Member
Judy,
I followed your suggestion of moving the content to the Selected state and it worked great, thank you!
I then tried to put my 3 buttons in a button set, but now they are no longer toggling back to the Normal state when the same button is clicked. Is there a way to get around that?
- JudyNolletSuper Hero
The point of a button set is to require the user to make a selection—and only 1 selection. For example, to indicate an answer to a question or to choose an avatar.
However, that means that to deselect a button in the set, the user has to select another button in the set. Or some other trigger has to change the button back to Normal.
Depending on your situation, you could try one of the following:
- Remove the button set. (That works if no answer is required or if more than one item can be selected.)
- Add a button to the set that's labeled something like "Clear selection." (Sure, technically, they'd be selecting that button. But that would deselect the other buttons with actual choices.)
- MarkMcDonald-58Community Member
Thanks Judy. If it was a simple layer, that would be a great simple solution (I'll retain tour tip for another occasion).
Unfortunately, it's a complex layer that requires fiddling with new content (text and avatar) on each slide, so I'm hoping to retain the layer format.
- MichaelHinzeCommunity Member
See attached a quick example, using a True/False variable that is toggles whenever the button is clicked.
- MarkMcDonald-58Community Member
Many thanks Michael. Nice and easy to follow and just what I was wanting.
- JudyNolletSuper Hero
Glad to see that Michael jumped in with the toggle-variable solution. With that option, be sure to use a unique variable for each slide. Otherwise, the True/False values could get mixed up.
Other options:
- Put a copy of the button on the layer, and give it a trigger to hide the layer. (If it's in the same position, the user won't know it's a different button.)
or
- Cover the base button. Use a separate button on the layer that specifically indicates it's for closing that content.
- MarkMcDonald-58Community Member
Thanks for the tip, Judy
- PhilMayorSuper Hero
ou cannot toggle back to normal inside a button set that is by design