Skip to content

Commit

Permalink
search: Use e.key instead of deprecated e.which.
Browse files Browse the repository at this point in the history
Tested by making sure Enter works and expected in the navbar search
with and without the typeahead being present.
  • Loading branch information
priyank-p authored and timabbott committed Jun 2, 2021
1 parent 607abc0 commit a218143
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
12 changes: 6 additions & 6 deletions frontend_tests/node_tests/search.js
Expand Up @@ -228,7 +228,7 @@ test("initialize", () => {
let default_prevented = false;
let ev = {
type: "keydown",
which: 15,
key: "a",
preventDefault() {
default_prevented = true;
},
Expand All @@ -237,11 +237,11 @@ test("initialize", () => {
assert.equal(keydown(ev), undefined);
assert(!default_prevented);

ev.which = 13;
ev.key = "Enter";
assert.equal(keydown(ev), undefined);
assert(!default_prevented);

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
Expand Down Expand Up @@ -288,14 +288,14 @@ test("initialize", () => {
assert(!is_blurred);
assert(!search_button.prop("disabled"));

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => false;
searchbox_form.trigger(ev);

assert(!is_blurred);
assert(!search_button.prop("disabled"));

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
Expand All @@ -308,7 +308,7 @@ test("initialize", () => {
assert(!search_button.prop("disabled"));

_setup("ver");
ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
Expand Down
12 changes: 6 additions & 6 deletions frontend_tests/node_tests/search_legacy.js
Expand Up @@ -192,11 +192,11 @@ run_test("initialize", () => {
assert.equal(keydown(ev), undefined);
assert(!default_prevented);

ev.which = 13;
ev.key = "Enter";
assert.equal(keydown(ev), undefined);
assert(!default_prevented);

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
Expand Down Expand Up @@ -235,21 +235,21 @@ run_test("initialize", () => {
];
_setup("");

ev.which = 15;
ev.key = "a";
search_query_box.is = () => false;
searchbox_form.trigger(ev);

assert(!is_blurred);
assert(!search_button.prop("disabled"));

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => false;
searchbox_form.trigger(ev);

assert(!is_blurred);
assert(!search_button.prop("disabled"));

ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
Expand All @@ -262,7 +262,7 @@ run_test("initialize", () => {
assert(!search_button.prop("disabled"));

_setup("ver");
ev.which = 13;
ev.key = "Enter";
search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
Expand Down
7 changes: 3 additions & 4 deletions static/js/search.js
Expand Up @@ -134,8 +134,7 @@ export function initialize() {
searchbox_form
.on("keydown", (e) => {
update_button_visibility();
const code = e.which;
if (code === 13 && search_query_box.is(":focus")) {
if (e.key === "Enter" && search_query_box.is(":focus")) {
// Don't submit the form so that the typeahead can instead
// handle our Enter keypress. Any searching that needs
// to be done will be handled in the keyup.
Expand All @@ -147,8 +146,8 @@ export function initialize() {
is_using_input_method = false;
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
// means we didn't use the typeahead at all. In that
// case, we should act as though we're searching by
Expand Down

0 comments on commit a218143

Please sign in to comment.