Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always scroll to selected item on first open and flaky tests #816

Merged
merged 3 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/vaadin-combo-box-dropdown-wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@
}

_scrollIntoView(index) {
if (!(this.opened && index >= 0)) {
return;
}
const visibleItemsCount = this._visibleItemsCount();
if (visibleItemsCount === undefined) {
// Scroller is not visible. Moving is unnecessary.
Expand All @@ -360,6 +363,9 @@

if (index > this._selector.lastVisibleIndex - 1) {
// Index is below the bottom, scrolling down. Make the item appear at the bottom.
// First scroll to target (will be at the top of the scroller) to make sure it's rendered.
this._selector.scrollToIndex(index);
// Then calculate the index for the following scroll (to get the target to bottom of the scroller).
targetIndex = index - visibleItemsCount + 1;
} else if (index > this._selector.firstVisibleIndex) {
// The item is already visible, scrolling is unnecessary per se. But we need to trigger iron-list to set
Expand Down
14 changes: 5 additions & 9 deletions test/filtering.html
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,11 @@
comboBox = fixture('combobox');
});

it('should properly display all items in the selector', done => {
comboBox.opened = true;
setTimeout(() => {
comboBox.filteredItems = Array.apply(null, Array(20)).map((_, i) => `item${i}`);
setTimeout(() => {
expect(comboBox.$.overlay._selector.querySelectorAll('vaadin-combo-box-item').length).to.equal(20);
done();
}, 1);
});
it('should properly display all items in the selector', () => {
comboBox.open();
comboBox.filteredItems = Array.apply(null, Array(20)).map((_, i) => `item${i}`);
Polymer.flush();
expect(comboBox.$.overlay._selector.querySelectorAll('vaadin-combo-box-item').length).to.equal(20);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script src="test-suites.js"></script>
</head>

<body>
<body style="min-height: 520px;">
<script>
WCT.loadSuites(window.VaadinComboBoxSuites);
</script>
Expand Down
1 change: 1 addition & 0 deletions test/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
});

it('should scroll down after reaching the last visible item', () => {
selector.scrollToIndex(0);
comboBox._focusedIndex = comboBox.$.overlay._visibleItemsCount() - 1;
expect(selector.firstVisibleIndex).to.eql(0);

Expand Down