From ff2e0896800faeca0942dbd0fc4e0e159974d6a4 Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Tue, 18 Jul 2023 14:01:22 -0700 Subject: [PATCH] feat(textfield): add textarea type Fixes #4171, #1305, #2926 Changes: - Added "textarea" type (matches native + `; + } + + const prefix = this.renderPrefix(); + const suffix = this.renderSuffix(); // TODO(b/243805848): remove `as unknown as number` once lit analyzer is // fixed return html` - -1 ? this.maxLength : nothing} - min=${(this.min || nothing) as unknown as number} - minlength=${this.minLength > -1 ? this.minLength : nothing} - pattern=${this.pattern || nothing} - placeholder=${this.placeholder || nothing} - ?readonly=${this.readOnly} - ?required=${this.required} - step=${(this.step || nothing) as unknown as number} - type=${this.type} - .value=${live(this.value)} - @change=${this.redispatchEvent} - @input=${this.handleInput} - @select=${this.redispatchEvent} - > -
+
+ ${prefix} + -1 ? this.maxLength : nothing} + min=${(this.min || nothing) as unknown as number} + minlength=${this.minLength > -1 ? this.minLength : nothing} + pattern=${this.pattern || nothing} + placeholder=${this.placeholder || nothing} + ?readonly=${this.readOnly} + ?required=${this.required} + step=${(this.step || nothing) as unknown as number} + type=${this.type} + .value=${live(this.value)} + @change=${this.redispatchEvent} + @input=${this.handleInput} + @select=${this.redispatchEvent} + > + ${suffix} +
`; } @@ -618,8 +682,8 @@ export abstract class TextField extends LitElement { redispatchEvent(this, event); } - private getInput() { - if (!this.input) { + private getInputOrTextarea() { + if (!this.inputOrTextarea) { // If the input is not yet defined, synchronously render. // e.g. // const textField = document.createElement('md-outlined-text-field'); @@ -636,11 +700,19 @@ export abstract class TextField extends LitElement { this.scheduleUpdate(); } - return this.input!; + return this.inputOrTextarea!; + } + + private getInput() { + if (this.type === 'textarea') { + return null; + } + + return this.getInputOrTextarea() as HTMLInputElement; } private checkValidityAndDispatch() { - const valid = this.getInput().checkValidity(); + const valid = this.getInputOrTextarea().checkValidity(); let canceled = false; if (!valid) { canceled = !this.dispatchEvent(new Event('invalid', {cancelable: true}));