我需要对 Redux 表单字段的标签应用一些样式。 Redux Form API 没有提到任何方式来设置标签的样式。 classes.formField
类被应用到字段本身而不是标签。
这也可能是一个关于强制继承的问题,因为在这种情况下,标签没有继承父级的样式。
import { Field } from 'redux-form'
import TextField from 'redux-form-material-ui/lib/TextField'
<Field
className={classes.formField}
component={TextField}
label={'style me!!'}
fullWidth
name="answer"
required
type="text"
validate={[required]}
/>
最佳答案
添加您自己的 <CustomLabel />
标签 Prop 的组件。
<Field
className={classes.formField}
component={TextField}
label={<CustomLabel/>}
fullWidth
name="answer"
required
type="text"
validate={[required]}
/>
制作自定义标签组件并传递给它
const CustomLabel = () => {
var labelStyle = {
color: 'white',
};
return <label style={labelStyle}> Im the custom label with css </label>
}
In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version of the style name, and whose value is the style's value, usually a string.
关于css - Style Redux Form 'Field' 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49392535/