Skip to content

Commit

Permalink
refactor: defer scroll position adjustment until rAF
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Mar 5, 2019
1 parent 3ca005c commit 41f8709
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/vaadin-combo-box-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,12 @@

// Ensure metrics are up-to-date
this.$.overlay.updateViewportBoundaries();
Polymer.Async.microTask.run(() => this.$.overlay.adjustScrollPosition());
// Force iron-list to create reusable nodes. Otherwise it will only start
// doing that in scroll listener, which is especially slow in Edge.
this.$.overlay._selector._increasePoolIfNeeded();
setTimeout(() => this._resizeDropdown(), 1);
// Defer scroll position adjustment to prevent freeze in Edge
window.requestAnimationFrame(() => this.$.overlay.adjustScrollPosition());


// _detectAndDispatchChange() should not consider value changes done before opening
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"fire": false,
"fireMousedownMouseupClick": false,
"getCustomPropertyValue": false,
"onceScrolled": false,
"System": false,
"HTMLImports": false,
"MockInteractions": false,
Expand Down
12 changes: 12 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ var fireMousedownMouseupClick = (node) => {
fire('click', node);
};

var onceScrolled = (scroller) => {
return new Promise(resolve => {
const listener = () => {
scroller.removeEventListener('scroll', listener);
setTimeout(() => {
resolve();
});
};
scroller.addEventListener('scroll', listener);
});
};

var describeSkipIf = (bool, title, callback) => {
bool = typeof bool == 'function' ? bool() : bool;
if (bool) {
Expand Down
8 changes: 5 additions & 3 deletions test/filtering.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@
setInputValue('b');

// first scroll after open is async
setTimeout(() => {
expect(spy.callCount).to.eql(1); // scrolls once on open
done();
window.requestAnimationFrame(() => {
setTimeout(() => {
expect(spy.callCount).to.eql(1); // scrolls once on open
done();
}, 1);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@

comboBox.open();

setTimeout(() => {
onceScrolled(comboBox.$.overlay._scroller).then(() => {
expect(selector.firstVisibleIndex).to.be.within(50 - comboBox.$.overlay._visibleItemsCount(), 50);
done();
});
Expand Down
4 changes: 2 additions & 2 deletions test/scrolling.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
combobox.value = combobox.items[50];
combobox.open();

setTimeout(() => {
onceScrolled(combobox.$.overlay._scroller).then(() => {
expectSelectedItemPositionToBeVisible();
done();
}, 1);
});
});

it('should make selected item visible after reopen', done => {
Expand Down

0 comments on commit 41f8709

Please sign in to comment.