没有有关如何更改这些输入的文本颜色的指南https://material-ui-next.com/demos/text-fields/
我们是否仅使用外部CSS来做到这一点?
我也试过了,但是它没有通过TypeScript检查:
<TextField
inputProps={{ style: { fontFamily: 'Arial', color: 'white'}}}
style={{ flex: 1, margin: '0 20px 0 0', color: 'white'}}
onChange={(e: ChangeEvent<HTMLInputElement>) => changeSearch(e.target.value)}
type="text"
value={reducerState.search}
/>
(50,11): error TS2339: Property 'inputProps' does not exist on type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.
这可能纯粹是TypeScript类型问题
我只是用外部CSS完成的
.something input {
color: white;
}
@QuantumInformation我很高兴您找到了解决方案。 我鼓励人们这样做:
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
const styles = {
root: {
background: "black"
},
input: {
color: "white"
}
};
function CustomizedInputs(props) {
const { classes } = props;
return (
<TextField
defaultValue="color"
className={classes.root}
InputProps={{
className: classes.input
}}
/>
);
}
CustomizedInputs.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(CustomizedInputs);
https://codesandbox.io/s/1370v7y4zj
请注意,您还可以定位全局类名( .MuiInputBase-root
和.MuiInputBase-input
)。
在"@material-ui/core"
不起作用
任何更新,如何使其与@material-ui/core
? 我对此深感困惑
@pankajparkar我已经更新了以前的答案,以使用最新版本: https : https://material-ui.com/demos/text-fields/#customized -inputs中提供了一个自定义演示。
@oliviertassinari非常感谢。 我必须删除label
才能使其正常运行。
您是否有任何解决方案/解决方法可以使其与标签一起使用。 我知道标签为什么会被覆盖(我通过应用z-index
对标签进行了部分排序,但这导致了不同的问题)。
问题代码笔在这里
非常感谢你
丹,从来没有意识到我最初的回答是多么不受欢迎
@oliviertassinari非常感谢。 我必须删除
label
才能使其正常运行。
您是否有任何解决方案/解决方法可以使其与标签一起使用。 我知道标签为什么会被覆盖(我通过应用z-index
对标签进行了部分排序,但这导致了不同的问题)。问题代码笔在这里
我也需要完全一样!
最有用的评论
@QuantumInformation我很高兴您找到了解决方案。 我鼓励人们这样做:
https://codesandbox.io/s/1370v7y4zj
请注意,您还可以定位全局类名(
.MuiInputBase-root
和.MuiInputBase-input
)。