Skip to content

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

@bicknellr

Description

@bicknellr

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs implementer interestMoving the issue forward requires implementers to express interesttopic: shadowRelates to shadow trees (as defined in DOM)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions