【发布时间】:2019-12-23 12:58:05
【问题描述】:
我正在构建一个使用 <textarea> 元素的 Web 组件,但我不知道如何让它像原生 <textarea> 元素一样接受内部文本。
<body>
<textarea>this works</textarea>
<expanding-textarea>this doesn't</expanding-textarea>
<script type="module">
const template = document.createElement("template");
template.innerHTML = `<textarea></textarea>`;
class ExpandingTextarea extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define("expanding-textarea", ExpandingTextarea);
</script>
</body>
【问题讨论】:
-
你试过在元素上使用
contentEditable属性吗? -
虽然这不能回答问题,但我之前没有遇到过 contentEditable - 这很有趣,谢谢。但是,请注意,该规范预计不会超过目前的草案阶段w3c.github.io/editing/contentEditableTrue.html
标签: javascript html web-component native-web-component