Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[g] shadowRoot 事件监听无效 #1641

Closed
xiaoiver opened this issue Mar 18, 2024 · 1 comment
Closed

[g] shadowRoot 事件监听无效 #1641

xiaoiver opened this issue Mar 18, 2024 · 1 comment
Assignees
Labels

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Mar 18, 2024

相关问题:https://riddle.alibaba-inc.com/riddles/e818e445

CSS 样式是正确设置的:

截屏2024-03-18 下午4 15 09

但触发事件时,原生事件对象上的 target 并不是 <canvas> 而是 shadowRoot,目前的逻辑会判定成 outside 从而触发 pointeroutside 事件,导致 pointermove pointerup 等都无法正常触发。

因此需要在 WebComponent 中正确获取 target:
https://stackoverflow.com/questions/57963312/get-event-target-inside-a-web-component

如果检测到 shadowRoot,从 composedPath 中获取:

if (target?.shadowRoot) {
  target = nativeEvent.composedPath()[0] as Element;
}

另外 SVG 用于拾取的方法默认情况下也无法深入 shadowRoot 内部:

document.elementsFromPoint(clientX, clientY);

需要递归传入 shadowRoot 代替 document:
https://stackblitz.com/edit/vite-5cmvnt?file=main.js

@xiaoiver xiaoiver self-assigned this Mar 18, 2024
@xiaoiver xiaoiver added the bug label Mar 18, 2024
xiaoiver added a commit that referenced this issue Mar 18, 2024
@xiaoiver xiaoiver mentioned this issue Mar 18, 2024
14 tasks
xiaoiver added a commit that referenced this issue Mar 18, 2024
* fix: support shadowRoot #1641

* chore: commit changeset

* chore: remove gui from test cases for now
xiaoiver added a commit that referenced this issue Mar 19, 2024
* Fix 1641 (#1642)

* fix: support shadowRoot #1641

* chore: commit changeset

* chore: remove gui from test cases for now

* chore(release): bump version (#1643)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@xiaoiver
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant