diff --git a/dev/MenuBar/MenuBarItem.cpp b/dev/MenuBar/MenuBarItem.cpp index 4c038f05bf..21ddb8e095 100644 --- a/dev/MenuBar/MenuBarItem.cpp +++ b/dev/MenuBar/MenuBarItem.cpp @@ -214,29 +214,32 @@ void MenuBarItem::OnMenuBarItemAccessKeyInvoked(winrt::IInspectable const& sende // Menu Flyout actions void MenuBarItem::ShowMenuFlyout() { - if (auto button = m_button.get()) + if (Items().Size() != 0) { - const auto width = static_cast(button.ActualWidth()); - const auto height = static_cast(button.ActualHeight()); - - if (SharedHelpers::IsFlyoutShowOptionsAvailable()) - { - // Sets an exclusion rect over the button that generates the flyout so that even if the menu opens upwards - // (which is the default in touch mode) it doesn't cover the menu bar button. - winrt::FlyoutShowOptions options{}; - options.Position(winrt::Point(0, height)); - options.Placement(winrt::FlyoutPlacementMode::Bottom); - options.ExclusionRect(winrt::Rect(0, 0, width, height)); - m_flyout.get().ShowAt(button, options); - } - else + if (auto button = m_button.get()) { - m_flyout.get().ShowAt(button, winrt::Point(0, height)); + const auto width = static_cast(button.ActualWidth()); + const auto height = static_cast(button.ActualHeight()); + + if (SharedHelpers::IsFlyoutShowOptionsAvailable()) + { + // Sets an exclusion rect over the button that generates the flyout so that even if the menu opens upwards + // (which is the default in touch mode) it doesn't cover the menu bar button. + winrt::FlyoutShowOptions options{}; + options.Position(winrt::Point(0, height)); + options.Placement(winrt::FlyoutPlacementMode::Bottom); + options.ExclusionRect(winrt::Rect(0, 0, width, height)); + m_flyout.get().ShowAt(button, options); + } + else + { + m_flyout.get().ShowAt(button, winrt::Point(0, height)); + } + + // Attach keyboard event handler + auto presenter = winrt::get_self(m_flyout.get())->m_presenter.get(); + m_presenterKeyDownRevoker = presenter.KeyDown(winrt::auto_revoke, { this, &MenuBarItem::OnPresenterKeyDown }); } - - // Attach keyboard event handler - auto presenter = winrt::get_self(m_flyout.get())->m_presenter.get(); - m_presenterKeyDownRevoker = presenter.KeyDown(winrt::auto_revoke, { this, &MenuBarItem::OnPresenterKeyDown }); } } diff --git a/dev/MenuBar/MenuBar_InteractionTests/MenuBarTests.cs b/dev/MenuBar/MenuBar_InteractionTests/MenuBarTests.cs index 3c20da119f..56242c6a33 100644 --- a/dev/MenuBar/MenuBar_InteractionTests/MenuBarTests.cs +++ b/dev/MenuBar/MenuBar_InteractionTests/MenuBarTests.cs @@ -375,6 +375,30 @@ public void TabTest() } } + [TestMethod] + public void EmptyMenuBarItemNoPopupTest() + { + if (PlatformConfiguration.IsDevice(DeviceType.Phone)) + { + Log.Comment("Skipping tests on phone, because menubar is not supported."); + return; + } + using (var setup = new TestSetupHelper("MenuBar Tests")) + { + FindElement.ByName