Material UI单选按钮组默认选中多个值
Material UI Radio button group default multiple values selected
<RadioButtonGroup
name={currentQuestion.id.toString()}
onChange={this.onRadioBtnClick}
valueSelected={answerObject ? answerObject.answer : ''}
>
嘿,我的问题是;我知道道具 valueSelected select 是该特定值的单选按钮。但我想知道如何 select 多个单选按钮。这样做的依据或逻辑是什么?
谢谢。
Material UI 不允许你 select 多个单选按钮,如果不出意外,单选按钮组的简单原因应该只允许一个 select一次离子。
根据MDN...
A group of radio buttons. Only one radio button inside the group can
be selected at a time.
并且 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.`);
}
}
我建议为多个 select 离子使用一个复选框。
<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)
}
<RadioButtonGroup
name={currentQuestion.id.toString()}
onChange={this.onRadioBtnClick}
valueSelected={answerObject ? answerObject.answer : ''}
>
嘿,我的问题是;我知道道具 valueSelected select 是该特定值的单选按钮。但我想知道如何 select 多个单选按钮。这样做的依据或逻辑是什么? 谢谢。
Material UI 不允许你 select 多个单选按钮,如果不出意外,单选按钮组的简单原因应该只允许一个 select一次离子。
根据MDN...
A group of radio buttons. Only one radio button inside the group can be selected at a time.
并且 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.`);
}
}
我建议为多个 select 离子使用一个复选框。
<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)
}