Skip to content

Commit

Permalink
Merge pull request unoplatform#13634 from ramezgerges/focus_flyout_child
Browse files Browse the repository at this point in the history
fix(flyout): focus flyout child on open
  • Loading branch information
jeromelaban authored Sep 22, 2023
2 parents 8402b30 + 2ed32f0 commit cfd9f5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ public void ContentDialog_Simple_NotLightDismissible()

// tapping outside of dialog
var dialogRect = _app.GetLogicalRect(dialogSpace);
var dialogRectangle = dialogRect.ToRectangle(); // we need this later after the dialog is closed
_app.TapCoordinates(dialogRect.CenterX, dialogRect.Bottom + 50);
var dialogStillOpenedScreenshot = CurrentTestTakeScreenShot("2 ContentDialog Still Opened");

Expand All @@ -407,11 +408,13 @@ public void ContentDialog_Simple_NotLightDismissible()
_app.Wait(seconds: 1);
var dialogClosedScreenshot = CurrentTestTakeScreenShot("3 ContentDialog Closed");

// Test only to the left of the TextBox, which can have a blinking cursor and might fail the screenshot tests
var testRect = new Rectangle(0, 0, (int)dialogRectangle.X + 10, dialogOpenedScreenshot.Height);

// compare
ImageAssert.AreNotEqual(initialScreenshot, dialogOpenedScreenshot);
ImageAssert.AreEqual(dialogOpenedScreenshot, dialogStillOpenedScreenshot);
ImageAssert.AreEqual(dialogOpenedScreenshot, dialogStillOpenedScreenshot, testRect);
ImageAssert.AreNotEqual(dialogStillOpenedScreenshot, dialogClosedScreenshot);

}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ public async Task When_Flyout_Has_Focusable_Child()
stackPanel.Children.Add(button);
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForIdle();
await TestServices.WindowHelper.WaitForLoaded(button);

var flyout = new Flyout();
var flyoutButton = new Button() { Content = "Flyout content" };
Expand All @@ -621,9 +622,9 @@ public async Task When_Flyout_Has_Focusable_Child()

FlyoutBase.ShowAttachedFlyout(button);
await TestServices.WindowHelper.WaitForIdle();
await TestServices.WindowHelper.WaitForLoaded(flyoutButton);

var focused = FocusManager.GetFocusedElement(TestServices.WindowHelper.XamlRoot);
Assert.IsInstanceOfType(focused, typeof(Popup));
Assert.AreEqual(flyoutButton, FocusManager.GetFocusedElement(TestServices.WindowHelper.XamlRoot));

flyout.Hide();
await TestServices.WindowHelper.WaitForIdle();
Expand Down
4 changes: 0 additions & 4 deletions src/Uno.UI/UI/Xaml/Controls/Popup/Popup.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ partial void OnIsOpenChangedPartial(bool oldIsOpen, bool newIsOpen)
Focus(FocusState.Programmatic);
}
}

Opened?.Invoke(this, newIsOpen);
}
else
{
Expand All @@ -131,8 +129,6 @@ partial void OnIsOpenChangedPartial(bool oldIsOpen, bool newIsOpen)
{
elementToFocus.Focus(FocusState.Programmatic);
}

Closed?.Invoke(this, newIsOpen);
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Popup/Popup.WithPopupRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,30 @@ partial void OnIsOpenChangedPartialNative(bool oldIsOpen, bool newIsOpen)
}
#endif

// It's important for PopupPanel to be visible before the popup is opened so that
// child controls can be IsFocusable, which depends on all ancestors (including PopupPanel)
// being visible
PopupPanel.Visibility = Visibility.Visible;

var currentXamlRoot = XamlRoot ?? Child?.XamlRoot ?? WinUICoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot;
_closePopup.Disposable = currentXamlRoot?.OpenPopup(this);

PopupPanel.Visibility = Visibility.Visible;
}
else
{
_closePopup.Disposable = null;
PopupPanel.Visibility = Visibility.Collapsed;
}
}

if (newIsOpen)
{
Opened?.Invoke(this, newIsOpen);
}
else
{
Closed?.Invoke(this, newIsOpen);
}
}

#if __ANDROID__
Expand Down

0 comments on commit cfd9f5e

Please sign in to comment.