Overview
onParent(targetRef, events) is an element directive placed on a child (or descendant). It attaches listeners to the element held by targetRef (typically a parent/ancestor set with setRef).
Listeners bind when the ref’s element becomes available, re-sync when the event map updates, and unbind when the host element disconnects.
onParent vs @event vs on()
|
API
|
Listener target
|
Notes
|
|---|---|---|
@click=${fn}
| Same element | Native lit-html listener on the host node. |
onParent(ref, map)
| Ref’d ancestor | Child hosts the directive; events fire on the parent/ancestor element. |
Component on(…) hooks
| Window / document / … | Outer-function lifecycle hooks — different layer. |
Child listening to parent scroll
The scroll container owns a ref. Each row applies onParent(scrollRef, { scroll, click }) so listeners attach to the parent and clean up with the row.
Parent click counter
Listen for click on an ancestor ref from a nested child.