react 替换标签内容_如何在React中更改Material-UI Textfield标签样式

I'm new to Material-UI, I couldn't able to figure it out, how to change the color of the label which is showing in grey color. I want it in black. Can anyone help me with this query?

Here is the Code :

import React from "react";

import ReactDOM from "react-dom";

import { TextField, Button, Grid } from "@material-ui/core";

class App extends React.Component {

render() {

return (

id="outlined-name"

label="Name"

value={"Enter value"}

onChange={() => console.log("I was changed")}

margin="normal"

variant="outlined"

/>

Submit

);

}

}

解决方案

If you use the selection tools in your browser, you would find out that:

The class name used is MuiFormLabel-root

Name

So set the styles using nesting selector to the TextField component

Functional component

import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles(theme => ({

root: {

"& .MuiFormLabel-root": {

color: "red" // or black

}

}

}));

...

const classes = useStyles();

Classical component

import { withStyles, createStyles } from "@material-ui/core/styles";

const styles = theme => createStyles({

root: {

"& .MuiFormLabel-root": {

color: "red"

}

}

});

...

const { classes } = this.props;

...

export default withStyles(styles)(App);

usage

className={classes.root}

...

>

By this way, you can change the label color, as the screenshot is shown below (currently red)

Try it online:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值