Skip to content

Commit

Permalink
fix(ripple): unable to add event listeners to parent node with shadow…
Browse files Browse the repository at this point in the history
… root in attached mode
  • Loading branch information
lingbopro committed Dec 22, 2024
1 parent e7142eb commit 1f04d96
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/ripple/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
}
},
},
Expand Down

0 comments on commit 1f04d96

Please sign in to comment.