Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compareDocumentPosition should allow comparison of elements in the same shadow-including root #320

Closed
bicknellr opened this issue Aug 30, 2016 · 3 comments
Labels
needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@bicknellr
Copy link

(Some discussion on this already happened in #309.)

https://dom.spec.whatwg.org/#dom-node-comparedocumentposition

compareDocumentPosition should be able to compare nodes with different roots if those nodes have the same shadow-including root and the user indicates they would like to compare using the composed tree.

Consider:

<div>
  <!-- ShadowRoot -->
    <slot></slot>
    <div id="A"></div>
  <!-- /ShadowRoot -->
  <div id="B"></div>
</div>

which composes to something 'like':

<div>
  <!-- ShadowRoot -->
    <slot>
      <div id="B"></div>
    </slot>
    <div id="A"></div>
  <!-- /ShadowRoot -->
</div>

A.compareDocumentPosition(B, {composed: true});, or something similar, should return DOCUMENT_POSITION_PRECEDING.

A strange situation this brings up is how fallback content of a slot compare to other nodes in the same shadow-including root when that slot has assigned nodes. IMHO, when comparing using the composed tree, the slot's fallback content should be considered disconnected.

Also, given that a ShadowRoot doesn't have a natural position in its host's tree (or relative to its host's descendants - it's not a special child) without composition, I think step 6 in the specced behavior should continue to apply if no explicit opt-in is indicated.

@annevk annevk added topic: shadow Relates to shadow trees (as defined in DOM) needs implementer interest Moving the issue forward requires implementers to express interest labels Aug 31, 2016
@travisleithead
Copy link
Member

Do you find that you need to compare nodes across Shadow DOM very often? And if so, why? If this is a current problem, I suppose you have written some extra logic to implement a shadow-including comparison utility function?

@annevk
Copy link
Member

annevk commented Oct 25, 2018

Thanks, given the lack of interest thus far and lack of popular library that does this, I'm going to close this. If this does ever become something that's needed we can obviously reconsider.

@annevk annevk closed this as completed Oct 25, 2018
@MKhowaja
Copy link

MKhowaja commented Jan 7, 2020

Running into this issue as well.
Implemented a workaround in the meantime here:
https://stackblitz.com/edit/comparedocumentposition-shadowroot-patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM)
Development

No branches or pull requests

4 participants