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

Typing {{arrowUp}} should trigger event on input[type=number] #29611

Closed
Abdillah opened this issue Jun 4, 2024 · 11 comments · Fixed by #29636
Closed

Typing {{arrowUp}} should trigger event on input[type=number] #29611

Abdillah opened this issue Jun 4, 2024 · 11 comments · Fixed by #29636

Comments

@Abdillah
Copy link
Contributor

Abdillah commented Jun 4, 2024

Current behavior

Currently, get('input[type=number]').type('{{arrowUp}}') has the same behavior as calling input.stepUp() only which will not trigger any event, like when we press arrow up on the input.

Desired behavior

Typing {{arrowUp}} should be equal as pressing arrow up button on a focused number input. Pressing real arrow up button will trigger input event.

Test code to reproduce

This will not show any alert:

<input type="number" oninput="alert('Testing')" value=3>

cy.get('#a input').type('{upArrow}').should(haveValue(4))

versus

<input type="number" oninput="alert('Testing')" value=3>

cy.get('#a input').type(4).should(haveValue(4))

which will show an alert. Or try the input DOM in browser and press arrow up button.

Cypress Version

13.2.0

Node version

18.16.0

Operating System

NixOS 23.11

Debug Logs

No response

Other

No response

@thevladisss
Copy link
Contributor

Can I collaborate in resolving this bug?

@Abdillah
Copy link
Contributor Author

Abdillah commented Jun 5, 2024

Sure @thevladisss.

At initial discovery, this part seems the one responsible.

@thevladisss
Copy link
Contributor

@Abdillah I spent some time investigating this issue and it appears like your issue is quite natural, as under the hood it calls "stepUp" and "stepDown" on input type number. This method does not trigger any event on the input, unlilke clicking arrows on input type number.

@jennifer-shehane I think that {upArrow} actually implies that user clicks up arrow key, which does trigger events on the input, as it is same as clicking on the arrows. Do you beleive I can work on implementing this behavior?

@Abdillah
Copy link
Contributor Author

Abdillah commented Jun 9, 2024

Yes, that is spot on.

That doesn't match with user expectation using Cypress for real world arrow up behavior.
I believe it can be improved.

@thevladisss
Copy link
Contributor

@jennifer-shehane Can I start working on this?

@Abdillah
Copy link
Contributor Author

Abdillah commented Jun 10, 2024

Arrow up can be simulated using the following way (a work around).

const arrowDown = $el => {
    const v = parseInt($el.val())++
    cy.wrap($el).type('{selectAll}' + v)
}

const arrowDown = $el => {
    const v = parseInt($el.val())--
    cy.wrap($el).type('{selectAll}' + v)
}

cy.get('input[type=number]').then(arrowUp)
cy.get('input[type=number]').then(arrowDown)

Edited: use .type() instead of val()

@thevladisss
Copy link
Contributor

Arrow up can be simulated using the following way (a work around).

const arrowUp = $el => $el.val($e.val()++)

const arrowDown = $el => $el.val($e.val()--)



cy.get('input[type=number]').then(arrowUp)

cy.get('input[type=number]').then(arrowDown)

I think there should be a solution rather than workaround. There is certain specific behaviour about type number that cannot be just covered by adding value unfortunately

@Abdillah
Copy link
Contributor Author

Abdillah commented Jun 10, 2024

@thevladisss Actually, Cypress team has considered this as a bug, you can just create a PR and request them for review rather than waiting for them (they have lots of issue to triage). Currently I'm not available to tackle this issue but need to get things done, hence the workaround.

@Abdillah
Copy link
Contributor Author

If you need some discussion, @thevladisss, you can throw it here. I can be your second brain.

@thevladisss
Copy link
Contributor

If you need some discussion, @thevladisss, you can throw it here. I can be your second brain.

Thanks! Once I get something I will comeback here.

@jennifer-shehane jennifer-shehane added stage: needs review The PR code is done & tested, needs review and removed stage: needs investigating Someone from Cypress needs to look at this labels Jun 11, 2024
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 18, 2024

Released in 13.12.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.12.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Jun 18, 2024
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants