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() value?: any; @property() autocomplete?: any; @property() required?: any; @property({ type: Boolean }) passwordToggle?: boolean; @state() isPasswordVisible: boolean = false; render() { return html`
${this.passwordToggle ? html` ` : ""}
`; } private onTogglePassword() { this.isPasswordVisible = !this.isPasswordVisible; } handleKeyDown(event: KeyboardEvent) { // Enable submit on enter when using if (event.key === "Enter") { const form = this.closest("form") as HTMLFormElement; if (form) { const submitButton = form.querySelector( 'sl-button[type="submit"]' ) as HTMLButtonElement; if (submitButton) { submitButton.click(); } } } } }