【发布时间】:2021-01-19 13:12:51
【问题描述】:
我的 material-ui 单选按钮最初可以工作,但是当我使用 react-final-form 实现时,我可以工作。现在的问题是该单选按钮根本不可点击,但是当我删除 inputProps 内的 ...input 单选按钮时有效。
我知道有一个 material-ul react-final-form 包装器https://github.com/Deadly0/final-form-material-ui,但我现在不想使用它。
有什么帮助吗?
import { Box, Typography } from '@material-ui/core'
import { useCallback, useState } from 'react'
import { useContext } from '/form-context'
import { Field } from 'react-final-form'
const GetFruitFav = () => {
const { values, setValues } = useContext()
const { favFruits = 'orange' } = values || {}
const [food, setFood] = useState(favFruits)
const handleBtn = useCallback(
(value) => {
setFood(value)
},
[setFood]
)
return (
<div>
<Field
name="food"
type="radio"
render={({ input, meta }) => (
<StyledRadioBox>
<StyledRadioButton
checked={food === 'orange'}
onChange={() => handleBtn('orange')}
value="orange"
name="orange"
inputProps={{
'aria-label': 'orange',
...input,
}}
/>
</StyledRadioBox>
)}
/>
<Field
name="food"
type="radio"
render={({ input, meta }) => (
<>
<StyledRadioBox>
<StyledRadioButton
checked={food === 'grapes'}
onChange={() => handleBtn('grapes')}
value="grapes"
name="grapes"
inputProps={{
'aria-label': 'grapes',
...input,
}}
/>
</StyledRadioBox>
</>
)}
/>
</div>
)
}
【问题讨论】:
标签: javascript reactjs material-ui react-final-form