Skip to content

Support events on buttons/links/forms in ShadowDOMs - #1351

Merged
Jethro Nederhof (jethron) merged 2 commits into
snowplow:release/4.0.0from
jethron:shadow-clicks
Oct 9, 2024
Merged

Support events on buttons/links/forms in ShadowDOMs#1351
Jethro Nederhof (jethron) merged 2 commits into
snowplow:release/4.0.0from
jethron:shadow-clicks

Conversation

@jethron

@jethron Jethro Nederhof (jethron) commented Oct 4, 2024

Copy link
Copy Markdown
Contributor

When DOM events on elements within Custom Components/ShadowRoots trigger against the document, the target is set to the Custom Element/shadow host rather than the actual element that caused the event.

This change adds support to the from/button/link tracking plugins to detect when this occurs, and use the first element from the Event's composedPath instead of the target. This enables them to see the actual even target and fire correctly in this scenario.

For the Form tracker, only focus events are considered composed, so change and submit events don't actually get reported outside the shadow DOM. As a workaround, when the focus events occur, if enabled the change/submit event listeners are bound directly to the form (or field if it has no associated form) rather than just the document.

@bundlemon

bundlemon Bot commented Oct 4, 2024

Copy link
Copy Markdown

BundleMon

Files added (6)
Status Path Size Limits
trackers/javascript-tracker/dist/sp.js
+24.32KB 30KB / +10%
libraries/browser-tracker-core/dist/index.mod
ule.js
+23.41KB 25KB / +10%
libraries/tracker-core/dist/index.module.js
+19.12KB 20KB / +10%
trackers/browser-tracker/dist/index.umd.min.j
s
+17.24KB 20KB / +10%
trackers/javascript-tracker/dist/sp.lite.js
+17.18KB 20KB / +10%
trackers/browser-tracker/dist/index.module.js
+3.49KB 5KB / +10%

Total files change +104.75KB 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history

@jethron Jethro Nederhof (jethron) changed the title Support clicks on buttons/links in ShadowDOMs Support events on buttons/links/forms in ShadowDOMs Oct 8, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@jethron
Jethro Nederhof (jethron) merged commit 759f88d into snowplow:release/4.0.0 Oct 9, 2024
@jethron
Jethro Nederhof (jethron) deleted the shadow-clicks branch October 9, 2024 22:18
Matus Tomlein (matus-tomlein) pushed a commit that referenced this pull request Oct 25, 2024
* Support clicks on buttons/links in ShadowDOMs

* Detect form events within ShadowRoots
Matus Tomlein (matus-tomlein) pushed a commit that referenced this pull request Oct 28, 2024
* Support clicks on buttons/links in ShadowDOMs

* Detect form events within ShadowRoots
Matus Tomlein (matus-tomlein) pushed a commit that referenced this pull request Oct 28, 2024
* Support clicks on buttons/links in ShadowDOMs

* Detect form events within ShadowRoots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants