BR: Invisible components can have keyboard focus and respond to keystrokes

Very simple test case. Create and add a TextEditor, use the textEditorTextChanged to update the screen. Make a timer that hides the text editor. Once it’s hidden you can still type into it.

Code: juce_bugs/PluginEditor.h at master · FigBug/juce_bugs · GitHub

Video: Screen Recording 2021 01 21 at 3 30 41 PM - YouTube

Issue:

        if (! shouldBeVisible)
        {
            ComponentHelpers::releaseAllCachedImageResources (*this);

            if (currentlyFocusedComponent == this || isParentOf (currentlyFocusedComponent))
            {
                if (parentComponent != nullptr)
                    parentComponent->grabKeyboardFocus();
                else
                    giveAwayFocus (true);
            }
        }

When a component is hidden, focus is given away to the parent. However, it is not checked that the parent actually took the focus. If the parent doesn’t want the focus, then it should be cleared.

Thanks for reporting. Generally the focus will bubble up to the top-level component or window but in plug-ins where we are in a host window this doesn’t always happen. Adding a second check to see if we really gave away the focus should fix it: