can't trigger 'onChange' for an input type='range' rendered by React
See original GitHub issueCurrent behavior:
...
return (
...
<div className="search-bar__form-range">
<input type="range" min={10} max={900} step={10} value={500} onChange={(event)=>alert(`slider changed
to:${event.target.value}`)}
/>
...
cy.get('.search-bar__form-range > input[type=range]').as('range').invoke('val', 700)
.trigger('change');
Changes the slider value. Doesn’t trigger the onChange handler.
Desired behavior:
should trigger the onChange handler
Steps to reproduce:
Set up a React app with an input type=‘range’ and an onChange handler Try to trigger the onChange event from cypress.
Versions
“cypress”: “^2.1.0” “react”: “^15.4.2”
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:31 (1 by maintainers)
Top Results From Across the Web
Trigger change event for React rendered input (type=range)
Ok, so I've found sort of a workaround. it looks like the onInput event can be triggered just fine. In the case of...
Read more >How to trigger onchange event on input type=range while ...
Onchange : Onchange executes a JavaScript when a user changes the state of a select element. This attribute occurs only when the element...
Read more >FAQs | React Hook Form - Simple React forms validation
React Hook Form relies on uncontrolled form, which is the reason why the register function capture ref and controlled component has its re-rendering...
Read more >Value Bubbles for Range Inputs | CSS-Tricks
Range inputs in HTML are like this: <input type="range" name="quantity" min="1" max="10">. In browsers that support them, they look like ...
Read more >Uncontrolled Components - React
In the React rendering lifecycle, the value attribute on form elements will override the value in the DOM. With an uncontrolled component, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have put together a workaround for this issue that does not require switching to the
input
event.There are two parts:
change
event on it such that React picks up the change.That works like this:
I’m fairly new to the cypress ecosystem, so perhaps someone can do this in a more cypress-y way, but this solves the problem.
It doesn’t work for TypeScript. I received the error:
Argument of type '{ value: number; bubbles: true; }' is not assignable to parameter of type 'EventInit'. Object literal may only specify known properties, and 'value' does not exist in type 'EventInit'
So I’ve solved my problem with this issue for TypeScript using the following code: In commands:
And use it in the test: