22// Licensed under the MIT License.
33
44using Microsoft . UI . Xaml . Automation ;
5+ using Microsoft . UI . Xaml . Input ;
56using Windows . Foundation ;
67
78namespace 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 )
0 commit comments