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

Toggleable password input #1159

Merged
merged 2 commits into from
Dec 11, 2023
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
8 changes: 8 additions & 0 deletions packages/frontend/src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ ion-menu.cookingToolbarOpen {
font-size: 40px;
}

.medium-icon {
font-size: 2em;
}

.eye-icon {
vertical-align: middle;
}

Comment on lines +33 to +40
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking] Would be nice for these styles not to sit in the global app.scss, but it looks like directives can't apply stylesheets directly. I do see some mention of directives supporting a host property here, though https://stackoverflow.com/a/35915497/21691840

ion-popover,
.alert-wrapper {
--width: 280px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Directive, ElementRef, Renderer2 } from "@angular/core";

@Directive({
selector: "[appToggleablePassword]",
})
export class ToggleablePasswordDirective {
private showPassword = false;
private eyeIcon!: HTMLElement;

constructor(
private el: ElementRef,
private renderer: Renderer2,
) {
this.setup();
}

setup() {
// Create the eye icon for showing/hiding password
this.eyeIcon = this.renderer.createElement("ion-icon");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed while testing that this needs cursor: pointer. For accessibility, it'd also be nice for this to be a button (which would solve the problem anyway). You could use the icon-only button here

this.renderer.addClass(this.eyeIcon, "medium-icon");
this.renderer.addClass(this.eyeIcon, "eye-icon");
this.renderer.setAttribute(this.eyeIcon, "name", "eye-off-outline");
this.renderer.listen(this.eyeIcon, "click", () => this.toggleShow());

// Append the eye icon next to the input field
this.renderer.appendChild(this.el.nativeElement.parentNode, this.eyeIcon);
}

toggleShow() {
this.showPassword = !this.showPassword;
const passwordInput = this.el.nativeElement;
passwordInput.type = this.showPassword ? "text" : "password";

const iconName = this.showPassword ? "eye-outline" : "eye-off-outline";
this.renderer.setAttribute(this.eyeIcon, "name", iconName);
}
}
3 changes: 2 additions & 1 deletion packages/frontend/src/app/pages/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { LogoIconModule } from "~/components/logo-icon/logo-icon.module";
import { TosClickwrapAgreementModule } from "~/components/tos-clickwrap-agreement/tos-clickwrap-agreement.module";

import { GlobalModule } from "~/global.module";
import { ToggleablePasswordDirective } from "../../directives/toggleable-password.directive";

@NgModule({
declarations: [AuthPage],
declarations: [AuthPage, ToggleablePasswordDirective],
imports: [
CommonModule,
IonicModule,
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/app/pages/auth/auth.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ <h2>{{ 'pages.auth.welcome.register' | translate }}</h2>
[(ngModel)]="password"
(keyup.enter)="showLogin && auth()"
type="password"
appToggleablePassword
/>
</label>
<br /><br />
Expand All @@ -76,6 +77,7 @@ <h2>{{ 'pages.auth.welcome.register' | translate }}</h2>
[(ngModel)]="confirmPassword"
(keyup.enter)="auth()"
type="password"
appToggleablePassword
/>
</label>
<br /><br />
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/app/pages/auth/auth.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
}

input {
width: 100%;
width: 90%;
background: none;
margin-right: 10px;
border: none;
border-bottom: 1px solid;
border-color: var(--ion-border-color);
Expand Down