【发布时间】:2018-12-30 18:40:33
【问题描述】:
我在将材质 UI RadioGroup 与组件返回的 FormControlLabels 结合使用时遇到问题。
目前我试试这个:
<FormControl component="fieldset">
<RadioGroup
row
name="genreSelection"
className="genre-wrapper"
value={this.state.selection}
onChange={this.handleRadioSelection}
>
{
this.state.genres.map(genre => (
<GenreItem key={genre} label={genre} radioButton/>
))
}
</RadioGroup>
</FormControl>
而GenreItem的渲染函数是这样的:
if (this.props.radioButton) {
return (
<FormControlLabel
value={this.props.label}
label={this.props.label}
control={
<Radio/>
}
className="genre-item"
/>
);
}
// Another return here
我的问题是 FormControlLabel 无法正常工作,因为 "handleRadioSelection" 没有在任何选择上触发。
现在我发现从 Radio 元素生成的 input 元素没有 name="genreSelection" 作为属性,这意味着它不属于上面定义的 RadioGroup。
如果我将 FormControlLabel 从 GenreItem 中直接放入 this.state.genres.map 函数中,一切正常。
是我做错了什么还是这只是材质 UI 的限制?
【问题讨论】:
标签: reactjs material-ui