Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress does not type commas into number inputs #30411

Open
Natrocx opened this issue Oct 16, 2024 · 3 comments
Open

Cypress does not type commas into number inputs #30411

Natrocx opened this issue Oct 16, 2024 · 3 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this topic: cy.type ⌨️

Comments

@Natrocx
Copy link

Natrocx commented Oct 16, 2024

Current behavior

Currently cypress actively prevents typing commas into inputs of the type "number". As this is the decimal separator in some languages/locales like German, this prevents accurate testing in the way a user might interact with the page.
There is a regex which prevents such inputs:

const isValidNumberInputChar = /[-+eE\d\.]/

Desired behavior

As far as I am aware, there is no reason to prevent a comma from being typed into a number input. Indeed the HTML specification itself suggests that the "user agent"/browser should allow such inputs and convert them internally (which is indeed what Chrome does in my case when I manually type into the inputs) https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number).
I am unsure about how much of the browser's validation can actually be used in this case since the implementation does not always simulate key presses, and the implementation details of converting the number input's values differs between browsers but there should be a way to type the characters mentioned in the spec regardless of their validity in the context of a en-US locale input (maybe with force: true if there is no other way).

Test code to reproduce

There is no need to reproduce this as the issue is not unexpected behaviour.

Cypress Version

v13.15.0

Node version

v22.7.0

Operating System

Any

Debug Logs

No response

Other

Someone familiar with the implementation should consider whether it is safe to remove or extend (with commas etc.) the validation regex in every case and either do so or add a way to ignore the regex.

@nsbarsukov
Copy link
Contributor

@Natrocx
Copy link
Author

Natrocx commented Oct 18, 2024

Also this issue from 2020 describes the bug:
#7775

@Natrocx
Copy link
Author

Natrocx commented Oct 18, 2024

Maybe @kuceb would like to comment on why this regex is necessary.
As far as I understand, it should not cause problems to just emit events for invalid keys when using simulated key events since it is the browsers job to filter these out on submission or when receiving the key events.

I further don't understand what this line is supposed to do:

options.simulated = true

It appears the simulated property of the typeoptions is set but never read from. Maybe this is the legacy of an older typing mechanism?

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this topic: cy.type ⌨️ labels Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this topic: cy.type ⌨️
Projects
None yet
Development

No branches or pull requests

3 participants