Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude MoreButton if Not using PrimaryCommands #6044

Merged
merged 10 commits into from
Nov 9, 2021

Conversation

karkarl
Copy link
Contributor

@karkarl karkarl commented Oct 6, 2021

Description

If no PrimaryCommands is present, the SeeMore button is still visible and focusable, causing keyboard accessibility issues.

The fix is to check if PrimaryCommands().Size() > 0 at PopulateAccessibleControls() on PrimaryCommands().VectorChanged(). If size is 0, the SeeMore button is excluded from being populated in the horizontally and vertically accessible controls member variable, and is no longer accessible.

Motivation and Context

Fixes #5857 and internal bug 35345814

How Has This Been Tested?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 6, 2021
@ranjeshj ranjeshj added team-Controls Issue for the Controls team area-Commanding AppBar, UICommand, MVVM, etc and removed needs-triage Issue needs to be triaged by the area owners labels Oct 6, 2021
@ranjeshj ranjeshj requested a review from llongley October 6, 2021 19:51
@ranjeshj
Copy link
Contributor

ranjeshj commented Oct 6, 2021

@karenbtlai can you please add a test ?

@karkarl
Copy link
Contributor Author

karkarl commented Oct 20, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the primary commands size is reduced from 1 to 0? what about if its increased from 0 to 1? do we have the appropriate code in place to make sure that the more button is added or removed based on this? Can we add a test for these scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

var favoriteToggleElement = AutomationElement.FocusedElement;
Verify.AreEqual(favoriteToggleElement.Current.AutomationId, favoriteToggleButton6.AutomationId);

Log.Comment("Press Down key to make sure commands loops back focus to first secondary command: Redo.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this test faster by simply pressing the up key from the first element and making sure it goes to the last and not the more button?

Copy link
Contributor Author

@karkarl karkarl Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@karkarl
Copy link
Contributor Author

karkarl commented Oct 26, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@karkarl
Copy link
Contributor Author

karkarl commented Oct 27, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@karkarl
Copy link
Contributor Author

karkarl commented Oct 28, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


[TestMethod]
public void VerifyAddRemovePrimaryCommands()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't test the removal of a primary command, only the addition of one.

More importantly, I wouldn't expect the behavior to fail when you change the number of commands in the CBF while it is closed. The bug I called out in the product code would only happen if you change the number of commands while the flyout is open.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a scenario where the number of commands will change while the flyout is open, since CBF is a flyout and transient by design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. Test case is updated to be adding PrimaryCommands dynamically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness removing the last primary command could also be tested. It uses what looks like the same code path though so maybe it is fine.

@karkarl
Copy link
Contributor Author

karkarl commented Nov 3, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@karkarl
Copy link
Contributor Author

karkarl commented Nov 6, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@StephenLPeters StephenLPeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure that the WidthExpansionDelta change makes sense.


[TestMethod]
public void VerifyAddRemovePrimaryCommands()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness removing the last primary command could also be tested. It uses what looks like the same code path though so maybe it is fine.

@@ -678,7 +678,7 @@ void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
collapsedWidth = static_cast<float>(expandedWidth);
}

flyoutTemplateSettings->WidthExpansionDelta(collapsedWidth - expandedWidth);
flyoutTemplateSettings->WidthExpansionDelta(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change, but if @llongley or someone else does that is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was a need for a nonzero value for this, but Karen said that she tested all of the scenarios and they all continue to look right, so if that's the case it seems OK to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When PrimaryCommands are being loaded dynamically, it causes a weird crop issue that is caused by a negative WidthExpansionDelta. Setting it to 0 fixes this specific use case. Upon investigation, it seems a non-zero WidthExpansionDelta is only for when SecondaryCommands is collapsed, and the width of primaryCommands is less than the width of SecondaryCommands, so the flyout expands to the full width when opening the secondaryCommands.

However, setting it to 0 doesn't seem to break that scenario. This may be because CBF no longer has the expanding animation. I manually all scenarios with and without the WidthExpansionDelta change, and it doesn't change or break anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CBF does have the expanding animation still though, there is a button for it on the CommandBarFlyout test page labeled "Show expanding CommandBarFlyout"

This is the behavior before this change:

PreChange.mp4

and this is the behavior after the change

PostChange.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I now see a subtle expanding animation that is missing from the update. I think the appropriate action is to revert the hardcoding of ExpansionWidthDelta, and fix the dynamically adding primary buttons in a separate fix. It is beyond the scope of the original accessibility bug to begin with.

@karkarl karkarl merged commit b29a29b into main Nov 9, 2021
@karkarl karkarl deleted the user/karenlai/CommandBarFlyoutFocusFix branch November 9, 2021 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Commanding AppBar, UICommand, MVVM, etc team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Focus disappears in CommandBarFlyout with SecondaryCommands, no PrimaryCommands
4 participants