common: Fix parameter type of `autofocus` function.

Throughout the codebase there is currently one usage of `autofocus`
excepts in test files. The only one usage is in `signup.js` and was
supposed to pass a `JQuery` selector to `autofocus` rather than a
string. Passing a selector is more convenient in this case: The
selector accessed in `signup.js` is ready to `trigger` the `focus`
function, while getting a attirubte string from the selector and then
passing to `autofocus` and then accessing the selector by attribute
cost extra layers of work. Therefore writing this commit to simplify
the type for easy usage.

Fixes the test case(s) accordingly.
This commit is contained in:
Junyao Chen 2023-06-12 21:29:20 +00:00 committed by Tim Abbott
parent ae3458a294
commit c008ba1172
2 changed files with 3 additions and 3 deletions

View File

@ -7,9 +7,9 @@ import {$t} from "./i18n";
export const status_classes = "alert-error alert-success alert-info alert-warning alert-loading"; export const status_classes = "alert-error alert-success alert-info alert-warning alert-loading";
// TODO: Move this to the portico codebase. // TODO: Move this to the portico codebase.
export function autofocus(selector: string): void { export function autofocus($elem: JQuery): void {
$(() => { $(() => {
$(selector).trigger("focus"); $elem.trigger("focus");
}); });
} }

View File

@ -21,7 +21,7 @@ const navigator = set_global("navigator", {});
const common = zrequire("common"); const common = zrequire("common");
run_test("basics", () => { run_test("basics", () => {
common.autofocus("#home"); common.autofocus($("#home"));
$.get_initialize_function()(); $.get_initialize_function()();
assert.ok($("#home").is_focused()); assert.ok($("#home").is_focused());
$.clear_initialize_function(); $.clear_initialize_function();