DEV: gives sk components a way to trigger a search manually (#9199)

This commit is contained in:
Joffrey JAFFEUX
2020-03-13 12:41:08 +01:00
committed by GitHub
parent ac8d8e3b62
commit b727e39a42

View File

@ -231,10 +231,7 @@ export default Component.extend(
}); });
if (this.selectKit.isExpanded) { if (this.selectKit.isExpanded) {
if (this._searchPromise) { this.triggerSearch();
cancel(this._searchPromise);
}
this._searchPromise = this._searchWrapper(this.selectKit.filter);
} }
if (this.computeContent) { if (this.computeContent) {
@ -388,7 +385,7 @@ export default Component.extend(
_debouncedInput(filter) { _debouncedInput(filter) {
this.selectKit.setProperties({ filter, isLoading: true }); this.selectKit.setProperties({ filter, isLoading: true });
this._searchPromise = this._searchWrapper(filter); this.triggerSearch(filter);
}, },
_onChangeWrapper(value, items) { _onChangeWrapper(value, items) {
@ -567,6 +564,15 @@ export default Component.extend(
return content; return content;
}, },
triggerSearch(filter) {
if (this._searchPromise) {
cancel(this._searchPromise);
}
this._searchPromise = this._searchWrapper(
filter || this.selectKit.filter
);
},
_searchWrapper(filter) { _searchWrapper(filter) {
this.clearErrors(); this.clearErrors();
this.setProperties({ mainCollection: [], "selectKit.isLoading": true }); this.setProperties({ mainCollection: [], "selectKit.isLoading": true });
@ -869,10 +875,7 @@ export default Component.extend(
this.selectKit.options.filterable || this.selectKit.options.allowAny this.selectKit.options.filterable || this.selectKit.options.allowAny
}); });
if (this._searchPromise) { this.triggerSearch();
cancel(this._searchPromise);
}
this._searchPromise = this._searchWrapper();
this._safeAfterRender(() => { this._safeAfterRender(() => {
this._focusFilter(); this._focusFilter();