Skip to content

Commit

Permalink
revert some changes, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Apr 19, 2024
1 parent 912b959 commit 73cc8c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/combo-box/src/vaadin-combo-box-data-provider-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ export const ComboBoxDataProviderMixin = (superClass) =>
sync: true,
},

/** @private */
_hasData: {
type: Boolean,
value: false,
},

/** @private */
__previousDataProviderFilter: {
type: String,
Expand Down Expand Up @@ -143,7 +137,8 @@ export const ComboBoxDataProviderMixin = (superClass) =>
return;
}

if (opened && !this._hasData) {
if (opened && this._forceNextRequest) {
this._forceNextRequest = false;
this._dataProviderController.loadFirstPage();
}
}
Expand All @@ -155,8 +150,6 @@ export const ComboBoxDataProviderMixin = (superClass) =>

/** @private */
_onDataProviderPageLoaded() {
this._hasData = true;

this.requestContentUpdate();

if (!this.opened && !this._isInputFocused()) {
Expand All @@ -174,12 +167,13 @@ export const ComboBoxDataProviderMixin = (superClass) =>

this._dataProviderController.clearCache();

this._hasData = false;

this.requestContentUpdate();

if (this._shouldFetchData()) {
this._dataProviderController.loadFirstPage();
this._forceNextRequest = false;
} else {
this._forceNextRequest = true;
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/combo-box/test/lazy-loading.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,23 @@ describe('lazy loading', () => {
expect(comboBox.size).to.be.undefined;
});

it('should not have default value after setting dataProvider', () => {
comboBox.dataProvider = spyDataProvider;
expect(comboBox.size).to.be.undefined;
});

it('should be set from dataProvider callback', () => {
comboBox.opened = true;
comboBox.dataProvider = spyDataProvider;
expect(comboBox.size).to.equal(SIZE);
});

it('should be set to 0 when dataProvider returns size 0', () => {
comboBox.opened = true;
comboBox.dataProvider = (params, callback) => callback([], 0);
expect(comboBox.size).to.equal(0);
});

it('should remove extra filteredItems when decreasing size', () => {
comboBox.dataProvider = (params, callback) => callback(['foo', 'bar'], 2);
comboBox.open();
Expand Down

0 comments on commit 73cc8c8

Please sign in to comment.