1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00
Files
browser/libs/components/src/form-field/password-input-toggle.directive.ts
Shane Melton f75c1ab02d [PM-8524] Cipher Form - Edit Login Details Section (#10081)
* [PM-8524] Introduce login details section component

* [PM-8524] Add ability to remove passkey

* [PM-8524] Introduce TotpCaptureService and the Browser implementation

* [PM-8524] Tweak storybook

* [PM-8524] Add note regarding existing login view references

* [PM-8524] Fix clone mode so that a new cipher is created

* [PM-8524] Add support for generating usernames/passwords and auditing passwords

* [PM-8524] Migrate password/username generation to CipherFormGenerationService

* [PM-8524] Add optional passwordInput to BitPasswordInputToggle to support conditionally rendered password toggle buttons

* [PM-8524] Add LoginDetailsSection tests

* [PM-8524] Add BrowserTotpCaptureService tests

* Revert "[PM-8524] Add optional passwordInput to BitPasswordInputToggle to support conditionally rendered password toggle buttons"

This reverts commit e76a0ccfe8.

* [PM-8524] Add null check to password input toggle
2024-07-18 09:38:55 -07:00

73 lines
1.8 KiB
TypeScript

import {
AfterContentInit,
Directive,
EventEmitter,
Host,
HostBinding,
HostListener,
Input,
OnChanges,
Output,
} from "@angular/core";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { BitIconButtonComponent } from "../icon-button/icon-button.component";
import { BitFormFieldComponent } from "./form-field.component";
@Directive({
selector: "[bitPasswordInputToggle]",
})
export class BitPasswordInputToggleDirective implements AfterContentInit, OnChanges {
/**
* Whether the input is toggled to show the password.
*/
@HostBinding("attr.aria-pressed") @Input() toggled = false;
@Output() toggledChange = new EventEmitter<boolean>();
@HostBinding("attr.title") title = this.i18nService.t("toggleVisibility");
@HostBinding("attr.aria-label") label = this.i18nService.t("toggleVisibility");
/**
* Click handler to toggle the state of the input type.
*/
@HostListener("click") onClick() {
this.toggled = !this.toggled;
this.toggledChange.emit(this.toggled);
this.update();
this.formField.input?.focus();
}
constructor(
@Host() private button: BitIconButtonComponent,
private formField: BitFormFieldComponent,
private i18nService: I18nService,
) {}
get icon() {
return this.toggled ? "bwi-eye-slash" : "bwi-eye";
}
ngOnChanges(): void {
this.update();
}
ngAfterContentInit(): void {
if (this.formField.input?.type) {
this.toggled = this.formField.input.type !== "password";
}
this.button.icon = this.icon;
}
private update() {
this.button.icon = this.icon;
if (this.formField.input?.type != null) {
this.formField.input.type = this.toggled ? "text" : "password";
this.formField.input.spellcheck = this.toggled ? false : undefined;
}
}
}