Skip to content

Commit

Permalink
Shadow DOM events improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
plegner committed Jul 20, 2023
1 parent a1511e6 commit 3388440
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ function makeClickOutsideEvent($el: ElementView) {
$el._data['clickOutsideEvent'] = true;

$body.on('pointerdown', (e: ScreenEvent) => {
let target = e.target as Node|null;

// Elements within shadow roots are opaque, so we check using coordinates.
const shadowRoot = $el._el.getRootNode?.() as ShadowRoot|undefined;
const posn = pointerPosition(e);
if (shadowRoot?.host) target = (shadowRoot as any).elementFromPoint(posn.x, posn.y);

// The .composedPath method ensures that this still works in shadow DOM.
let target = (e.composedPath()[0] || e.target) as Node|null;

Check failure on line 119 in src/events.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x

'target' is never reassigned. Use 'const' instead

Check failure on line 119 in src/events.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x

'target' is never reassigned. Use 'const' instead
if (!target || $el._el === target || $el._el.contains(target)) return;
$el.trigger('clickOutside', e);
});
Expand Down

0 comments on commit 3388440

Please sign in to comment.