Fix: select doesn't work in gr-autocomplete
In Polymer 2 selectAll doesn't work, because inputElement is not a native input. nativeInput is a replacement for Polymer 2. Bug: Issue 11585 Change-Id: Ib22164cc33d387013b10d6c679626b3825030002
This commit is contained in:
@@ -177,6 +177,11 @@
|
||||
'_updateSuggestions(text, threshold, noDebounce)',
|
||||
],
|
||||
|
||||
get _nativeInput() {
|
||||
// In Polymer 2 inputElement isn't nativeInput anymore
|
||||
return this.$.input.$.nativeInput || this.$.input.inputElement;
|
||||
},
|
||||
|
||||
attached() {
|
||||
this.listen(document.body, 'tap', '_handleBodyTap');
|
||||
},
|
||||
@@ -195,7 +200,7 @@
|
||||
},
|
||||
|
||||
selectAll() {
|
||||
const nativeInputElement = this.$.input.inputElement;
|
||||
const nativeInputElement = this._nativeInput;
|
||||
if (!this.$.input.value) { return; }
|
||||
nativeInputElement.setSelectionRange(0, this.$.input.value.length);
|
||||
},
|
||||
|
||||
@@ -82,16 +82,19 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('selectAll', () => {
|
||||
const nativeInput = element.$.input.inputElement;
|
||||
const selectionStub = sandbox.stub(nativeInput, 'setSelectionRange');
|
||||
test('selectAll', done => {
|
||||
flush(() => {
|
||||
const nativeInput = element._nativeInput;
|
||||
const selectionStub = sandbox.stub(nativeInput, 'setSelectionRange');
|
||||
|
||||
element.selectAll();
|
||||
assert.isFalse(selectionStub.called);
|
||||
element.selectAll();
|
||||
assert.isFalse(selectionStub.called);
|
||||
|
||||
element.$.input.value = 'test';
|
||||
element.selectAll();
|
||||
assert.isTrue(selectionStub.called);
|
||||
element.$.input.value = 'test';
|
||||
element.selectAll();
|
||||
assert.isTrue(selectionStub.called);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('esc key behavior', done => {
|
||||
|
||||
Reference in New Issue
Block a user