CONTEXT. I have a button that triggers a drop down list. The button has 2 states: normal (the list is hidden) and pressed (the list is shown and the button changes color). When the button is clicked it changes state and shows or hides the drop down list. When an item from the list is clicked the button returns to the normal state and the list is hidden. The same behavior should happen when clicking outside the button or the list.
PROBLEM. If I show the list as a lightbox then clicking outside the list hides it. What it does not do is return the button to its normal state. At first I added a script in the list, so that when OnLostFocus the list is hidden and the button is set to the normal state, but it does no seem to work. I have read in a post in this forum that the focus only works on widgets such as text field and radio buttons, not on groups or rectangles. I tried adding a text field and set focus on it when the list is dropped down, but now the script for the OnClick of the items of the list is not executing, so I cannot select any of the items of the list.
QUESTION. How does the mechanism of the OnLostFocus exactly work? I had to insert a wait time in the action of clicking the button before setting focus on the text field to make it work, so I am guessing that there are some actions that take place before others. I tried placing waiting times in different places but it does not work, so it would be better to understand what is happening. What happens when I click something and something has an OnLostFocus script, what executes first and what does not execute?
EXAMPLE. Here an example with the 2 cases, using a lightbox that gets stuck in the pressed state when clicked outside the component, the other using a hidden textfield (1px wide and casted by the list when dropped down) that does not allow to select any of the elements of the list:
https://jtrxhf.axshare.com/#g=3&p=dropdown_button
Layout.rp (752.9 KB)
NOTE. Although I talk about the button having 2 states, in reality what I do is have 2 overlapping buttons and toggle their visibility when the button is pressed.