Browse Source

caps-lock directive added

pull/16807/head
Masum ULU 3 years ago
parent
commit
a0df51dd23
  1. 30
      npm/ng-packs/packages/core/src/lib/directives/caps-lock.directive.ts
  2. 1
      npm/ng-packs/packages/core/src/lib/directives/index.ts

30
npm/ng-packs/packages/core/src/lib/directives/caps-lock.directive.ts

@ -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.capS(event));
}
@HostListener('window:keyup', ['$event'])
onKeyUp(event: KeyboardEvent): void {
this.capsLock.emit(this.capS(event));
}
capS(e) {
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;
}
}

1
npm/ng-packs/packages/core/src/lib/directives/index.ts

@ -7,3 +7,4 @@ export * from './permission.directive';
export * from './replaceable-template.directive';
export * from './stop-propagation.directive';
export * from './show-password.directive';
export * from './caps-lock.directive';

Loading…
Cancel
Save