Created
June 24, 2021 07:12
-
-
Save julianrubisch/bbc9d858fd4f886b6a2f574c5cceade8 to your computer and use it in GitHub Desktop.
contenteditable lit-element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LitElement, html, css } from "lit"; | |
import { property, customElement } from "lit/decorators.js"; | |
@customElement("content-element-input") | |
class ContentElementInput extends LitElement { | |
@property({ type: Boolean }) | |
contentEditable = true; | |
@property({ type: String }) | |
placeholder = ""; | |
static styles = css` | |
:host { | |
display: block; | |
} | |
slot { | |
display: block; | |
} | |
slot:focus { | |
outline: none; | |
} | |
slot:focus:empty::before { | |
content: attr(placeholder); | |
} | |
`; | |
render() { | |
return html`<slot | |
?contenteditable=${this.contentEditable} | |
placeholder=${this.placeholder} | |
></slot>`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment