Switch onChange doesn't trigger
See original GitHub issueI’m see in docs inside SelectionControls an usage example of Switch with label, it’s supposed to be used like:
<FormControlLabel
control={
<Switch
checked={this.state.checkedA}
onChange={(event, checked) => this.setState({ checkedA: checked })}
/>
}
label="A"
/>
But my state never changes. To fix it I did:
<FormControlLabel
control={
<Switch
checked={this.state.enableCache}
/>
}
label="Enable cache?"
onClick={() => this.setState({ enableCache: !this.state.enableCache })}
/>
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
- When clicking it should change state
Current Behavior
- State unchanged
Steps to Reproduce (for bugs)
- Create a component with just a div
- Add a initial state for that component with value true or false
- Inside that div copy+paste this:
<FormControlLabel
control={
<Switch
checked={this.state.checkedA}
onChange={(event, checked) => this.setState({ checkedA: checked })}
/>
}
label="A"
/>
Your Environment
Tech | Version |
---|---|
Material-UI | 1.0.0-beta.25 |
React | 16.2.0 |
browser | Google Chrome |
etc |
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
OnChange function doesn't trigger when change occurs
Your component expects a handleChange but you pass it an onChange . Change onChange={this.handleChange} to handleChange={this.handleChange}.
Read more >Using Switch doesn't trigger change event #21090 - GitHub
Use the switch or the slider, no changes logged in console. Using Input will update the changes. What is expected? For the boolean...
Read more >On Change doesnt work | OutSystems
I have a ListBox. I have Destination set to - a method called - Filter_OnChange_Send_list. When a value in the List Box Changes,...
Read more >textbox onchange doesn't fire if user tabs out and value ...
3) Reopen the page with that form. 4) Change the value and leave the input-field. (onchange is fired) Go back to that field....
Read more >Primitive input onChange event does not trigger on value ...
The on change seems to trigger only once, once the input is blurred. January 12, 2021. Log in to leave a comment. Log...
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
Same issue. Its from my CSS where I had:
Input : { height: auto!important; }
I just checked in the browser using the inspect tool, the
input
wasn’t atwidth: 100%; height: 100%
as it was supposed to be. But that was just me, maybe it’s something different for you.