Add this.$ to LitElement as it's still very light-weight but usefule
See original GitHub issuePolymer has this.$
as a convenient way to access all shadow root elements with an id
defined, by id.
This can be easily added to LitElement as:
constructor() {
super(...arguments);
this.__renderComplete = null;
this.__resolveRenderComplete = null;
this.__isInvalid = false;
this.__isChanging = false;
// Add support for this.$
this.$ = {};
}
ready() {
this._root = this._createRoot();
super.ready();
// Add support for this.$
for( const el of this._root.querySelectorAll( "*[id]" ) )
this.$[el.id] = el;
this._firstRendered();
}
and then accessed the same way as in Polymer: this.$.name.value
for example, if we have an <input id="name"/>
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Add this.$ to LitElement as it's still very light-weight but usefule
Polymer has this.$ as a convenient way to access all shadow root elements with an id defined, by id. This can be easily...
Read more >Lightweight And Fast Web Components With LitElement
LitElement is a pure base class for creating fast, lightweight Web Components that work in any web page with or without a framework...
Read more >LitElement
Lit templates, based on tagged template literals, are simple, expressive and fast, featuring HTML markup with native JavaScript expressions inline. No custom ...
Read more >Getting started with LitElement and TypeScript - This Dot Labs
LitElement is an excellent alternative to build lightweight web applications since it's based on the Web Components standard, with the addition ...
Read more >From Web Component to Lit Element - Google Codelabs
Lit is a simple library for building fast, lightweight web components that work in any framework, or with no framework at all. With...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would be against this feature request. Since
lit-element
useslit-html
to handle elements declaratively, it’s almost unnecessary to adjust elements manually, and if you still need it, you can do it by built-in tools likequerySelector
orgetElementById
called fromthis.shadowRoot
.For posterity, and anyone landing here from google (greetings!), I present a simple mixin: