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

MenuBar Keyboard Accessibility Fixes #6953

Merged
merged 6 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion dev/MenuBar/MenuBarItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,42 @@ void MenuBarItem::OnMenuBarItemKeyDown( winrt::IInspectable const& sender, winrt
{
ShowMenuFlyout();
}
else if (key == winrt::VirtualKey::Right)
{
if (FlowDirection() == winrt::FlowDirection::RightToLeft)
{
MoveFocusTo(FlyoutLocation::Left);
}
else
{
MoveFocusTo(FlyoutLocation::Right);
}
}
else if (key == winrt::VirtualKey::Left)
{
if (FlowDirection() == winrt::FlowDirection::RightToLeft)
{
MoveFocusTo(FlyoutLocation::Right);
}
else
{
MoveFocusTo(FlyoutLocation::Left);
}
}

args.Handled(TRUE);
bkudiess marked this conversation as resolved.
Show resolved Hide resolved
}

void MenuBarItem::OnPresenterKeyDown( winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args)
{
if (auto const& subitem = args.OriginalSource().try_as<winrt::MenuFlyoutSubItem>())
bkudiess marked this conversation as resolved.
Show resolved Hide resolved
{
if (subitem.Items().GetAt(0))
{
return;
}
}

const auto key = args.Key();
if (key == winrt::VirtualKey::Right)
{
Expand Down Expand Up @@ -269,6 +301,23 @@ void MenuBarItem::OpenFlyoutFrom(FlyoutLocation location)
}
}

void MenuBarItem::MoveFocusTo(FlyoutLocation location)
{
if (auto menuBar = m_menuBar.get())
{
uint32_t index = 0;
menuBar.Items().IndexOf(*this, index);
if (location == FlyoutLocation::Left)
{
winrt::get_self<MenuBarItem>(menuBar.Items().GetAt(((index - 1) + menuBar.Items().Size()) % menuBar.Items().Size()))->Focus(winrt::FocusState::Programmatic);
}
else
{
winrt::get_self<MenuBarItem>(menuBar.Items().GetAt((index + 1) % menuBar.Items().Size()))->Focus(winrt::FocusState::Programmatic);
}
}
}

void MenuBarItem::AddPassThroughElement(const winrt::DependencyObject& element)
{
m_passThroughElement = winrt::make_weak(element);
Expand Down Expand Up @@ -306,7 +355,7 @@ void MenuBarItem::OnFlyoutClosed( winrt::IInspectable const& sender, winrt::IIns

void MenuBarItem::OnFlyoutOpening( winrt::IInspectable const& sender, winrt::IInspectable const& args)
{
Focus(winrt::FocusState::Pointer);
Focus(winrt::FocusState::Programmatic);

m_isFlyoutOpen = true;

Expand Down
1 change: 1 addition & 0 deletions dev/MenuBar/MenuBarItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MenuBarItem :
void AttachEventHandlers();
void DetachEventHandlers(bool useSafeGet = false);
void OpenFlyoutFrom(FlyoutLocation location);
void MoveFocusTo(FlyoutLocation location);

void OnVisualPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args);
void UpdateVisualStates();
Expand Down