我一直在做一个创建自定义元素的项目,该元素在shadowRoot中具有<slot>.从Chrome 117的发布开始,如果有人点击一个可满足的div,元素就会获得焦点,他们就可以打字了,但如果你来回点击,那么该元素就不再是可聚焦的.下面是一个最小的例子(demo):

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body>
    <input id="test-input" />

    <example-component>
      <div contenteditable="true">
        <h1>Hello World!</h1>
        <p>This is an example</p>
      </div>
    </example-component>

    <script>
      customElements.define(
        "example-component",
        class extends HTMLElement {
          constructor() {
            super();
            this.attachShadow({ mode: "open" });
            this.shadowRoot.innerHTML = `
            <slot></slot>
          `;
          }
        }
      );
    </script>
  </body>
</html>

这个错误只出现在Chrome版本117(和118测试版)中,而不会出现在任何其他浏览器中(我可以在我的Mac上测试).有谁有什么主意吗?

推荐答案

这似乎是Chrome(bug #1484447)中的一个错误.已提交(src)更新/third_party/blink/renderer/core/css/resolver/style_resolver.cc(1193至1201行)并添加以下代码的最新修补程序:

// contenteditable attribute (implemented by -webkit-user-modify) should
// be propagated from shadow host to distributed node.
if (!style_request.IsPseudoStyleRequest() && element.AssignedSlot()) {
  if (Element* parent = element.parentElement()) {
    if (const ComputedStyle* shadow_host_style =
            parent->GetComputedStyle()) {
      state.StyleBuilder().SetUserModify(shadow_host_style->UserModify());
    }
  }
}

这允许卷影主机 node 俯视其父 node ,以查看它们是否可编辑.

Javascript相关问答推荐

React中的表格中 Select Radio按钮

使脚本兼容于其他YouTube URL格式

鼠标移动时更新画布

基于每个索引迭代嵌套对象

在JavaScript中,如何将请求的回调函数的结果合并到运行的代码中?

根据总价格对航班优惠数组进行排序并检索前五个结果- Angular HTTP请求

Vega中的模运算符

从mat—country—select获取整个Country数组

将现场录音发送到后端

在带有背景图像和圆形的div中添加长方体阴影时的重影线

使用LocaleCompare()进行排序时,首先使用大写字母

覆盖TypeScrip中的Lit-Element子类的属性类型

正则表达式,允许我匹配除已定义的子字符串之外的所有内容

Webpack在导入前混淆文件名

将数组扩展到对象中

以编程方式聚焦的链接将被聚焦,但样式不适用

是否可以将Select()和Sample()与Mongoose结合使用?

如何使用<;Link>;执行与JS Reaction中的";window.Location=/GameOverDied;";类似的操作?

如何使用Astro优化大图像?

在JavaScript中将Base64转换为JSON