From ddde977a0a485f327a041bedb0d7b249df4770bf Mon Sep 17 00:00:00 2001 From: Fabi <192151969+fabske0@users.noreply.github.com> Date: Thu, 4 Sep 2025 11:31:52 +0200 Subject: [PATCH] [UI/UX] Auto focus first input field (#6413) --- src/ui/form-modal-ui-handler.ts | 5 +++++ src/ui/pokedex-scan-ui-handler.ts | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/form-modal-ui-handler.ts b/src/ui/form-modal-ui-handler.ts index 5c547465de9..c6ef8705aa8 100644 --- a/src/ui/form-modal-ui-handler.ts +++ b/src/ui/form-modal-ui-handler.ts @@ -136,6 +136,11 @@ export abstract class FormModalUiHandler extends ModalUiHandler { this.submitAction = config.buttonActions.length ? config.buttonActions[0] : null; this.cancelAction = config.buttonActions[1] ?? null; + // Auto focus the first input field after a short delay, to prevent accidental inputs + setTimeout(() => { + this.inputs[0].setFocus(); + }, 50); + // #region: Override button pointerDown // Override the pointerDown event for the buttonBgs to call the `submitAction` and `cancelAction` // properties that we set above, allowing their behavior to change after this method terminates diff --git a/src/ui/pokedex-scan-ui-handler.ts b/src/ui/pokedex-scan-ui-handler.ts index 4f606cbcbb0..9be7a903dec 100644 --- a/src/ui/pokedex-scan-ui-handler.ts +++ b/src/ui/pokedex-scan-ui-handler.ts @@ -106,10 +106,6 @@ export class PokedexScanUiHandler extends FormModalUiHandler { this.reduceKeys(); - setTimeout(() => { - input.setFocus(); // Focus after a short delay to avoid unwanted input - }, 50); - input.on("keydown", (inputObject, evt: KeyboardEvent) => { if ( ["escape", "space"].some(v => v === evt.key.toLowerCase() || v === evt.code.toLowerCase()) &&