Declare dependencies to _updateSuggestions observer
Because the observer for _updateSuggestions was setup without declaring all the properties it depended on, and since the one declared dependency was set statically, the observer would fire before the element was ready and frequently before all the dependencies were setup. Make the property dependencies explicit so that the observer executes at the expected time. Bug: Issue 8149 Change-Id: I9fff4d0a9c563afa9cd4559fa63061a3749cb9cf
This commit is contained in:
@@ -39,7 +39,6 @@ limitations under the License.
|
||||
allow-non-suggested-values="[[allowAnyInput]]"
|
||||
on-commit="_handleInputCommit"
|
||||
clear-on-commit
|
||||
no-debounce
|
||||
warn-uncommitted
|
||||
text="{{_inputText}}">
|
||||
</gr-autocomplete>
|
||||
|
||||
@@ -88,7 +88,6 @@
|
||||
text: {
|
||||
type: String,
|
||||
value: '',
|
||||
observer: '_updateSuggestions',
|
||||
notify: true,
|
||||
},
|
||||
|
||||
@@ -168,6 +167,7 @@
|
||||
|
||||
observers: [
|
||||
'_maybeOpenDropdown(_suggestions, _focused)',
|
||||
'_updateSuggestions(text, threshold, debounceWait)',
|
||||
],
|
||||
|
||||
attached() {
|
||||
@@ -219,7 +219,7 @@
|
||||
|
||||
_onInputFocus() {
|
||||
this._focused = true;
|
||||
this._updateSuggestions();
|
||||
this._updateSuggestions(this.text, this.threshold, this.debounceWait);
|
||||
this.$.input.classList.remove('warnUncommitted');
|
||||
// Needed so that --paper-input-container-input updated style is applied.
|
||||
this.updateStyles();
|
||||
@@ -232,14 +232,13 @@
|
||||
this.updateStyles();
|
||||
},
|
||||
|
||||
_updateSuggestions() {
|
||||
_updateSuggestions(text, threshold, debounceWait) {
|
||||
if (this._disableSuggestions) { return; }
|
||||
if (this.text === undefined || this.text.length < this.threshold) {
|
||||
if (text === undefined || text.length < threshold) {
|
||||
this._suggestions = [];
|
||||
this.value = '';
|
||||
return;
|
||||
}
|
||||
const text = this.text;
|
||||
|
||||
const update = () => {
|
||||
this.query(text).then(suggestions => {
|
||||
@@ -258,8 +257,8 @@
|
||||
});
|
||||
};
|
||||
|
||||
if (this.debounceWait) {
|
||||
this.debounce('update-suggestions', update, this.debounceWait);
|
||||
if (debounceWait) {
|
||||
this.debounce('update-suggestions', update, debounceWait);
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -261,9 +261,7 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('undefined or empty text results in no suggestions', () => {
|
||||
sandbox.spy(element, '_updateSuggestions');
|
||||
element.text = undefined;
|
||||
assert(element._updateSuggestions.calledOnce);
|
||||
element._updateSuggestions(undefined, 0, null);
|
||||
assert.equal(element._suggestions.length, 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user