Skip to content

Commit 2b657ae

Browse files
committed
Trying to fix "Tab navigation isn't properly focusing on the Breadcrumb Bar"
1 parent 5ddb463 commit 2b657ae

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.UI.Xaml.Automation;
5+
using Microsoft.UI.Xaml.Input;
56
using Windows.Foundation;
67

78
namespace Files.App.Controls
@@ -25,6 +26,8 @@ public partial class BreadcrumbBar : Control
2526

2627
private bool _isEllipsisRendered;
2728

29+
private bool _focusedViaKeyboard = false; // Used to determine if the BreadcrumbBar was focused via keyboard on Tab focus
30+
2831
// Properties
2932

3033
public int IndexAfterEllipsis
@@ -62,11 +65,18 @@ protected override void OnApplyTemplate()
6265
_ellipsisBreadcrumbBarItem.SetOwner(this);
6366
_itemsRepeater.Layout = _itemsRepeaterLayout;
6467

68+
//GettingFocus += BreadcrumbBar_GettingFocus;
69+
//GettingFocus += BreadcrumbBar_GotFocus;
6570
_itemsRepeater.ElementPrepared += ItemsRepeater_ElementPrepared;
6671
_itemsRepeater.ElementClearing += ItemsRepeater_ElementClearing;
6772
_itemsRepeater.ItemsSourceView.CollectionChanged += ItemsSourceView_CollectionChanged;
6873
}
6974

75+
private void BreadcrumbBar_GettingFocus(UIElement sender, GettingFocusEventArgs args)
76+
{
77+
_focusedViaKeyboard = args.InputDevice is FocusInputDeviceKind.Keyboard;
78+
}
79+
7080
internal protected virtual void RaiseItemClickedEvent(BreadcrumbBarItem item)
7181
{
7282
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
@@ -122,6 +132,11 @@ internal bool TryGetElement(int index, out BreadcrumbBarItem? item)
122132

123133
// Event methods
124134

135+
private void BreadcrumbBar_GotFocus(object sender, RoutedEventArgs e)
136+
{
137+
_rootBreadcrumbBarItem?.Focus(FocusState.Keyboard);
138+
}
139+
125140
private void ItemsRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args)
126141
{
127142
if (args.Element is not BreadcrumbBarItem item || _itemsRepeater is null)

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
Grid.Column="0"
5858
Padding="{StaticResource BreadcrumbBarRootItemPadding}"
5959
CornerRadius="{StaticResource BreadcrumbBarRootItemCornerRadius}"
60-
ItemToolTip="{TemplateBinding RootItemToolTip}">
60+
ItemToolTip="{TemplateBinding RootItemToolTip}"
61+
TabIndex="0">
6162
<ContentPresenter Content="{Binding RootItem, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
6263
</local:BreadcrumbBarItem>
6364

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs a
3030
args.TryCancel();
3131
return;
3232
}
33+
34+
if (args.InputDevice is FocusInputDeviceKind.Keyboard || args.Direction is FocusNavigationDirection.Next or FocusNavigationDirection.Previous)
35+
{
36+
CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Programmatic);
37+
}
3338
}
3439

3540
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
124124
// Add the reposition transition to the all modes
125125
mode.Transitions = [new RepositionThemeTransition()];
126126
mode.UpdateLayout();
127-
mode.IsTabStop = true;
128127
}
129128

130129
var index = _modesHostGrid.Children.IndexOf(newMode);
@@ -154,7 +153,6 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
154153
ChangeTextBoxText(newMode.Text ?? string.Empty);
155154

156155
VisualStateManager.GoToState(newMode, "Focused", true);
157-
newMode.IsTabStop = false;
158156

159157
ModeChanged?.Invoke(this, new(oldMode, newMode!));
160158

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
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}" />
120+
<!--<Setter Property="IsTabStop" Value="True" />
121+
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />-->
122122

123123
<Setter Property="Template">
124124
<Setter.Value>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ namespace Files.App.Controls
77
{
88
public partial class OmnibarMode
99
{
10+
private void ModeButton_KeyDown(object sender, KeyRoutedEventArgs e)
11+
{
12+
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
13+
return;
14+
15+
if (e.Key is Windows.System.VirtualKey.Enter)
16+
{
17+
owner.CurrentSelectedMode = this;
18+
}
19+
}
20+
1021
private void ModeButton_PointerEntered(object sender, PointerRoutedEventArgs e)
1122
{
1223
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected override void OnApplyTemplate()
3535
?? throw new MissingFieldException($"Could not find {TemplatePartName_ModeButton} in the given {nameof(OmnibarMode)}'s style.");
3636

3737
Loaded += OmnibarMode_Loaded;
38+
_modeButton.KeyDown += ModeButton_KeyDown;
3839
_modeButton.PointerEntered += ModeButton_PointerEntered;
3940
_modeButton.PointerPressed += ModeButton_PointerPressed;
4041
_modeButton.PointerReleased += ModeButton_PointerReleased;

0 commit comments

Comments
 (0)