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 297338ddf6)
This commit is contained in:
Becky Siegel
2017-10-12 13:43:57 -07:00
committed by David Pursehouse
parent 203f0e444e
commit 263454cfb8
3 changed files with 26 additions and 27 deletions

View File

@@ -53,7 +53,7 @@ limitations under the License.
text="{{_inputVal}}"
query="[[query]]"
on-commit="_handleInputCommit"
allowNonSuggestedValues
allow-non-suggested-values
multi
borderless
threshold="[[_threshold]]"

View File

@@ -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);

View File

@@ -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);
});