question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch onChange doesn't trigger

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alan345commented, Aug 31, 2018

Same issue. Its from my CSS where I had: Input : { height: auto!important; }

0reactions
jsieberncommented, Jan 4, 2018

I just checked in the browser using the inspect tool, the input wasn’t at width: 100%; height: 100% as it was supposed to be. But that was just me, maybe it’s something different for you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found