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

feat: add missing API related to dataProvider #3961

Merged
merged 1 commit into from
May 30, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi

static get properties() {
return {
/**
* Total number of items.
* @type {number | undefined}
*/
size: {
type: Number,
notify: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the regular web component does not dispatch size-changed event, so I had to override the property here to specify notify: true - this is done in order to ensure host element size is updated properly.

},

_target: {
type: Object,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ declare class MultiSelectComboBox<TItem = ComboBoxDefaultItem> extends HTMLEleme
*/
selectedItems: TItem[];

/**
* Total number of items.
*/
size: number | undefined;

/**
* Clears the cached pages and reloads data from data provider when needed.
*/
clearCache(): void;

addEventListener<K extends keyof MultiSelectComboBoxEventMap<TItem>>(
type: K,
listener: (this: MultiSelectComboBox<TItem>, ev: MultiSelectComboBoxEventMap<TItem>[K]) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
allow-custom-value="[[allowCustomValue]]"
data-provider="[[dataProvider]]"
filter="{{filter}}"
size="{{size}}"
filtered-items="[[filteredItems]]"
opened="{{opened}}"
renderer="[[renderer]]"
Expand Down Expand Up @@ -327,6 +328,13 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
reflectToAttribute: true,
},

/**
* Total number of items.
*/
size: {
type: Number,
},

/**
* Number of items fetched at a time from the data provider.
* @attr {number} page-size
Expand Down Expand Up @@ -470,6 +478,15 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
return this.required && !this.readonly ? this._hasValue : true;
}

/**
* Clears the cached pages and reloads data from data provider when needed.
*/
clearCache() {
if (this.$ && this.$.comboBox) {
this.$.comboBox.clearCache();
}
}

/**
* Override method inherited from `DisabledMixin` to forward disabled to chips.
* @protected
Expand Down
23 changes: 23 additions & 0 deletions packages/multi-select-combo-box/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ describe('basic', () => {
comboBox.itemValuePath = 'key';
expect(internal.itemValuePath).to.equal('key');
});

it('should propagate size property to combo-box', () => {
comboBox.size = 20;
expect(internal.size).to.equal(20);
});

it('should update size when combo-box size changes', () => {
internal.size = 20;
expect(comboBox.size).to.equal(20);
});

it('should call clearCache() method on the combo-box', () => {
const spy = sinon.spy(internal, 'clearCache');
comboBox.clearCache();
expect(spy.calledOnce).to.be.true;
});

it('should not throw on clearCache() if not attached', () => {
const combo = document.createElement('vaadin-multi-select-combo-box');
expect(() => {
combo.clearCache();
}).to.not.throw(Error);
});
});

describe('selecting items', () => {
Expand Down