From 3fac21553433ac3f75c11ee989c4eae284dda1fb Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 8 Oct 2021 11:32:19 +0100 Subject: [PATCH] Component: Give away keyboard focus when disabled --- modules/juce_gui_basics/components/juce_Component.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 245f0bb91d..2fc36410ec 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -3007,6 +3007,15 @@ void Component::setEnabled (bool shouldBeEnabled) BailOutChecker checker (this); componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentEnablementChanged (*this); }); + + if (! shouldBeEnabled && hasKeyboardFocus (true)) + { + if (parentComponent != nullptr) + parentComponent->grabKeyboardFocus(); + + // ensure that keyboard focus is given away if it wasn't taken by parent + giveAwayKeyboardFocus(); + } } }