Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created June 24, 2021 07:12
Show Gist options
  • Save julianrubisch/bbc9d858fd4f886b6a2f574c5cceade8 to your computer and use it in GitHub Desktop.
Save julianrubisch/bbc9d858fd4f886b6a2f574c5cceade8 to your computer and use it in GitHub Desktop.
contenteditable lit-element
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