Skip to content

Commit

Permalink
Avoid notifyResize calls when overlay is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Aug 14, 2018
1 parent f8c1a11 commit 9c1054a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/vaadin-combo-box-dropdown-wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
}

_setOverlayHeight() {
if (!this.positionTarget || !this._selector) {
if (!this.opened || !this.positionTarget || !this._selector) {
return;
}

Expand Down
34 changes: 23 additions & 11 deletions src/vaadin-combo-box-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
// Ensure metrics are up-to-date
this.$.overlay.updateViewportBoundaries();
Polymer.Async.microTask.run(() => this.$.overlay.adjustScrollPosition());
setTimeout(() => this.$.overlay.$.dropdown.notifyResize(), 1);
setTimeout(() => this._resizeDropdown(), 1);


// _detectAndDispatchChange() should not consider value changes done before opening
Expand Down Expand Up @@ -595,6 +595,10 @@
}
}

_resizeDropdown() {
this.$.overlay.$.dropdown.notifyResize();
}

_updateHasValue(hasValue) {
if (hasValue) {
this.setAttribute('has-value', '');
Expand Down Expand Up @@ -695,15 +699,9 @@
this.$.overlay.indexOfLabel(this.filter) :
this._indexOfValue(this.value, this.filteredItems);

// async needed to reposition correctly after filtering
// (especially when aligned on top of input)
setTimeout(() => {
this.$.overlay.$.dropdown.notifyResize();
this.$.overlay.updateViewportBoundaries();
this.$.overlay.ensureItemsRendered();
this.$.overlay._selector.notifyResize();
Polymer.flush && Polymer.flush();
}, 1);
if (this.opened) {
this._repositionOverlay();
}
}
}

Expand All @@ -722,7 +720,21 @@
_setOverlayItems(items) {
this.$.overlay.set('_items', items);

this.$.overlay.$.dropdown.notifyResize();
if (this.opened) {
this._resizeDropdown();
}
}

_repositionOverlay() {
// async needed to reposition correctly after filtering
// (especially when aligned on top of input)
setTimeout(() => {
this._resizeDropdown();
this.$.overlay.updateViewportBoundaries();
this.$.overlay.ensureItemsRendered();
this.$.overlay._selector.notifyResize();
Polymer.flush && Polymer.flush();
}, 1);
}

_indexOfValue(value, items) {
Expand Down
14 changes: 14 additions & 0 deletions test/filtering.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,20 @@
comboBox = fixture('configured');
expect(comboBox._focusedIndex).to.eql(1);
});

it('should not notify resize the dropdown if not opened', () => {
const resizeSpy = sinon.spy(comboBox.$.overlay.$.dropdown, 'notifyResize');
comboBox.filteredItems = ['foo', 'bar', 'baz'];

expect(resizeSpy).to.not.have.been.called;
});

it('should not re-position the overlay if not opened', () => {
const repositionSpy = sinon.spy(comboBox, '_repositionOverlay');
comboBox.filteredItems = ['foo', 'bar', 'baz'];

expect(repositionSpy).to.not.have.been.called;
});
});

describe('setting items when opened', () => {
Expand Down
8 changes: 8 additions & 0 deletions test/overlay-position.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,20 @@
});

it('should notify resize on items change', () => {
comboBox.opened = true;
const spy = sinon.spy();
comboBox.$.overlay.$.dropdown.notifyResize = spy;
comboBox.items = [1, 2, 3];
expect(spy.called).to.be.true;
});

it('should not notify resize when not opened', () => {
const spy = sinon.spy();
comboBox.$.overlay.$.dropdown.notifyResize = spy;
comboBox.items = [1, 2, 3];
expect(spy.called).to.be.false;
});

it('should reposition on scroll', () => {
comboBox.opened = true;
comboBox.$.overlay.updateViewportBoundaries = sinon.spy();
Expand Down

0 comments on commit 9c1054a

Please sign in to comment.