Merge "Fix backspace doesn't work in Polymer 2"
This commit is contained in:
		| @@ -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; | ||||||
|   | |||||||
| @@ -417,43 +417,51 @@ 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); | ||||||
|         // Next line is a workaround for Firefix not moving cursor |         flush(() => { | ||||||
|         // on input field update |           // Next line is a workaround for Firefix not moving cursor | ||||||
|         assert.equal(input.$.input.inputElement.selectionStart, 0); |           // on input field update | ||||||
|         input.text = 'test'; |           assert.equal( | ||||||
|         MockInteractions.focus(input.$.input); |               element._getNativeInput(input.$.input).selectionStart, 0); | ||||||
|         flushAsynchronousOperations(); |           input.text = 'test'; | ||||||
|         assert.equal(element.accounts.length, 2); |           MockInteractions.focus(input.$.input); | ||||||
|         MockInteractions.pressAndReleaseKeyOn( |           flushAsynchronousOperations(); | ||||||
|             input.$.input.inputElement, 8); // Backspace |           assert.equal(element.accounts.length, 2); | ||||||
|         assert.equal(element.accounts.length, 2); |           MockInteractions.pressAndReleaseKeyOn( | ||||||
|         input.text = ''; |               element._getNativeInput(input.$.input), 8); // Backspace | ||||||
|         MockInteractions.pressAndReleaseKeyOn( |           assert.equal(element.accounts.length, 2); | ||||||
|             input.$.input.inputElement, 8); // Backspace |           input.text = ''; | ||||||
|         assert.equal(element.accounts.length, 1); |           MockInteractions.pressAndReleaseKeyOn( | ||||||
|  |               element._getNativeInput(input.$.input), 8); // Backspace | ||||||
|  |           flushAsynchronousOperations(); | ||||||
|  |           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()]; | ||||||
|         MockInteractions.focus(input.$.input); |         flush(() => { | ||||||
|         flushAsynchronousOperations(); |           MockInteractions.focus(input.$.input); | ||||||
|         const chips = element.accountChips; |           flushAsynchronousOperations(); | ||||||
|         const chipsOneSpy = sandbox.spy(chips[1], 'focus'); |           const chips = element.accountChips; | ||||||
|         MockInteractions.pressAndReleaseKeyOn(input.$.input, 37); // Left |           const chipsOneSpy = sandbox.spy(chips[1], 'focus'); | ||||||
|         assert.isTrue(chipsOneSpy.called); |           MockInteractions.pressAndReleaseKeyOn(input.$.input, 37); // Left | ||||||
|         const chipsZeroSpy = sandbox.spy(chips[0], 'focus'); |           assert.isTrue(chipsOneSpy.called); | ||||||
|         MockInteractions.pressAndReleaseKeyOn(chips[1], 37); // Left |           const chipsZeroSpy = sandbox.spy(chips[0], 'focus'); | ||||||
|         assert.isTrue(chipsZeroSpy.called); |           MockInteractions.pressAndReleaseKeyOn(chips[1], 37); // Left | ||||||
|         MockInteractions.pressAndReleaseKeyOn(chips[0], 37); // Left |           assert.isTrue(chipsZeroSpy.called); | ||||||
|         assert.isTrue(chipsZeroSpy.calledOnce); |           MockInteractions.pressAndReleaseKeyOn(chips[0], 37); // Left | ||||||
|         MockInteractions.pressAndReleaseKeyOn(chips[0], 39); // Right |           assert.isTrue(chipsZeroSpy.calledOnce); | ||||||
|         assert.isTrue(chipsOneSpy.calledTwice); |           MockInteractions.pressAndReleaseKeyOn(chips[0], 39); // Right | ||||||
|  |           assert.isTrue(chipsOneSpy.calledTwice); | ||||||
|  |           done(); | ||||||
|  |         }); | ||||||
|       }); |       }); | ||||||
|  |  | ||||||
|       test('delete', done => { |       test('delete', done => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ben Rohlfs
					Ben Rohlfs