Skip to content

Commit 57406c5

Browse files
authored
fix: assign flattened nodes as list-mixin items (#4337)
1 parent 2b05f47 commit 57406c5

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎packages/vaadin-list-mixin/test/list-mixin.test.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ customElements.define(
9393
},
9494
);
9595

96+
customElements.define(
97+
'test-list-wrapper-element',
98+
class extends PolymerElement {
99+
static get template() {
100+
return html`
101+
<style>
102+
:host {
103+
display: block;
104+
}
105+
</style>
106+
107+
<test-list-element>
108+
<slot></slot>
109+
</test-list-element>
110+
`;
111+
}
112+
},
113+
);
114+
96115
describe('vaadin-list-mixin', () => {
97116
let list;
98117

@@ -120,6 +139,25 @@ describe('vaadin-list-mixin', () => {
120139
});
121140
});
122141

142+
describe('wrapped list with slotted items', () => {
143+
beforeEach(() => {
144+
const wrapper = fixtureSync(`
145+
<test-list-wrapper-element>
146+
<test-item-element>Item 0</test-item-element>
147+
<test-item-element>Item 1</test-item-element>
148+
<test-item-element>Item 2</test-item-element>
149+
</test-list-wrapper-element>
150+
`);
151+
list = wrapper.shadowRoot.querySelector('test-list-element');
152+
});
153+
154+
it('should have a list of valid items after the DOM `_observer` has been run', () => {
155+
// DOM _observer runs asynchronously, we need to flush to access items
156+
list._observer.flush();
157+
expect(list.items.length).to.be.equal(3);
158+
});
159+
});
160+
123161
describe('DOM', () => {
124162
beforeEach(() => {
125163
list = fixtureSync(`

‎packages/vaadin-list-mixin/vaadin-list-mixin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const ListMixin = (superClass) =>
8787
this.addEventListener('click', (e) => this._onClick(e));
8888

8989
this._observer = new FlattenedNodesObserver(this, () => {
90-
this._setItems(this._filterItems(Array.from(this.children)));
90+
this._setItems(this._filterItems(FlattenedNodesObserver.getFlattenedNodes(this)));
9191
});
9292
}
9393

0 commit comments

Comments
 (0)