Skip to content

Commit abbb027

Browse files
Make MSearchSelect (aka loop button selection of search type) keyboard accessible.
1 parent 7128df4 commit abbb027

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/htmlgen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ static void writeClientSearchBox(TextStream &t,const QCString &relPath)
7575
{
7676
t << " <div id=\"MSearchBox\" class=\"MSearchBoxInactive\">\n";
7777
t << " <span class=\"left\">\n";
78-
t << " <span id=\"MSearchSelect\" ";
78+
t << " <span id=\"MSearchSelect\" tabindex=\"0\" ";
7979
t << " onmouseover=\"return searchBox.OnSearchSelectShow()\" ";
80+
t << " onclick=\"return searchBox.OnSearchSelectShow()\" ";
8081
t << " onmouseout=\"return searchBox.OnSearchSelectHide()\">&#160;</span>\n";
8182
t << " <input type=\"text\" id=\"MSearchField\" value=\"\" placeholder=\""
8283
<< theTranslator->trSearch() << "\" accesskey=\"S\"\n";
@@ -1436,7 +1437,7 @@ void HtmlGenerator::writeSearchInfoStatic(TextStream &t,const QCString &)
14361437
if (searchEngine && !serverBasedSearch)
14371438
{
14381439
t << "<!-- window showing the filter options -->\n";
1439-
t << "<div id=\"MSearchSelectWindow\"\n";
1440+
t << "<div id=\"MSearchSelectWindow\" tabindex=\"0\"\n";
14401441
t << " onmouseover=\"return searchBox.OnSearchSelectShow()\"\n";
14411442
t << " onmouseout=\"return searchBox.OnSearchSelectHide()\"\n";
14421443
t << " onkeydown=\"return searchBox.OnSearchSelectKey(event)\">\n";

templates/html/htmlbase.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ $(document).ready(function(){initNavTree('{{ page.fileName }}{% if page_postfix
217217
{% block searchInfo %}
218218
{% if config.SEARCHENGINE and not config.SERVER_BASED_SEARCH %}
219219
<!-- window showing the filter options -->
220-
<div id="MSearchSelectWindow"
220+
<div id="MSearchSelectWindow tabindex="0""
221221
onmouseover="return searchBox.OnSearchSelectShow()"
222222
onmouseout="return searchBox.OnSearchSelectHide()"
223223
onkeydown="return searchBox.OnSearchSelectKey(event)">

templates/html/search.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function SearchBox(name, resultsPath, extension)
9999
this.searchIndex = 0;
100100
this.searchActive = false;
101101
this.extension = extension;
102+
this.ignoreNextEscKeyUp = false;
102103

103104
// ----------- DOM Elements
104105

@@ -196,6 +197,11 @@ function SearchBox(name, resultsPath, extension)
196197
else if (e.keyCode==27) // Escape out of the search field
197198
{
198199
e.stopPropagation();
200+
if (this.ignoreNextEscKeyUp)
201+
{
202+
this.ignoreNextEscKeyUp = false;
203+
return;
204+
}
199205
this.DOMSearchField().blur();
200206
this.DOMPopupSearchResultsWindow().style.display = 'none';
201207
this.DOMSearchClose().style.display = 'none';
@@ -291,6 +297,10 @@ function SearchBox(name, resultsPath, extension)
291297
else if (e.keyCode==13 || e.keyCode==27)
292298
{
293299
e.stopPropagation();
300+
if (e.keyCode==27)
301+
{
302+
this.ignoreNextEscKeyUp = true;
303+
}
294304
this.OnSelectItem(this.searchIndex);
295305
this.CloseSelectionWindow();
296306
this.DOMSearchField().focus();
@@ -304,6 +314,7 @@ function SearchBox(name, resultsPath, extension)
304314
this.CloseResultsWindow = function()
305315
{
306316
this.DOMPopupSearchResultsWindow().style.display = 'none';
317+
this.DOMPopupSearchResultsWindow().style.tabindex = '-1';
307318
this.DOMSearchClose().style.display = 'none';
308319
this.Activate(false);
309320
}
@@ -820,5 +831,22 @@ function init_search()
820831
results.appendChild(link);
821832
}
822833
searchBox.OnSelectItem(0);
834+
835+
836+
var input = document.getElementById("MSearchSelect");
837+
var searchSelectWindow = document.getElementById("MSearchSelectWindow");
838+
839+
input.addEventListener("keypress", function(event) {
840+
if (event.key === "Enter") {
841+
event.preventDefault();
842+
if (searchSelectWindow.style.display == 'block') {
843+
this.CloseSelectionWindow();
844+
this.DOMSearchField().focus();
845+
} else {
846+
searchBox.OnSearchSelectShow();
847+
searchSelectWindow.focus();
848+
}
849+
}
850+
});
823851
}
824852
/* @license-end */

0 commit comments

Comments
 (0)