search: Use e.key instead of deprecated e.which.

Tested by making sure Enter works and expected in the navbar search
with and without the typeahead being present.
This commit is contained in:
Priyank Patel
2021-05-31 16:38:57 +00:00
committed by Tim Abbott
parent 607abc0b77
commit a218143db7
3 changed files with 15 additions and 16 deletions

View File

@@ -228,7 +228,7 @@ test("initialize", () => {
let default_prevented = false; let default_prevented = false;
let ev = { let ev = {
type: "keydown", type: "keydown",
which: 15, key: "a",
preventDefault() { preventDefault() {
default_prevented = true; default_prevented = true;
}, },
@@ -237,11 +237,11 @@ test("initialize", () => {
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(!default_prevented); assert(!default_prevented);
ev.which = 13; ev.key = "Enter";
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(!default_prevented); assert(!default_prevented);
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(default_prevented); assert(default_prevented);
@@ -288,14 +288,14 @@ test("initialize", () => {
assert(!is_blurred); assert(!is_blurred);
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => false; search_query_box.is = () => false;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(!is_blurred); assert(!is_blurred);
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(is_blurred); assert(is_blurred);
@@ -308,7 +308,7 @@ test("initialize", () => {
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
_setup("ver"); _setup("ver");
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(is_blurred); assert(is_blurred);

View File

@@ -192,11 +192,11 @@ run_test("initialize", () => {
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(!default_prevented); assert(!default_prevented);
ev.which = 13; ev.key = "Enter";
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(!default_prevented); assert(!default_prevented);
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
assert.equal(keydown(ev), undefined); assert.equal(keydown(ev), undefined);
assert(default_prevented); assert(default_prevented);
@@ -235,21 +235,21 @@ run_test("initialize", () => {
]; ];
_setup(""); _setup("");
ev.which = 15; ev.key = "a";
search_query_box.is = () => false; search_query_box.is = () => false;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(!is_blurred); assert(!is_blurred);
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => false; search_query_box.is = () => false;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(!is_blurred); assert(!is_blurred);
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(is_blurred); assert(is_blurred);
@@ -262,7 +262,7 @@ run_test("initialize", () => {
assert(!search_button.prop("disabled")); assert(!search_button.prop("disabled"));
_setup("ver"); _setup("ver");
ev.which = 13; ev.key = "Enter";
search_query_box.is = () => true; search_query_box.is = () => true;
searchbox_form.trigger(ev); searchbox_form.trigger(ev);
assert(is_blurred); assert(is_blurred);

View File

@@ -134,8 +134,7 @@ export function initialize() {
searchbox_form searchbox_form
.on("keydown", (e) => { .on("keydown", (e) => {
update_button_visibility(); update_button_visibility();
const code = e.which; if (e.key === "Enter" && search_query_box.is(":focus")) {
if (code === 13 && search_query_box.is(":focus")) {
// Don't submit the form so that the typeahead can instead // Don't submit the form so that the typeahead can instead
// handle our Enter keypress. Any searching that needs // handle our Enter keypress. Any searching that needs
// to be done will be handled in the keyup. // to be done will be handled in the keyup.
@@ -147,8 +146,8 @@ export function initialize() {
is_using_input_method = false; is_using_input_method = false;
return; return;
} }
const code = e.which;
if (code === 13 && search_query_box.is(":focus")) { if (e.key === "Enter" && search_query_box.is(":focus")) {
// We just pressed Enter and the box had focus, which // We just pressed Enter and the box had focus, which
// means we didn't use the typeahead at all. In that // means we didn't use the typeahead at all. In that
// case, we should act as though we're searching by // case, we should act as though we're searching by