【问题标题】:shadowRoot.activeElement is not working in safarishadowRoot.activeElement 在 Safari 中不起作用
【发布时间】:2019-07-12 02:44:40
【问题描述】:

目前我正在研究具有实现 shadow dom 功能的 stencilJS。我面临一个与 shadowRoot 的 activeElement 相关的问题。它在 Chrome 上运行良好,但是当我测试我的组件时,activeElement 在 safari 中变为 null。

这里是代码sn-p

import { Component, Prop, Listen } from '@stencil/core';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',
  shadow: true
})
export class MyComponent {
  /**
   * The first name
   */
  @Prop() first: string;

  /**
   * The middle name
   */
  @Prop() middle: string;

  /**
   * The last name
   */
  @Prop() last: string;

  @Listen('click')
  onHadnleClickEvent(ev) {
    console.log('===== 31 =====', ev.target.shadowRoot.activeElement)// getting null in safari
  }

  render() {
    return ( <div>
        <button>Click Me!!!</button>
      </div>
    )
  }
}

【问题讨论】:

标签: web-component shadow-dom stenciljs


【解决方案1】:

我找到了启用shadowDom时获得点击元素的结果。这是解决方案:

  @Listen('click')
  onHadnleClickEvent(ev) {
    console.log('===== 31 =====', ev.composedPath()[0]// It will give you the clicked element
  }

【讨论】:

    猜你喜欢
    • 2019-01-08
    • 2013-08-17
    • 2015-05-12
    • 2012-12-15
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多