another version of Element.prototype.contains
that considers slotted elements as children
#1214
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: nodes
topic: shadow
Relates to shadow trees (as defined in DOM)
Hi, hope you all are well :)
motivation
Currently,
Element.prototype.contains()
doesn't see slotted elements as children.ref: the latest version of DOM Living Standard: https://dom.spec.whatwg.org/#dom-node-contains
This behavior is sometimes problematic when
<template>
is used, and this kind of situation can possibly increase by the appearance of declarative shadow dom.Of course, the alternative can be implemented on the side of each developer.
But it's not so simple to implement it, especially taking the calculation cost into account.
So it'll be helpful if another version of the function that considers slotted elements as children is provided by default.
draft of implementation for discussion
Basically, it's enough to apply
Element.prototype.contains()
recursively while drilling up to parentNode or assignedSlot.This implementation can detect shadow-including descendant also.
I think it's a bit too complicated to let each developer to implement by themselves.
Would like to hear opinions here :)
The text was updated successfully, but these errors were encountered: