Proof of concept / strategy decision: Extend or wrap built in elements. #59
Replies: 4 comments
-
In September 2020, in the Lit Slack, someone states:
I could not get an extended component to work myself. :( It doesn't do anything. import {html, css, LitElement} from 'lit';
import {customElement, property} from 'lit/decorators.js';
export class SimpleGreeting extends LitElement {
static styles = css`p { color: blue }`;
render() {
return html`<span>This is from the component!</span>`;
}
}
customElements.define('simple-greeting', SimpleGreeting, { extends: 'p' }); <h2>Extended Component</h2>
<p is="simple-greeting">This is from the light DOM</p> |
Beta Was this translation helpful? Give feedback.
-
Response today from Lit Slack: So, I don't think we can extend built in components with Lit. |
Beta Was this translation helpful? Give feedback.
-
Chris Snyder brought up the way REI is extending components. While REI uses Vue and not web components (?), we thought maybe we can copy the pattern as an optional feature in Outline.
https://rei.github.io/rei-cedar-docs/components/links/ To explain a broad use case, if we have a component that has attributes like For updates, we could use a mutation observer like in Checkbox:
|
Beta Was this translation helpful? Give feedback.
-
The Answer in Lit is that you wrap, because it doesn't support extending. I think that pattern is worse, but I understand the decision with the lack of support in Safari. I think we can consider this closed. |
Beta Was this translation helpful? Give feedback.
-
Do we want to extend or wrap built in elements like
a
andbutton
?A wrapped element would look something like:
An extended element:
A brand new element:
Notes
Brand new elements
Wrapped elements
Extended built in elements
Extended elements in Lit can be created by omitting the
@customElement
decorator and using the standard web component javascript likeReferences
Lit documentation on defining element.
https://lit.dev/docs/components/defining/
Beta Was this translation helpful? Give feedback.
All reactions