Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(a11y): clr-password-container show/hide Icon does not have unique label #1179

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/angular/clarity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2923,8 +2923,12 @@ export class ClrPasswordContainer extends ClrAbstractContainer {
// (undocumented)
focusService: FocusService_2;
// (undocumented)
hidePasswordText(label: string): string;
// (undocumented)
show: boolean;
// (undocumented)
showPasswordText(label: string): string;
// (undocumented)
toggle(): void;
// (undocumented)
static ɵcmp: i0.ɵɵComponentDeclaration<ClrPasswordContainer, "clr-password-container", never, { "clrToggle": "clrToggle"; }, {}, never, ["label", "[clrPassword]", "clr-control-helper", "clr-control-error", "clr-control-success"], false, never>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export default function (): void {

it('should provide screen-reader only text for toggle button', () => {
const button: HTMLButtonElement = containerEl.querySelector('button');
expect(button.textContent.trim()).toEqual('Show password');
expect(button.textContent.trim()).toEqual('Show password for Hello World');
button.click();
fixture.detectChanges();
expect(button.textContent.trim()).toEqual('Hide password');
expect(button.textContent.trim()).toEqual('Hide password for Hello World');
});
});
});
Expand Down
10 changes: 9 additions & 1 deletion projects/angular/src/forms/password/password-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const TOGGLE_SERVICE_PROVIDER = { provide: TOGGLE_SERVICE, useFactory: To
>
<cds-icon status="info" class="clr-password-eye-icon" [attr.shape]="show ? 'eye-hide' : 'eye'"></cds-icon>
<span class="clr-sr-only">
{{ show ? commonStrings.keys.passwordHide : commonStrings.keys.passwordShow }}
{{ show ? hidePasswordText(label?.labelText) : showPasswordText(label?.labelText) }}
</span>
</button>
</div>
Expand Down Expand Up @@ -118,4 +118,12 @@ export class ClrPasswordContainer extends ClrAbstractContainer {
this.show = !this.show;
this.toggleService.next(this.show);
}

showPasswordText(label: string) {
return this.commonStrings.parse(this.commonStrings.keys.passwordShow, { LABEL: label });
}

hidePasswordText(label: string) {
return this.commonStrings.parse(this.commonStrings.keys.passwordHide, { LABEL: label });
}
}
4 changes: 2 additions & 2 deletions projects/angular/src/utils/i18n/common-strings.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export const commonStringsDefault: ClrCommonStrings = {
* Password Input
* Screen-reader text for the hide/show password field button
*/
passwordHide: 'Hide password',
passwordShow: 'Show password',
passwordHide: 'Hide password for {LABEL}',
passwordShow: 'Show password for {LABEL}',

/**
* Datagrid footer; sr-only text after the number of selected rows.
Expand Down
Loading