mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-25 14:45:45 -04:00
Restore focus to re-enabled elements
This commit is contained in:
@@ -49,13 +49,24 @@ void Component::set_disabled(bool value) {
|
||||
if (Component::disabled() == value) {
|
||||
return;
|
||||
}
|
||||
auto* context = mRoot->GetContext();
|
||||
if (value) {
|
||||
if (context != nullptr && context->GetFocusElement() == mRoot) {
|
||||
// RmlUi moves focus to the parent when a focused control is disabled.
|
||||
mDisabledFocusFallback = mRoot->GetParentNode();
|
||||
}
|
||||
mRoot->SetAttribute("disabled", "");
|
||||
mRoot->SetPseudoClass("disabled", true);
|
||||
mRoot->Blur();
|
||||
} else {
|
||||
const bool restoreFocus = mDisabledFocusFallback != nullptr && context != nullptr &&
|
||||
context->GetFocusElement() == mDisabledFocusFallback;
|
||||
mRoot->RemoveAttribute("disabled");
|
||||
mRoot->SetPseudoClass("disabled", false);
|
||||
mDisabledFocusFallback = nullptr;
|
||||
if (restoreFocus) {
|
||||
focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user