Fix tab navigation in search results by making SettingsGroup headers focusable

Co-authored-by: davidegiacometti <25966642+davidegiacometti@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-09-09 18:58:56 +00:00
parent ce69603d16
commit da4b02306f
2 changed files with 39 additions and 1 deletions

View File

@@ -65,6 +65,14 @@
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Unfocused" />
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Target="HeaderPresenter.Foreground" Value="{ThemeResource SystemAccentColor}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>

View File

@@ -25,6 +25,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
public SettingsGroup()
{
DefaultStyleKey = typeof(SettingsGroup);
UpdateTabStop();
// Handle focus state changes for visual feedback
GotFocus += OnGotFocus;
LostFocus += OnLostFocus;
}
[Localizable(true)]
@@ -38,7 +43,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
"Header",
typeof(string),
typeof(SettingsGroup),
new PropertyMetadata(default(string)));
new PropertyMetadata(default(string), OnHeaderChanged));
[Localizable(true)]
public object Description
@@ -68,6 +73,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
((SettingsGroup)d).Update();
}
private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((SettingsGroup)d).UpdateTabStop();
}
private void SettingsGroup_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
SetEnabledState();
@@ -95,6 +105,26 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
}
}
private void UpdateTabStop()
{
// Make the SettingsGroup focusable only when it has a header
// This allows keyboard navigation to group headers in search results
IsTabStop = !string.IsNullOrEmpty(Header);
}
private void OnGotFocus(object sender, RoutedEventArgs e)
{
if (IsTabStop)
{
VisualStateManager.GoToState(this, "Focused", true);
}
}
private void OnLostFocus(object sender, RoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Unfocused", true);
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new SettingsGroupAutomationPeer(this);