From 1f04d965b114df2f36742b588e530140039efa72 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 22 Dec 2024 11:02:26 +0800 Subject: [PATCH] fix(ripple): unable to add event listeners to parent node with shadow root in attached mode --- src/components/ripple/ripple.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/ripple/ripple.ts b/src/components/ripple/ripple.ts index 7d0ae58..7f5e3c5 100644 --- a/src/components/ripple/ripple.ts +++ b/src/components/ripple/ripple.ts @@ -21,7 +21,10 @@ export class Ripple extends useElement({ ) as HTMLDivElement; /** 父元素(用于吸附模式) */ - const parent = this.parentElement; + const parent = + this.parentNode instanceof ShadowRoot + ? (this.parentNode.host as HTMLElement) + : (this.parentNode as HTMLElement); /** 波纹点击开始 */ const rippleTouchStart = (event: MouseEvent, node?: HTMLElement) => { @@ -128,10 +131,11 @@ export class Ripple extends useElement({ if (!this.isConnected) { return; } - if (!prop) { - addListeners(this); + const parent = this.parentElement; + if (prop) { + if (parent) addListeners(parent); } else { - removeListeners(this); + if (parent) removeListeners(parent); } }, },