From b29a29b8b626fcd0888f17981e92341dfada8155 Mon Sep 17 00:00:00 2001 From: Karen Lai <7976322+karenbtlai@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:40:06 -0800 Subject: [PATCH] Exclude MoreButton if Not using PrimaryCommands (#6044) * exclude MoreButton if not using primaryCommands * workaround for commandBarFlyout no primary keyboard focus * new test wip * add new test * add new test case * fix failing rs2 test * fix failing tests * update tests * set up test for dynamic primary commands scenario * add dynamic add primary command test --- .../CommandBarFlyoutCommandBar.cpp | 13 ++- .../InteractionTests/CommandBarFlyoutTests.cs | 92 +++++++++++++++++++ .../TestUI/CommandBarFlyoutPage.xaml | 10 +- .../TestUI/CommandBarFlyoutPage.xaml.cs | 86 ++++++++++++++++- 4 files changed, 195 insertions(+), 6 deletions(-) diff --git a/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp b/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp index ca1a8fc02b..fae82e0e3f 100644 --- a/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp +++ b/dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp @@ -678,7 +678,7 @@ void CommandBarFlyoutCommandBar::UpdateTemplateSettings() collapsedWidth = static_cast(expandedWidth); } - flyoutTemplateSettings->WidthExpansionDelta(collapsedWidth - expandedWidth); + flyoutTemplateSettings->WidthExpansionDelta(0); flyoutTemplateSettings->WidthExpansionAnimationStartPosition(-flyoutTemplateSettings->WidthExpansionDelta() / 2.0); flyoutTemplateSettings->WidthExpansionAnimationEndPosition(-flyoutTemplateSettings->WidthExpansionDelta()); flyoutTemplateSettings->ContentClipRect({ 0, 0, static_cast(expandedWidth), primaryItemsRootDesiredSize.Height }); @@ -896,7 +896,9 @@ void CommandBarFlyoutCommandBar::PopulateAccessibleControls() m_verticallyAccessibleControls.Clear(); } - for (winrt::ICommandBarElement const& command : PrimaryCommands()) + const auto primaryCommands = PrimaryCommands(); + + for (winrt::ICommandBarElement const& command : primaryCommands) { if (auto const& commandAsControl = command.try_as()) { @@ -907,8 +909,11 @@ void CommandBarFlyoutCommandBar::PopulateAccessibleControls() if (auto const& moreButton = m_moreButton.get()) { - m_horizontallyAccessibleControls.Append(moreButton); - m_verticallyAccessibleControls.Append(moreButton); + if (primaryCommands.Size() > 0) + { + m_horizontallyAccessibleControls.Append(moreButton); + m_verticallyAccessibleControls.Append(moreButton); + } } for (winrt::ICommandBarElement const& command : SecondaryCommands()) diff --git a/dev/CommandBarFlyout/InteractionTests/CommandBarFlyoutTests.cs b/dev/CommandBarFlyout/InteractionTests/CommandBarFlyoutTests.cs index 3e1968f0a5..243818dc44 100644 --- a/dev/CommandBarFlyout/InteractionTests/CommandBarFlyoutTests.cs +++ b/dev/CommandBarFlyout/InteractionTests/CommandBarFlyoutTests.cs @@ -992,5 +992,97 @@ public void VerifyDynamicSecondaryCommandLabel() Verify.AreEqual(finalBoundingRectangle.Height, initialBoundingRectangle.Height); } } + + [TestMethod] + public void VerifyIsFlyoutKeyboardAccessibleWithNoPrimaryCommands() + { + if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2)) + { + Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2"); + return; + } + + using (var setup = new CommandBarFlyoutTestSetupHelper()) + { + Button showCommandBarFlyoutButtonWithNoPrimaryCommands = FindElement.ByName