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,10 +65,17 @@ 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 . ItemsSourceView . CollectionChanged += ItemsSourceView_CollectionChanged ;
6772 }
6873
74+ private void BreadcrumbBar_GettingFocus ( UIElement sender , GettingFocusEventArgs args )
75+ {
76+ _focusedViaKeyboard = args . InputDevice is FocusInputDeviceKind . Keyboard ;
77+ }
78+
6979 internal protected virtual void RaiseItemClickedEvent ( BreadcrumbBarItem item )
7080 {
7181 var index = _itemsRepeater ? . GetElementIndex ( item ) ?? throw new ArgumentNullException ( $ "{ _itemsRepeater } is null.") ;
@@ -121,6 +131,11 @@ internal bool TryGetElement(int index, out BreadcrumbBarItem? item)
121131
122132 // Event methods
123133
134+ private void BreadcrumbBar_GotFocus ( object sender , RoutedEventArgs e )
135+ {
136+ _rootBreadcrumbBarItem ? . Focus ( FocusState . Keyboard ) ;
137+ }
138+
124139 private void ItemsRepeater_ElementPrepared ( ItemsRepeater sender , ItemsRepeaterElementPreparedEventArgs args )
125140 {
126141 if ( args . Element is not BreadcrumbBarItem item || _itemsRepeater is null )
0 commit comments