Skip to content

Commit

Permalink
[a11y] Make CommandPalette announce selected item (#13519)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
The command palette (and tab search by extension) doesn't ever tell screen readers what is selected. Here, we simply hook up the selection changed event to a function that tells the screen reader what is selected. With this, the user no longer has to tab into the list view to know what is selected!

Will resolve the following bug upon validation from a11y team: #12065 

## Validation Steps Performed
Performed repro steps from #12065.

NOTE: we do NOT read the selected item when the command palette is first opened. I think that's ok.
  • Loading branch information
carlos-zamora authored Aug 26, 2022
1 parent 623a59e commit deb5e7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,34 @@ namespace winrt::TerminalApp::implementation
}
}

void CommandPalette::_listItemSelectionChanged(const Windows::Foundation::IInspectable& /*sender*/, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& e)
{
// We don't care about...
// - CommandlineMode: it doesn't have any selectable items in the list view
// - TabSwitchMode: focus and selected item are in sync
if (_currentMode == CommandPaletteMode::ActionMode || _currentMode == CommandPaletteMode::TabSearchMode)
{
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(_searchBox()) })
{
if (const auto selectedList = e.AddedItems(); selectedList.Size() > 0)
{
const auto selectedCommand = selectedList.GetAt(0);
if (const auto filteredCmd = selectedCommand.try_as<TerminalApp::FilteredCommand>())
{
if (const auto paletteItem = filteredCmd.Item().try_as<TerminalApp::PaletteItem>())
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ItemAdded,
Automation::Peers::AutomationNotificationProcessing::MostRecent,
paletteItem.Name() + L" " + paletteItem.KeyChordText(),
L"CommandPaletteSelectedItemChanged" /* unique name for this notification category */);
}
}
}
}
}
}

// Method Description:
// This event is called when the user clicks on a ChevronLeft button right
// next to the ParentCommandName (e.g. New Tab...) above the subcommands list.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace winrt::TerminalApp::implementation

void _listItemClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::ItemClickEventArgs& e);

void _listItemSelectionChanged(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& e);

void _moveBackButtonClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&);

void _updateFilteredActions();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/CommandPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
IsItemClickEnabled="True"
ItemClick="_listItemClicked"
ItemsSource="{x:Bind FilteredActions}"
SelectionChanged="_listItemSelectionChanged"
SelectionMode="Single" />

</Grid>
Expand Down

0 comments on commit deb5e7c

Please sign in to comment.