Merge "Fix backspace doesn't work in Polymer 2"

This commit is contained in:
Ben Rohlfs
2019-09-25 07:30:14 +00:00
committed by Gerrit Code Review
2 changed files with 43 additions and 30 deletions

View File

@@ -253,8 +253,13 @@
console.warn('received remove event for missing account', toRemove); console.warn('received remove event for missing account', toRemove);
}, },
_getNativeInput(paperInput) {
// In Polymer 2 inputElement isn't nativeInput anymore
return paperInput.$.nativeInput || paperInput.inputElement;
},
_handleInputKeydown(e) { _handleInputKeydown(e) {
const input = e.detail.input.inputElement; const input = this._getNativeInput(e.detail.input);
if (input.selectionStart !== input.selectionEnd || if (input.selectionStart !== input.selectionEnd ||
input.selectionStart !== 0) { input.selectionStart !== 0) {
return; return;

View File

@@ -417,30 +417,36 @@ limitations under the License.
}); });
suite('keyboard interactions', () => { suite('keyboard interactions', () => {
test('backspace at text input start removes last account', () => { test('backspace at text input start removes last account', done => {
const input = element.$.entry.$.input; const input = element.$.entry.$.input;
sandbox.stub(input, '_updateSuggestions'); sandbox.stub(input, '_updateSuggestions');
sandbox.stub(element, '_computeRemovable').returns(true); sandbox.stub(element, '_computeRemovable').returns(true);
flush(() => {
// Next line is a workaround for Firefix not moving cursor // Next line is a workaround for Firefix not moving cursor
// on input field update // on input field update
assert.equal(input.$.input.inputElement.selectionStart, 0); assert.equal(
element._getNativeInput(input.$.input).selectionStart, 0);
input.text = 'test'; input.text = 'test';
MockInteractions.focus(input.$.input); MockInteractions.focus(input.$.input);
flushAsynchronousOperations(); flushAsynchronousOperations();
assert.equal(element.accounts.length, 2); assert.equal(element.accounts.length, 2);
MockInteractions.pressAndReleaseKeyOn( MockInteractions.pressAndReleaseKeyOn(
input.$.input.inputElement, 8); // Backspace element._getNativeInput(input.$.input), 8); // Backspace
assert.equal(element.accounts.length, 2); assert.equal(element.accounts.length, 2);
input.text = ''; input.text = '';
MockInteractions.pressAndReleaseKeyOn( MockInteractions.pressAndReleaseKeyOn(
input.$.input.inputElement, 8); // Backspace element._getNativeInput(input.$.input), 8); // Backspace
flushAsynchronousOperations();
assert.equal(element.accounts.length, 1); assert.equal(element.accounts.length, 1);
done();
});
}); });
test('arrow key navigation', () => { test('arrow key navigation', done => {
const input = element.$.entry.$.input; const input = element.$.entry.$.input;
input.text = ''; input.text = '';
element.accounts = [makeAccount(), makeAccount()]; element.accounts = [makeAccount(), makeAccount()];
flush(() => {
MockInteractions.focus(input.$.input); MockInteractions.focus(input.$.input);
flushAsynchronousOperations(); flushAsynchronousOperations();
const chips = element.accountChips; const chips = element.accountChips;
@@ -454,6 +460,8 @@ limitations under the License.
assert.isTrue(chipsZeroSpy.calledOnce); assert.isTrue(chipsZeroSpy.calledOnce);
MockInteractions.pressAndReleaseKeyOn(chips[0], 39); // Right MockInteractions.pressAndReleaseKeyOn(chips[0], 39); // Right
assert.isTrue(chipsOneSpy.calledTwice); assert.isTrue(chipsOneSpy.calledTwice);
done();
});
}); });
test('delete', done => { test('delete', done => {