user_status: Trigger input focus once the modal is shown.

Previously, once the user opens the "Set user status" UI,
the focus isn't automatically set to the input bar.

This is so because the input field isn't visible at
the time when UI is loaded because of the bootstrap
fade property which delays the event.

Added a fix to trigger the focus event on input bar
only when the modal is completely shown.

Fixes #19417.
This commit is contained in:
aryanshridhar 2021-07-29 15:16:21 +05:30 committed by Tim Abbott
parent 94b872828b
commit 3443f62d9a
1 changed files with 5 additions and 1 deletions

View File

@ -41,7 +41,6 @@ export function open_user_status_modal() {
const field = input_field(); const field = input_field();
field.val(old_status_text); field.val(old_status_text);
field.trigger("select"); field.trigger("select");
field.trigger("focus");
toggle_clear_message_button(); toggle_clear_message_button();
const button = submit_button(); const button = submit_button();
@ -167,6 +166,11 @@ export function initialize() {
submit_new_status(); submit_new_status();
}); });
$("body").on("shown.bs.modal", "#set_user_status_modal", () => {
const field = input_field();
field.trigger("focus");
});
$("body").on("keypress", "#set_user_status_modal .user_status", (event) => { $("body").on("keypress", "#set_user_status_modal .user_status", (event) => {
if (event.key === "Enter") { if (event.key === "Enter") {
event.preventDefault(); event.preventDefault();