Skip to content

Commit 3d64db3

Browse files
Merge pull request #75 from saiganesh-sakthivel/main
SegmentedControl does not receive Focus when pressing the Tab key on Windows
2 parents 171777e + 15aac10 commit 3d64db3

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

maui/src/SegmentedControl/Interface/ISegmentInfo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ internal interface ISegmentItemInfo : ISegmentInfo
130130
/// </summary>
131131
void ClearFocusedView();
132132

133+
#if WINDOWS
134+
/// <summary>
135+
/// Update the keyboard focused view for the segmentedControl.
136+
/// </summary>
137+
void SetFocusVisualState(bool state);
138+
#endif
139+
133140
/// <summary>
134141
/// Updates the scroll view position to focused index for the segment item.
135142
/// </summary>

maui/src/SegmentedControl/SfSegmentedControl.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,21 @@ protected override Size ArrangeContent(Rect bounds)
10671067
return base.ArrangeContent(bounds);
10681068
}
10691069

1070+
#if WINDOWS
1071+
/// <summary>
1072+
/// Raises when <see cref="SfSegmentedControl"/>'s handler gets changed.
1073+
/// <exclude/>
1074+
/// </summary>
1075+
protected override void OnHandlerChanged()
1076+
{
1077+
base.OnHandlerChanged();
1078+
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement nativeView)
1079+
{
1080+
nativeView.IsTabStop = true;
1081+
}
1082+
}
1083+
#endif
1084+
10701085
/// <summary>
10711086
/// Invokes on the binding context of the view changed.
10721087
/// </summary>
@@ -1174,6 +1189,16 @@ void ISegmentItemInfo.ClearFocusedView()
11741189
_keyNavigationView?.ClearFocusedView();
11751190
}
11761191

1192+
#if WINDOWS
1193+
void ISegmentItemInfo.SetFocusVisualState(bool state)
1194+
{
1195+
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement nativeView)
1196+
{
1197+
nativeView.UseSystemFocusVisuals = state;
1198+
}
1199+
}
1200+
#endif
1201+
11771202
/// <summary>
11781203
/// Updates the scroll view position to focused index for the segment item.
11791204
/// </summary>

maui/src/SegmentedControl/Views/Keyboard/KeyNavigationView.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,21 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
199199
canvas.CanvasRestoreState();
200200
}
201201

202-
#endregion
202+
#if WINDOWS
203+
/// <summary>
204+
/// Raises when <see cref="KeyNavigationView"/>'s handler gets changed.
205+
/// <exclude/>
206+
/// </summary>
207+
protected override void OnHandlerChanged()
208+
{
209+
base.OnHandlerChanged();
210+
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement platformView)
211+
{
212+
platformView.IsTabStop = false;
213+
}
214+
}
215+
#endif
216+
217+
#endregion
203218
}
204219
}

maui/src/SegmentedControl/Views/OutlinedBorderView.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
8383
base.OnDraw(canvas, dirtyRect);
8484
}
8585

86+
#if WINDOWS
87+
/// <summary>
88+
/// Raises when <see cref="OutlinedBorderView"/>'s handler gets changed.
89+
/// <exclude/>
90+
/// </summary>
91+
protected override void OnHandlerChanged()
92+
{
93+
base.OnHandlerChanged();
94+
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement platformView)
95+
{
96+
platformView.IsTabStop = false;
97+
}
98+
}
99+
#endif
100+
86101
#endregion
87102
}
88103
}

maui/src/SegmentedControl/Views/SegmentLayout.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ internal void ProcessOnKeyDown(KeyEventArgs e)
196196
_focusedIndex = -1;
197197
}
198198

199+
#if WINDOWS
200+
if (e.Key == KeyboardKey.Left || e.Key == KeyboardKey.Right)
201+
{
202+
_itemInfo?.SetFocusVisualState(false);
203+
}
204+
#endif
205+
206+
if (e.Key == KeyboardKey.Tab || (e.Key == KeyboardKey.Tab && e.IsShiftKeyPressed) || e.Key == KeyboardKey.Down || e.Key == KeyboardKey.Up)
207+
{
208+
e.Handled = false;
209+
_focusedIndex = -1;
210+
_itemInfo?.ClearFocusedView();
211+
#if WINDOWS
212+
_itemInfo?.SetFocusVisualState(true);
213+
#endif
214+
return;
215+
}
216+
199217
e.Handled = true;
200218
}
201219

maui/src/SegmentedControl/Views/Selection/SelectionView.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
298298
base.OnDraw(canvas, dirtyRect);
299299
}
300300

301+
#if WINDOWS
302+
protected override void OnHandlerChanged()
303+
{
304+
base.OnHandlerChanged();
305+
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement platformView)
306+
{
307+
platformView.IsTabStop = false;
308+
}
309+
}
310+
#endif
311+
301312
#endregion
302313
}
303314
}

0 commit comments

Comments
 (0)