mirror of https://github.com/abpframework/abp
Merge pull request #16807 from abpframework/masum/password-directive
AngularUI: Password & CapsLock directive createdpull/16816/head
commit
a9b180b4b3
@ -0,0 +1,30 @@
|
||||
import { Directive, EventEmitter, HostListener, Output } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
standalone: true,
|
||||
selector: '[abpCapsLock]',
|
||||
})
|
||||
export class TrackCapsLockDirective {
|
||||
@Output('abpCapsLock') capsLock = new EventEmitter<Boolean>();
|
||||
|
||||
@HostListener('window:keydown', ['$event'])
|
||||
onKeyDown(event: KeyboardEvent): void {
|
||||
this.capsLock.emit(this.isCapsLockOpen(event));
|
||||
}
|
||||
@HostListener('window:keyup', ['$event'])
|
||||
onKeyUp(event: KeyboardEvent): void {
|
||||
this.capsLock.emit(this.isCapsLockOpen(event));
|
||||
}
|
||||
|
||||
isCapsLockOpen(e): boolean {
|
||||
var s = String.fromCharCode(e.which);
|
||||
if (
|
||||
(s.toUpperCase() === s && s.toLowerCase() !== s && e.shiftKey) ||
|
||||
(s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey) ||
|
||||
e.getModifierState('CapsLock')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import { Directive, ElementRef, Input, inject } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
standalone: true,
|
||||
selector: '[abpShowPassword]',
|
||||
})
|
||||
export class ShowPasswordDirective {
|
||||
protected readonly elementRef = inject(ElementRef);
|
||||
|
||||
@Input() set abpShowPassword(visible: boolean) {
|
||||
const element = this.elementRef.nativeElement as HTMLInputElement;
|
||||
if (!element) return;
|
||||
|
||||
element.type = visible ? 'text' : 'password';
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue