Add autofocus to password prompt

This commit is contained in:
Chocobozzz 2023-11-23 08:54:03 +01:00
parent b13460a10a
commit 80efccf6c5
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 18 additions and 4 deletions

View File

@ -14,9 +14,16 @@
<div *ngIf="inputLabel" class="form-group mt-3"> <div *ngIf="inputLabel" class="form-group mt-3">
<label for="confirmInput">{{ inputLabel }}</label> <label for="confirmInput">{{ inputLabel }}</label>
<input *ngIf="!isPasswordInput" type="text" id="confirmInput" name="confirmInput" [(ngModel)]="inputValue" (keyup.enter)="confirm()" /> <input
*ngIf="!isPasswordInput" type="text"
myAutofocusid="confirmInput" name="confirmInput"
[(ngModel)]="inputValue" (keyup.enter)="confirm()"
/>
<my-input-text *ngIf="isPasswordInput" inputId="confirmInput" [(ngModel)]="inputValue" (keyup.enter)="confirm()"></my-input-text> <my-input-text
*ngIf="isPasswordInput" [autofocus]="true" autocomplete="on"
inputId="confirmInput" [(ngModel)]="inputValue" (keyup.enter)="confirm()"
></my-input-text>
</div> </div>
<div *ngIf="hasError()" class="text-danger">{{ errorMessage }}</div> <div *ngIf="hasError()" class="text-danger">{{ errorMessage }}</div>

View File

@ -1,4 +1,4 @@
import { Component, ElementRef, forwardRef, Input, ViewChild } from '@angular/core' import { AfterViewInit, Component, ElementRef, forwardRef, Input, ViewChild } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
import { FormReactiveErrors } from './form-reactive.service' import { FormReactiveErrors } from './form-reactive.service'
@ -14,7 +14,7 @@ import { FormReactiveErrors } from './form-reactive.service'
} }
] ]
}) })
export class InputTextComponent implements ControlValueAccessor { export class InputTextComponent implements ControlValueAccessor, AfterViewInit {
@ViewChild('input') inputElement: ElementRef @ViewChild('input') inputElement: ElementRef
@Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined
@ -27,6 +27,7 @@ export class InputTextComponent implements ControlValueAccessor {
@Input() readonly = false @Input() readonly = false
@Input() show = false @Input() show = false
@Input() formError: string | FormReactiveErrors | FormReactiveErrors[] @Input() formError: string | FormReactiveErrors | FormReactiveErrors[]
@Input() autofocus = false
get inputType () { get inputType () {
return this.show return this.show
@ -40,6 +41,12 @@ export class InputTextComponent implements ControlValueAccessor {
: $localize`Show` : $localize`Show`
} }
ngAfterViewInit () {
if (this.autofocus !== true) return
this.inputElement.nativeElement.focus({ preventScroll: true })
}
toggle () { toggle () {
this.show = !this.show this.show = !this.show
} }