diff --git a/libs/components/src/color-password/color-password.component.ts b/libs/components/src/color-password/color-password.component.ts index 4fc94e4185..86ccb41ba3 100644 --- a/libs/components/src/color-password/color-password.component.ts +++ b/libs/components/src/color-password/color-password.component.ts @@ -1,7 +1,4 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore - -import { Component, HostBinding, Input } from "@angular/core"; +import { Component, computed, HostBinding, input } from "@angular/core"; import { Utils } from "@bitwarden/common/platform/misc/utils"; @@ -14,10 +11,10 @@ enum CharacterType { @Component({ selector: "bit-color-password", - template: `@for (character of passwordArray; track character; let i = $index) { + template: `@for (character of passwordCharArray(); track $index; let i = $index) { {{ character }} - @if (showCount) { + @if (showCount()) { {{ i + 1 }} } @@ -25,8 +22,13 @@ enum CharacterType { standalone: true, }) export class ColorPasswordComponent { - @Input() password: string = null; - @Input() showCount = false; + password = input(""); + showCount = input(false); + + // Convert to an array to handle cases that strings have special characters, i.e.: emoji. + passwordCharArray = computed(() => { + return Array.from(this.password() ?? ""); + }); characterStyles: Record = { [CharacterType.Emoji]: [], @@ -40,16 +42,11 @@ export class ColorPasswordComponent { return ["tw-min-w-0", "tw-whitespace-pre-wrap", "tw-break-all"]; } - get passwordArray() { - // Convert to an array to handle cases that strings have special characters, i.e.: emoji. - return Array.from(this.password); - } - getCharacterClass(character: string) { const charType = this.getCharacterType(character); const charClass = this.characterStyles[charType]; - if (this.showCount) { + if (this.showCount()) { return charClass.concat([ "tw-inline-flex", "tw-flex-col", diff --git a/libs/vault/src/cipher-view/login-credentials/login-credentials-view.component.spec.ts b/libs/vault/src/cipher-view/login-credentials/login-credentials-view.component.spec.ts index 02b96f10f1..0b5c4b246e 100644 --- a/libs/vault/src/cipher-view/login-credentials/login-credentials-view.component.spec.ts +++ b/libs/vault/src/cipher-view/login-credentials/login-credentials-view.component.spec.ts @@ -168,7 +168,7 @@ describe("LoginCredentialsViewComponent", () => { const passwordColor = passwordField.query(By.directive(ColorPasswordComponent)); - expect(passwordColor.componentInstance.password).toBe(cipher.login.password); + expect(passwordColor.componentInstance.password()).toBe(cipher.login.password); }); it("records event", () => { diff --git a/libs/vault/src/components/password-history-view/password-history-view.component.spec.ts b/libs/vault/src/components/password-history-view/password-history-view.component.spec.ts index b9f83ea217..c535847f7b 100644 --- a/libs/vault/src/components/password-history-view/password-history-view.component.spec.ts +++ b/libs/vault/src/components/password-history-view/password-history-view.component.spec.ts @@ -68,7 +68,7 @@ describe("PasswordHistoryViewComponent", () => { it("renders all passwords", () => { const passwords = fixture.debugElement.queryAll(By.directive(ColorPasswordComponent)); - expect(passwords.map((password) => password.componentInstance.password)).toEqual([ + expect(passwords.map((password) => password.componentInstance.password())).toEqual([ "bad-password-1", "bad-password-2", ]);