I'm trying to make a small app using the PWA Starter Kit from the Polymer project.
Is it possible to use a web component from https://material.io/develop/web/components/input-controls/text-field/ inside my LitElement? I want use a text area.
What I have tried:
import {html, customElement, LitElement} from "lit-element";
//
import {MDCTextField} from '@material/textfield';
@customElement('text-editor')
export class TextEditor extends LitElement {
protected render() {
return html`<div class="mdc-text-field mdc-text-field--textarea">
<textarea id="textarea" class="mdc-text-field__input" rows="8" cols="40"></textarea>
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch">
<label for="textarea" class="mdc-floating-label">Textarea Label</label>
</div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>`
}
}
However, because I don't use "MDCTextField" anywhere, the TypeScript compiler complains that "'MDCTextField' is declared but its value is never read.".
I do get a text area rendered in the HTML, but none of the styles are applied.
How can I reuse the MDCTextField web component in a LitElement?
Yes, you have to use LitElement's static styles which uses Constructible styles along with fallback for non-supporting browsers:
These are the things you need to do:
MDCTextFieldwhen the component is rendered for the first time usingfirstUpdatedlifecycle event.MDCTextFieldinstance.