Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(introspection): Search our shadowRoot as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Jan 6, 2014
1 parent 12f5f67 commit 6549c98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/introspection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Scope ngScope(dom.Node node) => ngProbe(node).scope;
List<dom.Element> ngQuery(dom.Node element, String selector, [String containsText]) {
var list = [];
var children = [element];
if ((element is dom.Element) && element.shadowRoot != null) {
children.add(element.shadowRoot);
}
while (!children.isEmpty) {
var child = children.removeAt(0);
child.querySelectorAll(selector).forEach((e) {
Expand Down
7 changes: 7 additions & 0 deletions test/introspection_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ main() => describe('introspection', () {
expect(toHtml(ngQuery(div, 'li', 'secret'))).toEqual('<li>secret</li>');
expect(toHtml(ngQuery(div, 'li', 'xxx'))).toEqual('');
});

it('should select elements in the root shadow root', () {
var div = new Element.html('<div></div>');
var shadowRoot = div.createShadowRoot();
shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>';
expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>');
});
});

0 comments on commit 6549c98

Please sign in to comment.