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

replace Shadow DOM support #22

Closed
rodneyrehm opened this issue Jul 21, 2015 · 3 comments
Closed

replace Shadow DOM support #22

rodneyrehm opened this issue Jul 21, 2015 · 3 comments

Comments

@rodneyrehm
Copy link
Member

>>>, /deep/ and ::shadow have been deprecated, see https://www.chromestatus.com/features/6750456638341120

We can traverse the DOM ourselves using Sizzle (probably overkill) or TreeWalker

@rodneyrehm rodneyrehm added this to the v0.1.0 - Focus milestone Jul 21, 2015
@rodneyrehm rodneyrehm changed the title remove Shadow DOM support replace Shadow DOM support Jul 23, 2015
@rodneyrehm
Copy link
Member Author

well, this will find all ShadowHost elements:

// see https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter
var ShadowHostFilter = {
  acceptNode: function(node) {
    return node.shadowRoot ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
    // possible optimization using FILTER_REJECT to skip checking the children
  }
};

function findShadowHosts(context, deep) {
  // see https://developer.mozilla.org/en-US/docs/Web/API/Document/createTreeWalker
  var shadowHostFinder = document.createTreeWalker(
    // root element to start search in
    context || document.documentElement,
    // element type filter
    NodeFilter.SHOW_ELEMENT,
    // custom NodeFilter filter
    ShadowHostFilter
  );

  var shadowHosts = [];
  while (shadowHostFinder.nextNode()) {
    shadowHosts.push(shadowHostFinder.currentNode);
    if (deep) {
      var children = findShadowHosts(shadowHostFinder.currentNode.shadowRoot, deep);
      shadowHosts = shadowHosts.concat(children);
    }
  }

  return shadowHosts;
}

// find all ShadowHosts recursively
findShadowHosts(document.documentElement, true);

@rodneyrehm
Copy link
Member Author

Maybe this was a bit premature, as >>> will remain available to querySelectorAll() - https://twitter.com/tabatkins/status/624254124398243840

We'll have to figure out how to make ally/style/focus-source work without >>>.

@rodneyrehm
Copy link
Member Author

query/focusable in "quick" mode (default) requires the support of "Shadow Piercing Descendant Combinator" for Shadow DOM introspection, "strict" mode does not (and will therefore work in Firefox).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant