From 5258149a34418a4cae9731433fc56dc5ef772ddc Mon Sep 17 00:00:00 2001 From: sua yoo Date: Sat, 8 Jan 2022 14:28:54 -0800 Subject: [PATCH] Fix password autocomplete and suggestions (#73) closes #72 --- frontend/src/components/index.ts | 2 + frontend/src/components/input/input.css | 52 ++++++++++++++++ frontend/src/components/input/input.ts | 81 +++++++++++++++++++++++++ frontend/src/components/sign-up-form.ts | 14 ++--- frontend/src/pages/log-in.ts | 32 +++++++--- frontend/src/pages/reset-password.ts | 6 +- 6 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 frontend/src/components/input/input.css create mode 100644 frontend/src/components/input/input.ts diff --git a/frontend/src/components/index.ts b/frontend/src/components/index.ts index 5b7127b5..d65e13e1 100644 --- a/frontend/src/components/index.ts +++ b/frontend/src/components/index.ts @@ -1,4 +1,5 @@ import { Alert } from "./alert"; +import { Input } from "./input/input"; import("./locale-picker").then(({ LocalePicker }) => { customElements.define("btrix-locale-picker", LocalePicker); }); @@ -19,3 +20,4 @@ import("./not-found").then(({ NotFound }) => { }); customElements.define("btrix-alert", Alert); +customElements.define("btrix-input", Input); diff --git a/frontend/src/components/input/input.css b/frontend/src/components/input/input.css new file mode 100644 index 00000000..c58ff03d --- /dev/null +++ b/frontend/src/components/input/input.css @@ -0,0 +1,52 @@ +.sl-label { + font-size: var(--sl-input-label-font-size-medium); + margin-bottom: var(--sl-spacing-3x-small); +} + +.sl-input-wrapper { + position: relative; + font-size: var(--sl-input-font-size-medium); + height: var(--sl-input-height-medium); +} + +.sl-input { + width: 100%; + font-family: inherit; + font-size: inherit; + font-weight: inherit; + min-width: 0; + height: calc( + var(--sl-input-height-medium) - var(--sl-input-border-width) * 2 + ); + color: var(--sl-input-color); + background-color: var(--sl-input-background-color); + border: solid var(--sl-input-border-width) var(--sl-input-border-color); + border-radius: var(--sl-input-border-radius-medium); + box-shadow: none; + padding: var(--sl-input-spacing-medium); + cursor: inherit; + -webkit-appearance: none; + transition: var(--sl-transition-fast) border, + var(--sl-transition-fast) box-shadow, + var(--sl-transition-fast) background-color; +} + +.sl-input:hover { + border-color: var(--sl-input-border-color-hover); +} + +.sl-input:focus { + border-color: var(--sl-input-border-color-focus); + box-shadow: var(--sl-focus-ring); +} + +.sl-input:not(:only-child) { + padding-right: calc(var(--sl-spacing-x-small) * 2 + 2em); +} + +.sl-input-icon-button { + position: absolute; + top: calc(var(--sl-input-border-width) + var(--sl-spacing-3x-small)); + right: 0; + margin-right: var(--sl-spacing-x-small); +} diff --git a/frontend/src/components/input/input.ts b/frontend/src/components/input/input.ts new file mode 100644 index 00000000..ba5d59ba --- /dev/null +++ b/frontend/src/components/input/input.ts @@ -0,0 +1,81 @@ +import { html } from "lit"; +import { property, state } from "lit/decorators.js"; +import { ifDefined } from "lit/directives/if-defined.js"; + +import LiteElement from "../../utils/LiteElement"; +import "./input.css"; + +/** + * Styled input element in the light DOM. + * Use instead of `sl-input` when disabling shadow DOM is necessary + * (e.g. for password manager autocomplete) + * See https://github.com/ikreymer/browsertrix-cloud/issues/72 + * and https://github.com/shoelace-style/shoelace/issues/413 + * + * Usage example: + * ```ts + * + * ``` + */ +export class Input extends LiteElement { + @property() + label?: string; + + @property({ type: String }) + id: string = ""; + + @property({ type: String }) + name?: string; + + @property({ type: String }) + type?: string; + + @property({ type: String }) + placeholder?: string; + + @property() + autocomplete?: any; + + @property() + required?: any; + + @property({ type: Boolean }) + togglePassword?: boolean; + + @state() + isPasswordVisible: boolean = false; + + render() { + return html` +
+ +
+
+ + ${this.togglePassword + ? html` + + ` + : ""} +
+ `; + } + + private onTogglePassword() { + this.isPasswordVisible = !this.isPasswordVisible; + } +} diff --git a/frontend/src/components/sign-up-form.ts b/frontend/src/components/sign-up-form.ts index 6151c8d3..f66c8e3e 100644 --- a/frontend/src/components/sign-up-form.ts +++ b/frontend/src/components/sign-up-form.ts @@ -62,7 +62,7 @@ export class SignUpForm extends LiteElement { /> ` : html` - - + `}
- - +
- - +

${msg("(optional)")} ${msg( "Your name will be visible to archive collaborators." diff --git a/frontend/src/pages/log-in.ts b/frontend/src/pages/log-in.ts index b016ccea..fc39b5fc 100644 --- a/frontend/src/pages/log-in.ts +++ b/frontend/src/pages/log-in.ts @@ -224,28 +224,43 @@ export class LogInPage extends LiteElement { } return html` +

- - +
- - +
${formError} @@ -280,14 +295,15 @@ export class LogInPage extends LiteElement { aria-describedby="formError" >
- - +
${formError} diff --git a/frontend/src/pages/reset-password.ts b/frontend/src/pages/reset-password.ts index f4252c6f..53ad9b49 100644 --- a/frontend/src/pages/reset-password.ts +++ b/frontend/src/pages/reset-password.ts @@ -33,16 +33,16 @@ export class ResetPassword extends LiteElement {
- - +
${formError}