Skip to content

Commit ae591bc

Browse files
committed
Fix tab focus on mode
1 parent 86d375b commit ae591bc

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

src/Files.App.Controls/Omnibar/Omnibar.Events.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
4747
// TextBox still has focus if the context menu for selected text is open
4848
var element = Microsoft.UI.Xaml.Input.FocusManager.GetFocusedElement(this.XamlRoot);
4949
if (element is FlyoutBase or Popup)
50-
return;
51-
50+
return;
51+
5252
GlobalHelper.WriteDebugStringForOmnibar("The TextBox lost the focus.");
5353

5454
IsFocused = false;

src/Files.App.Controls/Omnibar/Omnibar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
128128
// Add the reposition transition to the all modes
129129
mode.Transitions = [new RepositionThemeTransition()];
130130
mode.UpdateLayout();
131-
mode.IsTabStop = true;
131+
mode.IsTabStop = false;
132132
}
133133

134134
var index = _modesHostGrid.Children.IndexOf(newMode);

src/Files.App.Controls/Omnibar/Omnibar.xaml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,28 @@
117117
<Setter Property="HorizontalContentAlignment" Value="Left" />
118118
<Setter Property="VerticalAlignment" Value="Stretch" />
119119

120-
<Setter Property="IsTabStop" Value="True" />
121-
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
122-
123120
<Setter Property="Template">
124121
<Setter.Value>
125122
<ControlTemplate TargetType="local:OmnibarMode">
126123
<Grid
127124
x:Name="PART_RootGrid"
128125
Height="{TemplateBinding Height}"
129126
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
130-
Background="{TemplateBinding Background}"
131-
TabFocusNavigation="Local">
127+
Background="{TemplateBinding Background}">
132128
<!-- Mode Button -->
133-
<Border
129+
<Button
134130
x:Name="PART_ModeButton"
135131
Width="{StaticResource OmnibarModeDefaultClickAreaWidth}"
136132
Margin="1"
137133
Background="{TemplateBinding Background}"
138134
BorderBrush="{TemplateBinding BorderBrush}"
139-
BorderThickness="{TemplateBinding BorderThickness}"
135+
BorderThickness="0"
140136
CornerRadius="{TemplateBinding CornerRadius}"
141-
IsTabStop="True"
142-
ToolTipService.ToolTip="{Binding ModeName, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
143-
UseSystemFocusVisuals="{StaticResource UseSystemFocusVisuals}">
144-
<Border.BackgroundTransition>
145-
<BrushTransition Duration="0:0:0.083" />
146-
</Border.BackgroundTransition>
137+
ToolTipService.ToolTip="{Binding ModeName, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
138+
<Button.Resources>
139+
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="{ThemeResource SubtleFillColorSecondary}" />
140+
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="{ThemeResource SubtleFillColorTertiary}" />
141+
</Button.Resources>
147142

148143
<Grid>
149144
<ContentPresenter
@@ -160,7 +155,7 @@
160155
Content="{Binding IconOnActive, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
161156
Visibility="Collapsed" />
162157
</Grid>
163-
</Border>
158+
</Button>
164159

165160
<ContentPresenter
166161
x:Name="PART_InactiveContent"
@@ -174,14 +169,9 @@
174169

175170
<VisualStateGroup x:Name="PointerStates">
176171
<VisualState x:Name="PointerNormal" />
177-
<VisualState x:Name="PointerOver">
178-
<VisualState.Setters>
179-
<Setter Target="PART_ModeButton.Background" Value="{ThemeResource SubtleFillColorSecondaryBrush}" />
180-
</VisualState.Setters>
181-
</VisualState>
172+
<VisualState x:Name="PointerOver" />
182173
<VisualState x:Name="PointerPressed">
183174
<VisualState.Setters>
184-
<Setter Target="PART_ModeButton.Background" Value="{ThemeResource SubtleFillColorTertiaryBrush}" />
185175
<Setter Target="PART_ModeButtonInactiveIconPresenter.Visibility" Value="Collapsed" />
186176
<Setter Target="PART_ModeButtonActiveIconPresenter.Visibility" Value="Visible" />
187177
</VisualState.Setters>

src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ private void ModeButton_PointerReleased(object sender, PointerRoutedEventArgs e)
3535
GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has been unpressed from the UI area of this Mode ({this})");
3636

3737
VisualStateManager.GoToState(this, "PointerOver", true);
38-
39-
owner.IsModeButtonPressed = true;
40-
41-
// Change the current mode
42-
owner.CurrentSelectedMode = this;
4338
}
4439

4540
private void ModeButton_PointerExited(object sender, PointerRoutedEventArgs e)
@@ -48,5 +43,14 @@ private void ModeButton_PointerExited(object sender, PointerRoutedEventArgs e)
4843

4944
VisualStateManager.GoToState(this, "PointerNormal", true);
5045
}
46+
47+
private void ModeButton_Click(object sender, RoutedEventArgs e)
48+
{
49+
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
50+
return;
51+
52+
owner.IsModeButtonPressed = true;
53+
owner.CurrentSelectedMode = this;
54+
}
5155
}
52-
}
56+
}

src/Files.App.Controls/Omnibar/OmnibarMode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class OmnibarMode : ItemsControl
1616

1717
private WeakReference<Omnibar>? _ownerRef;
1818

19-
private Border _modeButton = null!;
19+
private Button _modeButton = null!;
2020

2121
// Constructor
2222

@@ -33,14 +33,15 @@ protected override void OnApplyTemplate()
3333
{
3434
base.OnApplyTemplate();
3535

36-
_modeButton = GetTemplateChild(TemplatePartName_ModeButton) as Border
36+
_modeButton = GetTemplateChild(TemplatePartName_ModeButton) as Button
3737
?? throw new MissingFieldException($"Could not find {TemplatePartName_ModeButton} in the given {nameof(OmnibarMode)}'s style.");
3838

3939
Loaded += OmnibarMode_Loaded;
4040
_modeButton.PointerEntered += ModeButton_PointerEntered;
4141
_modeButton.PointerPressed += ModeButton_PointerPressed;
4242
_modeButton.PointerReleased += ModeButton_PointerReleased;
4343
_modeButton.PointerExited += ModeButton_PointerExited;
44+
_modeButton.Click += ModeButton_Click;
4445

4546
GlobalHelper.WriteDebugStringForOmnibar($"The template and the events of the Omnibar Mode ({this}) have been initialized.");
4647
}

0 commit comments

Comments
 (0)