Skip to content

Commit d03e44d

Browse files
committed
test: Flyout should return focus to previously focused
1 parent 4d8af83 commit d03e44d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Windows.UI.Xaml.Controls;
1515
using Windows.UI.Xaml.Controls.Primitives;
1616
using Windows.UI.Xaml.Data;
17+
using Windows.UI.Xaml.Input;
1718
using Windows.UI.Xaml.Media;
1819
using Windows.UI.Xaml.Shapes;
1920

@@ -459,6 +460,38 @@ public async Task Test_Flyout_Binding()
459460
#endif
460461
}
461462

463+
[TestMethod]
464+
[RunsOnUIThread]
465+
public async Task When_Flyout_Content_Takes_Focus()
466+
{
467+
var stackPanel = new StackPanel();
468+
var button = new Button() { Content = "Flyout owner" };
469+
stackPanel.Children.Add(button);
470+
TestServices.WindowHelper.WindowContent = stackPanel;
471+
await TestServices.WindowHelper.WaitForIdle();
472+
473+
var flyout = new Flyout();
474+
var flyoutButton = new Button() { Content = "Flyout content" };
475+
flyout.Content = flyoutButton;
476+
FlyoutBase.SetAttachedFlyout(button, flyout);
477+
button.Focus(FocusState.Pointer);
478+
479+
Assert.AreEqual(button, FocusManager.GetFocusedElement());
480+
481+
FlyoutBase.ShowAttachedFlyout(button);
482+
flyoutButton.Focus(FocusState.Pointer);
483+
await TestServices.WindowHelper.WaitForIdle();
484+
485+
Assert.AreNotEqual(button, FocusManager.GetFocusedElement());
486+
487+
flyout.Hide();
488+
await TestServices.WindowHelper.WaitForIdle();
489+
490+
Assert.AreEqual(button, FocusManager.GetFocusedElement());
491+
492+
TestServices.WindowHelper.WindowContent = null;
493+
}
494+
462495
private static void VerifyRelativeContentPosition(HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, FrameworkElement target)
463496
{
464497
var contentScreenBounds = content.GetOnScreenBounds();

0 commit comments

Comments
 (0)