© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2021
J. KrauseDeveloping Web Components with TypeScripthttps://doi.org/10.1007/978-1-4842-6840-7_4

4. Events

Jörg Krause1  
(1)
Berlin, Berlin, Germany
 

The idea behind the shadow tree is to encapsulate internal implementation details of a component. This requires exposing events explicitly if you still want to interact with the inner parts of a component.

Let’s say a click event happens inside a Shadow DOM of the <user-card> component . But scripts in the main document have no idea about the Shadow DOM internals. So, to keep the details encapsulated, the browser has to retarget the event. Events that happen in the Shadow DOM have the host element as the target when ...

Get Developing Web Components with TypeScript: Native Web Development Using Thin Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.