mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-11 18:04:27 +08:00
refactor(animated modal): focus input if it exists and its not hidden
This commit is contained in:
parent
54237d369e
commit
f47340b301
1 changed files with 13 additions and 6 deletions
|
|
@ -158,12 +158,19 @@ export default class AnimatedModal {
|
|||
}
|
||||
|
||||
focusFirstInput(setting: true | "focusAndSelect" | undefined): void {
|
||||
if (setting === true) {
|
||||
this.modalEl.querySelector("input")?.focus();
|
||||
} else if (setting === "focusAndSelect") {
|
||||
const input = this.modalEl.querySelector("input") as HTMLInputElement;
|
||||
input.focus();
|
||||
input.select();
|
||||
const input = this.modalEl.querySelector("input");
|
||||
if (input !== null) {
|
||||
const isHidden = input.classList.contains("hidden");
|
||||
if (isHidden) {
|
||||
this.wrapperEl.focus();
|
||||
} else {
|
||||
if (setting === true) {
|
||||
input.focus();
|
||||
} else if (setting === "focusAndSelect") {
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.wrapperEl.focus();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue