[Bug 22141] [Shadow]: Need mechanism to tell if an element in a ShadowRoot has been inserted into the Document

https://www.w3.org/Bugs/Public/show_bug.cgi?id=22141

Jan Miksovsky <jan@quickui.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jan@quickui.org

--- Comment #4 from Jan Miksovsky <jan@quickui.org> ---
I ran across this issue this week, and Daniel pointed me at this bug. See the
thread at https://groups.google.com/forum/#!topic/polymer-dev/mGs_zkA_7-4.

Erik was asking for a scenario, and this thread presents one. An overlay
(popup) element wants to track and/or absorb all clicks on the document. Clicks
outside the overlay should dismiss the overlay, while clicks inside the element
should have no effect. The overlay author wires up a click handler on the
document, capturing events so that it gets first crack at them (and stop them
before they might inadvertently triggering other handlers). The overlay's click
handler looks at the event target to decide whether the target is in the
overlay or not. For this purpose, the developer decides to use contains(). The
dev tests the overlay's click tracking behavior with light DOM content inside
the overlay, and all works well.

Later, someone else (me) tries to include the overlay element in the shadow of
another element, and distribute content into the overlay. When the user looks
at the overlay, they see content presented inside the overlay. From the user's
point of view, the overlay contains the content. However, if the user clicks on
the (light DOM) content, the overlay's contains() check fails, and the overlay
fails to behave properly.

One could argue the overlay element should be written differently. Maybe it
could track clicks outside using capturing and track clicks inside using
bubbling, or find some other solution. But I think the dev made a reasonable
call to use contains() for this purpose, and it seemed to work for any tests
they cared to make. It was only when the overlay element was subsumed into the
shadow of another element that things broke.

I'll hazard that similar issues are likely to come up wherever a dev tries to
use contains() within a custom element. Subsuming that element into the shadow
of another element will cause problems. I believe custom elements will have a
general need to know whether they (visually) contain a given element,
regardless of whether the element is in their shadow or distributed to them.

How this is done, whether through modifying contains() or something new, I'll
leave to people wiser than me to figure out.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Thursday, 24 October 2013 23:14:55 UTC