From a76b3b655830392d409a4d322295ee5440d1cb0e Mon Sep 17 00:00:00 2001 From: Andrew Valleteau Date: Fri, 10 Jan 2020 16:33:28 +1000 Subject: [PATCH] =?UTF-8?q?fix(commands.type):=20Fix=20the=20.type=20comma?= =?UTF-8?q?nd=20on=20an=20input=20of=20type=20n=E2=80=A6=20(#6121)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix edge case introduced into #6033 about typing invalid number Fixes #6055 Co-authored-by: Jennifer Shehane --- packages/driver/src/cy/keyboard.ts | 3 ++- .../test/cypress/integration/commands/actions/type_spec.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/driver/src/cy/keyboard.ts b/packages/driver/src/cy/keyboard.ts index bf92fdc2929a..840c69ad5aad 100644 --- a/packages/driver/src/cy/keyboard.ts +++ b/packages/driver/src/cy/keyboard.ts @@ -263,7 +263,8 @@ const shouldUpdateValue = (el: HTMLElement, key: KeyDetails, options) => { debug('skipping inserting value since number input would be invalid', key.text, potentialValue) // when typing in a number input, only certain whitelisted chars will insert text if (!key.text.match(isValidNumberInputChar)) { - options.prevVal = '' + // https://github.com/cypress-io/cypress/issues/6055 + // Should not remove old valid values when a new one is not a valid number char, just dismiss it with return return } diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.js b/packages/driver/test/cypress/integration/commands/actions/type_spec.js index 76d6f9013054..f1942627c86d 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.js +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.js @@ -1252,6 +1252,13 @@ describe('src/cy/commands/actions/type', () => { .should('have.value', '-123.12') }) + // https://github.com/cypress-io/cypress/issues/6055 + it('can type negative numbers and dismiss invalid characters', () => { + cy.get('#number-without-value') + .type('-a42') + .should('have.value', '-42') + }) + it('can type {del}', () => { cy.get('#number-with-value') .type('{selectAll}{del}')