Allow opening wxSearchCtrl menu from keyboard with Alt-Down

The search menu could only be opened by clicking the button showing it,
which doesn't accept focus from the keyboard on purpose, so keyboard and
screen reader users couldn't use it at all.

Handle Alt-Down in the text part of the control and show the menu from
there, as suggested in the comments of the original ticket.

Fixes #18457.

Closes #27093.
This commit is contained in:
Quin Gillespie
2026-09-27 01:48:55 +02:00
committed by Vadim Zeitlin
parent d54b211e26
commit 00ee56c01d
3 changed files with 24 additions and 0 deletions
+1
View File
@@ -169,6 +169,7 @@ protected:
private:
friend class wxSearchButton;
friend class wxSearchTextCtrl;
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
// Implement wxMSW-specific pure virtual function by forwarding it to the
+3
View File
@@ -139,6 +139,9 @@ public:
Sets the search control's menu object.
If there is already a menu associated with the search control it is deleted.
In the ports using the generic implementation of this control, e.g.
wxMSW, the menu can be opened from the keyboard using Alt-Down.
@param menu
Menu to attach to the search control.
*/
+20
View File
@@ -81,6 +81,23 @@ protected:
m_search->GetEventHandler()->ProcessEvent(event);
}
#if wxUSE_MENUS
void OnKeyDown(wxKeyEvent& event)
{
// Alt-Down is the usual way of opening a drop-down menu and the only
// way of opening the search menu from the keyboard, as the button
// showing it doesn't accept focus.
if ( event.GetKeyCode() == WXK_DOWN && event.AltDown() &&
m_search->HasMenu() )
{
m_search->PopupSearchMenu();
return;
}
event.Skip();
}
#endif // wxUSE_MENUS
void OnTextEnter(wxCommandEvent& WXUNUSED(event))
{
if ( !IsEmpty() )
@@ -135,6 +152,9 @@ private:
};
wxBEGIN_EVENT_TABLE(wxSearchTextCtrl, wxTextCtrl)
#if wxUSE_MENUS
EVT_KEY_DOWN(wxSearchTextCtrl::OnKeyDown)
#endif // wxUSE_MENUS
EVT_TEXT(wxID_ANY, wxSearchTextCtrl::OnText)
EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnTextEnter)
EVT_TEXT_MAXLEN(wxID_ANY, wxSearchTextCtrl::OnText)