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.

OnChange not getting fired on radio button click

See original GitHub issue

I am using following code in my component, but handleChange event is not getting fired as i try to select one of the radio buttons. I have tried to update my react and react-dom version from 16.0.0 to 16.0.2.

/* eslint-disable flowtype/require-valid-file-annotation */

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Radio, { RadioGroup } from 'material-ui/Radio';
import { FormLabel, FormControl, FormControlLabel, FormHelperText } from 'material-ui/Form';

const styles = theme => ({
  root: {
    display: 'flex',
  },
  formControl: {
    margin: theme.spacing.unit * 3,
  },
  group: {
    margin: `${theme.spacing.unit}px 0`,
  },
});

class RadioButtonsGroup extends React.Component {
  state = {
    value: '',
  };

  handleChange = (event, value) => {
    debugger;
    this.setState({ value });
  };

  render() {
    const { classes } = this.props;

    return (
      <div className={classes.root}>
        <FormControl component="fieldset" required className={classes.formControl}>
          <FormLabel component="legend">Gender</FormLabel>
          <RadioGroup
            aria-label="gender"
            name="gender1"
            className={classes.group}
            value={this.state.value}
            onChange={this.handleChange}
          >
            <FormControlLabel value="male" control={<Radio />} label="male" />
            <FormControlLabel value="female" control={<Radio />} label="female" />
            <FormControlLabel value="other" control={<Radio />} label="other" />
            <FormControlLabel value="disabled" disabled control={<Radio />} label="Disabled" />
          </RadioGroup>
        </FormControl>
        
      </div>
    );
  }
}

RadioButtonsGroup.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(RadioButtonsGroup);
  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

handleChange function should execute when a user tries to click on one of the radio buttons.

Current Behavior

Nothing happens if a user tries to select a radio button and no input is shown to user

Context

Your Environment

Tech Version
Material-UI 1.0.0-beta.21
React 16.2.0
browser Chrome-62.0.3202.94
etc

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
mbrookescommented, Nov 29, 2017

@shivgarg5676 You can see this working in the docs site where it looks like your example originated, so the issue isn’t with Material-UI. Please use gitter or SO for how-to questions and issues with your own code.

6reactions
mbrookescommented, Nov 30, 2017

It’s working with React 16.1.1. The example you see running in the docs is running the code you see in the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Radio button onChange event not firing - Stack Overflow
Show activity on this post. Works by adding onClick event to the label. This is an issue when we use data-toggle="buttons", so the...
Read more >
OnChange not getting fired on radio button click #9336 - GitHub
I am using following code in my component, but handleChange event is not getting fired as i try to select one of the...
Read more >
Radio button onchange doesn't trigger following a
I have checked that both the SelectedText.Value and Selected.Value are cleared after reset and change when a radio button is selected, but this ......
Read more >
input type=radio doesn't fire onchange event for unchecking
When state is changed from checked to unchecked, no onchange event is fired. Reproducible: Always Steps to Reproduce: 1. select some input type=radio...
Read more >
Radio button OnChange event not working
But OnChange event is not working. If i use OnClick event instead of OnChange event and i click same radio button which is...
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