Bubbling in Shadow DOM

Web ComponentsShadow DOMEvents

  • If event occurs on an element from shadow DOM, then, as it bubbles out of shadow DOM, its event.target is reset to <custom-element>.

  • For purposes of event bubbling, flattened DOM is used.

  • if we have a slotted element, and an event occurs somewhere inside it, then it bubbles up to the <slot> and upwards. 👉 see: tab 1️⃣ (click on slotted element)

event.composedPath()

  • The full path to the original event target, with all the shadow elements, can be obtained using event.composedPath() 👉 see: tab 1️⃣

💾 replit (live demo on codepen)

Topics

Last updated