From 810a5cf37d4947a8bcc2c94fb1001be0152b36df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Maanp=C3=A4=C3=A4?= Date: Wed, 5 Jun 2019 15:18:58 +0300 Subject: [PATCH] fix: reposition overlay after first page load (#814) only if the number of items to render has increased from a previous rendering fix https://github.com/vaadin/vaadin-combo-box-flow/issues/250 --- src/vaadin-combo-box-data-provider-mixin.html | 4 ++++ test/lazy-loading.html | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/vaadin-combo-box-data-provider-mixin.html b/src/vaadin-combo-box-data-provider-mixin.html index 935564677..5dc62e2f8 100644 --- a/src/vaadin-combo-box-data-provider-mixin.html +++ b/src/vaadin-combo-box-data-provider-mixin.html @@ -156,6 +156,10 @@ if (Object.keys(this._pendingRequests).length === 0) { this.loading = false; } + if (page === 0 && this.__repositionOverlayDebouncer && items.length > (this.__maxRenderedItems || 0)) { + setTimeout(() => this.__repositionOverlayDebouncer.flush()); + this.__maxRenderedItems = items.length; + } } }; this._pendingRequests[page] = callback; diff --git a/test/lazy-loading.html b/test/lazy-loading.html index a50f53a7a..baa44a9dc 100644 --- a/test/lazy-loading.html +++ b/test/lazy-loading.html @@ -258,6 +258,23 @@ comboBox.open(); expect(dp).to.be.calledOnce; }); + + it('should render all visible items after delayed response', done => { + const items = [...Array(10)].map((_, i) => 'item ' + i); + comboBox.dataProvider = (params, callback) => { + setTimeout(() => { + callback(items, 10); + setTimeout(() => { + const renderedTexts = Array.from(comboBox.$.overlay._selector + .querySelectorAll('vaadin-combo-box-item')) + .map(i => i.shadowRoot.querySelector('#content').innerText); + expect(renderedTexts).to.eql(items); + done(); + }); + }, 50); + }; + comboBox.open(); + }); }); describe('when selecting item', () => {