Skip to content

Commit e6c03bc

Browse files
committed
fix: Popup should receive focus if its child is focusable
1 parent d03e44d commit e6c03bc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Uno.UI/UI/Xaml/Controls/Popup/Popup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public partial class Popup : PopupBase
2525

2626
internal bool IsSubMenu { get; set; }
2727

28+
/// <summary>
29+
/// In WinUI, Popup has IsTabStop set to true by default.
30+
/// UWP does not include IsTabStop, but Popup is still focusable.
31+
/// </summary>
32+
private protected override bool IsTabStopDefaultValue => true;
33+
2834
/// <summary>
2935
/// Returns true if the popup should show the light-dismiss overlay with its current configuration, false if not
3036
/// </summary>

src/Uno.UI/UI/Xaml/Controls/Popup/PopupBase.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,27 @@ partial void OnIsOpenChangedPartial(bool oldIsOpen, bool newIsOpen)
7878
_lastFocusedElement = new WeakReference<UIElement>(focusedElement);
7979
_lastFocusState = focusState;
8080
}
81+
82+
// Give the child focus if allowed
83+
if (Child is FrameworkElement fw && fw.AllowFocusOnInteraction)
84+
{
85+
Focus(FocusState.Programmatic);
86+
}
8187
}
8288

8389
Opened?.Invoke(this, newIsOpen);
8490
}
8591
else
8692
{
8793
_openPopupRegistration?.Dispose();
88-
89-
if (_lastFocusedElement != null && _lastFocusedElement.TryGetTarget(out var target))
94+
95+
if (IsLightDismissEnabled)
9096
{
91-
target.Focus(_lastFocusState);
92-
_lastFocusedElement = null;
97+
if (_lastFocusedElement != null && _lastFocusedElement.TryGetTarget(out var target))
98+
{
99+
target.Focus(_lastFocusState);
100+
_lastFocusedElement = null;
101+
}
93102
}
94103

95104
Closed?.Invoke(this, newIsOpen);

0 commit comments

Comments
 (0)