Home

Awesome

ngx-show-hide-password

Add split input button to password or text input. Toggles input type between "text" and "password".

Build Status npm version codecov

Installation

For an upt-to-date angular project version 16 with standalone Componentents:

npm install ngx-show-hide-password --save
npm install @fortawesome/angular-fontawesome \
    @fortawesome/fontawesome-svg-core \
    @fortawesome/free-solid-svg-icons --save

For angular project version 15 and Bootstrap 5:

npm install ngx-show-hide-password@2.6.5 --save
npm install @fortawesome/angular-fontawesome \
    @fortawesome/fontawesome-svg-core \
    @fortawesome/free-solid-svg-icons --save

:exclamation: For previous Angular releases please check the compatibility table of ngx-show-hide-password and @fortawesome/angular-fontawesome!

:white_check_mark: e.g. for angular version 8:

npm install ngx-show-hide-password@~2.1.0 --save
npm install @fortawesome/angular-fontawesome@^0.5 \
    @fortawesome/fontawesome-svg-core \
    @fortawesome/free-solid-svg-icons --save

Integration

with standalone components:

// nothing to do in main.ts

...
// component.ts
import {
  ShowHidePasswordComponent,
  ShowHideInputDirective,
  ShowHideStatusDirective,
  ShowHideTriggerDirective,
} from 'ngx-show-hide-password';

@Component({
  ...
  standalone: true,
  imports: [
    ShowHidePasswordComponent,
    ShowHideInputDirective,
    ShowHideStatusDirective,
    ShowHideTriggerDirective,
  ],
})
export class AppComponent {
  constructor(private showHideService: ShowHideService) {
    ...
    effect(() => {
      const show = this.showHideService.getSignal('password')();
      ...
    });
  }
}

as module (angular pre v16 and ngx-show-hide-password pre v2.7.0):

// app.module.ts
import { ShowHidePasswordModule } from 'ngx-show-hide-password';
// no need to import @fortawesome/angular-fontawesome for the component
...
@NgModule({
  ...
  imports: [
    BrowserModule,
    ShowHidePasswordModule,
    ...
  ],
  ...
})

template as component ...

<show-hide-password size="lg" btnStyle="primary" [btnOutline]="false">
  <input type="password" name="..." >
</show-hide-password>

or template with directives ...

<mat-form-field>
  <input id="mysecretpassword" type="password" placeholder="Password" matInput showHideInput>
  <i matSuffix
    class="material-icons"
    showHideTrigger="mysecretpassword"
    [showHideStatus]="{ materialIcon: true, id: 'mysecretpassword' }"
  ></i>
</mat-form-field>
Password hiddenPassword exposed
Hidden passwordExposed password

How to customize and some examples how to use the directives & service

Documentation

Component: show-hide-password

Demo on stackblitz

attributetypedescription
btnOutlinebooleandefault: true
btnStylestring'primary', 'secondary', 'success', 'warning', 'danger' or 'info'. default: 'secondary'
sizestring'sm', 'lg'. default: nothing.

Directive: showHideInput

Demo on stackblitz

:information_source: All directives (and the service) are bound to the same unique id. This can be the attribute id of the HTML input element or you can enter a synthetic ID.

attributetypedescription
idstringunique id.

Directive: showHideTrigger

typedescription
stringunique id. * required

Directive: showHideStatus

export interface ShowHideStatusConfig {
  id: string;
  show?: string;
  hide?: string;
  materialIcon?: boolean;
}
attributetypedescription
idstringunique id. * required
showstringoptional class/material icon identifier. default: 'visibility'
hidestringoptional class/material icon identifier. default: 'visibility_off'
materialIconbooleanif true updates innerHTML instead of class attribute. default: false

Service: ShowHideService

return Signal for input with id

getSignal(id: string): WritableSignal<boolean>

set Status for input with id

setShow(id: string, show: boolean): void

toggles Status for input with id

toggleShow(id: string): void

Release History

compatibility chart

local versionangular versionBootstrap versionstandalone
@^2.7.4v18v5
@^2.7.2v17v5
@^2.7.0v16v5
@^2.6.5v15v5
@^2.6.4v14v5
@^2.6.1v13v5
@^2.4.0v13v4
@^2.3.1v11
@^2.3.0v10
@^2.2.3v9
@~2.1.0v8
@~2.0.3v7
@~1.2.5v5 and v6
@~1.1.0v4

:exclamation: The Bootstrap version is only important if you use the show-hide-password Component.

Rename local master branch to main

git branch -m master main
git fetch origin
git branch -u origin/main main

LICENCE

MIT © Oliver Sahner