PopupMenu::show focus woes (and a workaround)

I just came across a problem that I spent far too long trying to mitigate.

I have a PopupMenu where one of the item callbacks is giving focus to a TextEditor, however based on the answer here it seems that (intentionally) when the menu closes it is returning focus to whichever component had the focus when the menu was opened, which would cause the TextEditor I gave focus to in the item callback to be lost.

Using showAsync instead solved this issue completely.

edit: I also imagine that if instead of using callbacks I reacted to the result from PopupMenu::show and then gave TextEditor focus that this would have solved the problem as well.

1 Like