mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
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:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user