Close autocomplete suggestions on tap When autocompletion "commits" a value, it should always clear the list of suggestions and hide it from view. This change moves that logic from the individual event handlers into _commit, so this now occurs on tap. Also refocuses on the input after a suggestion is tapped so the user can continue typing. Bug: Issue 4473 Change-Id: If0343b38bcc61a49fcca2fb5eabea09a7b36fdd6
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js index 467acb7..45d55eb 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js
@@ -200,13 +200,11 @@ if (this._suggestions.length > 0) { e.preventDefault(); this._commit(this.tabCompleteWithoutCommit); - this._suggestions = []; } break; case 13: // Enter e.preventDefault(); this._commit(); - this._suggestions = []; break; } }, @@ -245,6 +243,7 @@ _handleSuggestionTap: function(e) { this.$.cursor.setCursor(e.target); this._commit(); + this.focus(); }, /** @@ -275,6 +274,7 @@ } } + this._suggestions = []; if (!silent) { this.fire('commit', {value: value}); }
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html index 63c1b3c..c87521e 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html
@@ -271,5 +271,16 @@ assert.isTrue(element._computeSuggestionsHidden(suggestions, false)); assert.isFalse(element._computeSuggestionsHidden(suggestions, true)); }); + + test('tap on suggestion commits and refocuses on input', function() { + var focusStub = sinon.stub(element, 'focus'); + 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); + assert.isTrue(element.$.suggestions.hasAttribute('hidden')); + focusStub.restore(); + }); }); </script>