材质UI单选按钮组默认选择多个值

时间:2016-11-22 00:35:20

标签: reactjs material-ui



<RadioButtonGroup
    name={currentQuestion.id.toString()}
    onChange={this.onRadioBtnClick}
    valueSelected={answerObject ? answerObject.answer : ''}
 >
&#13;
&#13;
&#13;

嘿,我的问题是;我知道prop valueSelected选择该特定值的单选按钮。但我想知道如何选择多个单选按钮。那个道具或逻辑是什么? 感谢。

2 个答案:

答案 0 :(得分:1)

材质用户界面不允许您选择多个单选按钮,如果没有别的话,因为单选按钮组的简单原因应该一次只允许一个选择。

根据MDN ...

  

一组单选按钮。组内只有一个单选按钮   一次选择。

Material UI库updateRadioButtons方法确认这是不可能的......

updateRadioButtons(newSelection) {
  if (this.state.numberCheckedRadioButtons === 0) {
    this.setState({selected: newSelection});
  } else {
    warning(false, `Material-UI: Cannot select a different radio button while another radio button
      has the 'checked' property set to true.`);
  }
}

我建议使用复选框进行多项选择。

答案 1 :(得分:0)

<RadioButtonGroup name="Relations" style={{ display: 'flex' }} 
  valueSelected={this.props.RELATIONSHIP_ID}    
  value={this.props.RELATIONSHIP_ID}
  onChange={this.handleRadioButtonToggle}>
{
  this.props.relations.map( (key, index) => (
    <RadioButton value={key['RELATIONSHIP_ID']} 
    label={key['RELATIONSHIP_TYPE']}
    style={styles.radioButton}/>))
}
</RadioButtonGroup>
handleRadioButtonToggle=(e,value)=>{
console.log('radio',e,value)
}