0

我有三个带有用户角色的单选按钮。当我单击任何单选按钮时,它没有被选中;只有单击两次单选按钮才会被选中。

我正在将 React 与 materialUI 一起使用。

下面是我的代码,

 handleRoleChange(event) {
   const newRole = event.target.value
   const companiesAccess = isPlatformUserRole(newRole) ? 'ALL' : 'SELECT'
   this.changeFormField('companiesAccess', companiesAccess)
   this.changeFormField('companyTags', []) // clear current selection
 }

 <label className={style.requiredLabel} htmlFor="role">
      <span>ROLE</span>
 </label>

 <Radio
   display="row"
   name="role"
   radioItems={options.roleOptions}
   handleClickOnRadio={this.handleRoleChange}
   readOnly={!isNew}
 />

options.roleOptions角色列表在哪里。

自定义单选按钮的代码,

const Radio = (props) => {
  let radioButtonStyle = props.display === 'column' ? radioStyleColumn : radioStyleRow
  radioButtonStyle = { ...radioButtonStyle, ...props.radioButtonStyle }

  const items = props.radioItems.map((item, index) => {
const disabled = _isUndefined(item.disabled) ? props.disabled : item.disabled
/* let checked = false
if (props.currentUser === item.value) {
  checked = true
} else {
  checked = false
}
console.log(props.currentUser+' '+item.value+' '+checked)
debugger;*/
return (<RadioButton
  key={index}
  value={item.value}
  label={item.label}
  disabled={disabled}
  style={radioButtonStyle}
  labelStyle={labelStyle}
  iconStyle={iconStyle}
  inputStyle={inputStyle}
  checkedIcon={activeRadioIcon()}
  uncheckedIcon={normalRadioIcon()}
  onClick={props.handleClickOnRadio}
/>)
})

提前致谢。

4

0 回答 0