A11Y: Return focus to header search button upon escape of search (#18656)

This commit is contained in:
Keegan George
2022-10-18 15:01:09 -07:00
committed by GitHub
parent 799fa8d6f9
commit a8af510636
2 changed files with 7 additions and 1 deletions

View File

@@ -356,8 +356,9 @@ export default createWidget("search-menu", {
},
keyDown(e) {
if (e.which === 27 /* escape */) {
if (e.key === "Escape") {
this.sendWidgetAction("toggleSearchMenu");
document.querySelector("#search-button").focus();
e.preventDefault();
return false;
}

View File

@@ -450,6 +450,11 @@ acceptance("Search - Authenticated", function (needs) {
);
await triggerKeyEvent(".search-menu", "keydown", "Escape");
assert.strictEqual(
document.activeElement,
query("#search-button"),
"Escaping search returns focus to search button"
);
assert.ok(!exists(".search-menu:visible"), "Esc removes search dropdown");
await click("#search-button");