Skip to content

Commit

Permalink
Fixes queryAssignedNodes when querying for nodes on browsers that do …
Browse files Browse the repository at this point in the history
…have Element.matches

Fixes #1088.
  • Loading branch information
Steven Orvell committed Oct 16, 2020
1 parent 79fac08 commit 08af318
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- ### Removed -->
<!-- ### Fixed -->

## Unreleased

### Fixed
* Fixes an issue with `queryAssignedNodes` when applying a selector on a slot that included text nodes on older browsers not supporting Element.matches [#1088](https://github.com/Polymer/lit-element/issues/1088).

## [2.4.0] - 2020-08-19

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/lib/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ export function queryAssignedNodes(
if (nodes && selector) {
nodes = nodes.filter(
(node) => node.nodeType === Node.ELEMENT_NODE &&
(node as Element).matches ?
((node as any).matches ?
(node as Element).matches(selector) :
legacyMatches.call(node as Element, selector));
legacyMatches.call(node as Element, selector)));
}
return nodes;
},
Expand Down
33 changes: 33 additions & 0 deletions src/test/lib/decorators_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,39 @@ suite('decorators', () => {
flush();
assert.deepEqual(c.assignedNodesEl.footerAssignedItems, []);
});

test('returns assignedNodes for slot that contains text nodes filtered by selector when Element.matches does not exist', async () => {
const descriptor = Object.getOwnPropertyDescriptor(
Element.prototype,
'matches'
);
Object.defineProperty(Element.prototype, 'matches', {
value: undefined,
configurable: true,
});
const c = new C();
container.appendChild(c);
await c.updateComplete;
await c.assignedNodesEl.updateComplete;
assert.deepEqual(c.assignedNodesEl.footerAssignedItems, []);
const child1 = document.createElement('div');
const child2 = document.createElement('div');
const text1 = document.createTextNode('');
const text2 = document.createTextNode('');
child2.classList.add('item');
c.appendChild(child1);
c.appendChild(text1);
c.appendChild(child2);
c.appendChild(text2);
flush();
assert.deepEqual(c.assignedNodesEl.footerAssignedItems, [child2]);
c.removeChild(child2);
flush();
assert.deepEqual(c.assignedNodesEl.footerAssignedItems, []);
if (descriptor !== undefined) {
Object.defineProperty(Element.prototype, 'matches', descriptor);
}
});
});

suite('@queryAsync', () => {
Expand Down

0 comments on commit 08af318

Please sign in to comment.