Starts in:
3 DAYS
9 HRS
30 MIN
28 SEC
Starts in:
3 D
9 H
30 M
28 S

Caps Lock Directive

In password inputs, You may want to show if Caps Lock is on. To make this even easier, you can use the TrackCapsLockDirective which has been exposed by the @abp/ng.core package.

Getting Started

TrackCapsLockDirective is standalone. In order to use the TrackCapsLockDirective in an HTML template, import it to related module or your standalone component:

Importing to NgModule

import { TrackCapsLockDirective } from '@abp/ng.core';

@NgModule({
  //...
  declarations: [
   ...,
   TestComponent
  ],
  imports: [
   ...,
   TrackCapsLockDirective
  ],
})
export class MyFeatureModule {}

Usage

The TrackCapsLockDirective is very easy to use. The directive's selector is abpCapsLock. By adding the abpCapsLock event to an element, you can track the status of Caps Lock. You can use this to warn user.

See an example usage:

NgModule Component usage

@Component({
  selector: 'test-component',
  template: `
    <div class="d-flex flex-column">
      <label>Password</label>
      <input (abpCapsLock)="capsLock = $event"/>
      <i *ngIf="capsLock">icon</i>
    </div>
  `
})
export class TestComponent{
  capsLock = false;
}

Standalone Component usage

import { TrackCapsLockDirective } from '@abp/ng.core'

@Component({
  selector: 'standalone-component',
  standalone: true,
  template: `
    <div class="d-flex flex-column">
      <label>Password</label>
      <input (abpCapsLock)="capsLock = $event"/>
      <i *ngIf="capsLock">icon</i>
    </div>
  `,
  imports: [TrackCapsLockDirective]
})
export class StandaloneComponent{
  capsLock = false;
}

The abpCapsLock event has been added to the <input> element. Press Caps Lock to activate the TrackCapsLockDirective.

See the result:

Show Password directive

To see Caps Lock icon press Caps Lock.

Show Password directive

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Register Now
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More