Fix logic error in gr-autocomplete
In 44c1b91, I added logic for showing and hiding autocomplete
suggestions based on whether or not the input child element was
focused. This implementation missed the case where autocomplete
suggestions are clicked on.
Bug: Issue 4603
Change-Id: I076f8790a9776bfff79c2fb564f7ab16586a7cc6
This commit is contained in:
@@ -56,7 +56,6 @@ limitations under the License.
|
||||
placeholder="[[placeholder]]"
|
||||
on-keydown="_handleInputKeydown"
|
||||
on-focus="_onInputFocus"
|
||||
on-blur="_onInputBlur"
|
||||
autocomplete="off" />
|
||||
<div
|
||||
id="suggestions"
|
||||
|
||||
@@ -117,6 +117,14 @@
|
||||
|
||||
},
|
||||
|
||||
attached: function() {
|
||||
this.listen(document.body, 'click', '_handleBodyClick');
|
||||
},
|
||||
|
||||
detached: function() {
|
||||
this.unlisten(document.body, 'click', '_handleBodyClick');
|
||||
},
|
||||
|
||||
get focusStart() {
|
||||
return this.$.input;
|
||||
},
|
||||
@@ -144,10 +152,6 @@
|
||||
this._updateSuggestions();
|
||||
},
|
||||
|
||||
_onInputBlur: function() {
|
||||
this._focused = false;
|
||||
},
|
||||
|
||||
_updateSuggestions: function() {
|
||||
if (!this.text || this._disableSuggestions) { return; }
|
||||
if (this.text.length < this.threshold) {
|
||||
@@ -229,6 +233,16 @@
|
||||
}
|
||||
},
|
||||
|
||||
_handleBodyClick: function(e) {
|
||||
var eventPath = Polymer.dom(e).path;
|
||||
for (var i = 0; i < eventPath.length; i++) {
|
||||
if (eventPath[i] === this) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._focused = false;
|
||||
},
|
||||
|
||||
_handleSuggestionTap: function(e) {
|
||||
this.$.cursor.setCursor(e.target);
|
||||
this._commit();
|
||||
|
||||
@@ -271,8 +271,6 @@ limitations under the License.
|
||||
assert.isFalse(element._focused);
|
||||
element.$.input.focus();
|
||||
assert.isTrue(element._focused);
|
||||
element.$.input.blur();
|
||||
assert.isFalse(element._focused);
|
||||
});
|
||||
|
||||
test('_focused flag shows/hides the suggestions', function() {
|
||||
@@ -282,14 +280,18 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('tap on suggestion commits and refocuses on input', function() {
|
||||
var focusStub = sinon.stub(element, 'focus');
|
||||
var focusSpy = sinon.spy(element, 'focus');
|
||||
var commitSpy = sinon.spy(element, '_commit');
|
||||
element._focused = true;
|
||||
element._suggestions = [{name: 'first suggestion'}];
|
||||
assert.isFalse(element.$.suggestions.hasAttribute('hidden'));
|
||||
MockInteractions.tap(element.$$('#suggestions li:first-child'));
|
||||
assert.isTrue(focusStub.called);
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(focusSpy.called);
|
||||
assert.isTrue(commitSpy.called);
|
||||
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
|
||||
focusStub.restore();
|
||||
focusSpy.restore();
|
||||
commitSpy.restore();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user