From 263454cfb826eeaff595aad3e6f5acd4ba1a9917 Mon Sep 17 00:00:00 2001 From: Becky Siegel Date: Thu, 12 Oct 2017 13:43:57 -0700 Subject: [PATCH] Fix autocomplete issue where you could not select initial suggestion In the reply dialog, reviewers can be suggested initialy, without any user input. There was an issue where if you try to select an initial reviewer without input, the enter did not select the item as expected. This was due to solving a different problem in I9e77e94461c99 in which enter only fires if the commit text had changed since the last commit. Since there was no previous commit, it did not change. This change addresses both issues by only firing a commit, if the dropdown is open, in the case where suggested values are a requirement. Bug: Issue 7404 Change-Id: I1a352bc4adf4166341168089003c2f467f276de2 (cherry picked from commit 297338ddf69c7bfd9eaa4759648a83ceef4ae66e) --- .../core/gr-search-bar/gr-search-bar.html | 2 +- .../shared/gr-autocomplete/gr-autocomplete.js | 16 +++------ .../gr-autocomplete/gr-autocomplete_test.html | 35 +++++++++++-------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html index 6a6036325a..6208e78403 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html @@ -53,7 +53,7 @@ limitations under the License. text="{{_inputVal}}" query="[[query]]" on-commit="_handleInputCommit" - allowNonSuggestedValues + allow-non-suggested-values multi borderless threshold="[[_threshold]]" 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 18c811d9a5..092f859c18 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js @@ -68,6 +68,7 @@ value: 1, }, + allowNonSuggestedValues: Boolean, borderless: Boolean, disabled: Boolean, @@ -138,22 +139,12 @@ /** The DOM element of the selected suggestion. */ _selected: Object, - - _textChangedSinceCommit: { - type: Boolean, - value: false, - }, }, observers: [ - '_textChanged(text)', '_maybeOpenDropdown(_suggestions, _focused)', ], - _textChanged() { - this._textChangedSinceCommit = true; - }, - attached() { this.listen(document.body, 'tap', '_handleBodyTap'); }, @@ -298,8 +289,9 @@ * @param {boolean=} opt_tabComplete */ _handleInputCommit(opt_tabComplete) { - // Nothing to do if new input hasn't been entered. - if (!this._textChangedSinceCommit) { return; } + // Nothing to do if the dropdown is not open. + if (!this.allowNonSuggestedValues + && this.$.suggestions.isHidden) { return; } this._selected = this.$.suggestions.getCursorTarget(); this._commit(opt_tabComplete); 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 fdfcddb541..5bb1d2b878 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 @@ -303,28 +303,35 @@ limitations under the License. assert.isTrue(openStub.calledOnce); }); - test('changing input sets _textChangedSinceCommit', () => { - element._textChangedSinceCommit = false; - element.text = 'foo bar baz'; - assert.isTrue(element._textChangedSinceCommit); - }); - - test('_handleInputCommit with no change does nothing', () => { + test('_handleInputCommit with autocomplete hidden does nothing without' + + 'without allowNonSuggestedValues', () => { const commitStub = sandbox.stub(element, '_commit'); - element._textChangedSinceCommit = false; + element.$.suggestions.isHidden = true; element._handleInputCommit(); assert.isFalse(commitStub.called); }); - test('_textChangedSinceCommit reset after commit', () => { - element._textChangedSinceCommit = true; - element._commit(); - assert.isFalse(element._textChangedSinceCommit); + test('_handleInputCommit with autocomplete hidden with' + + 'allowNonSuggestedValues', () => { + const commitStub = sandbox.stub(element, '_commit'); + element.allowNonSuggestedValues = true; + element.$.suggestions.isHidden = true; + element._handleInputCommit(); + assert.isTrue(commitStub.called); }); - test('_handleInputCommit with change to text', () => { + test('_handleInputCommit with autocomplete open calls commit', () => { const commitStub = sandbox.stub(element, '_commit'); - element._textChangedSinceCommit = true; + element.$.suggestions.isHidden = false; + element._handleInputCommit(); + assert.isTrue(commitStub.calledOnce); + }); + + test('_handleInputCommit with autocomplete open calls commit' + + 'with allowNonSuggestedValues', () => { + const commitStub = sandbox.stub(element, '_commit'); + element.allowNonSuggestedValues = true; + element.$.suggestions.isHidden = false; element._handleInputCommit(); assert.isTrue(commitStub.calledOnce); });