MaterialUI-更改焦点上的颜色文本字段 [英] MaterialUI - Changing the color Textfield on focus

查看:106
本文介绍了MaterialUI-更改焦点上的颜色文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Textfield中更改标签文本的颜色,但似乎无法弄清楚.

I'm trying to change the color of the label text in Textfield but I can't seem to figure it out.

这是我正在尝试的:

<TextField
    value={value}
    key={name}
    label={label}
    id={id}
    name={name}
    InputLabelProps={{
      shrink: true,
      FormLabelClasses: {
        'root': {
          '&:focused': {
            color: 'white'
          }
        },
        focused: 'true'
      }
    }}
  />

有人可以帮我指出我在这里做错了什么吗?

Can someone give me a pointer on what I'm doing wrong here?

我也尝试过使用MuiThemeProvider,但似乎也无法找出其中一个:

I've also tried using the MuiThemeProvider but can't seem to figure that one out either:

const theme = createMuiTheme({
  overrides: {
    MuiFormLabel: {
      focused: true,
      root: {
        '&.focused': {
          color: 'white'
        }
      }
    }
  }
});

如何更改标签的颜色?在这张照片中,我希望注释"与下划线的颜色匹配

How can I change the color of the Label? In this photo, I want the "Notes" to match the color of the underline

感谢您的帮助!

推荐答案

提姆! 这是应该会帮助您的代码段.

Tim! Here is the snippet that should help you.

const {
  TextField,
  createMuiTheme,
  MuiThemeProvider,
  CssBaseline,
} = window['material-ui'];

const theme = createMuiTheme({
  overrides: {
    MuiFormLabel: {
      root: {
        "&$focused": {
          color: "tomato",
          fontWeight: "bold"
        }
      }, 
      
      focused: {}
    }
  }
});

class Index extends React.Component {  
  render() {
    return (
      <MuiThemeProvider theme={theme}>
        <div>
          <CssBaseline />
          <TextField label="Text field" InputLabelProps={{shrink:true}} />
        </div>
      </MuiThemeProvider>
    );
  }
}

ReactDOM.render(<Index />, document.getElementById('root'));

    <script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/@material-ui/core/umd/material-ui.development.js" crossorigin="anonymous"></script>

<div id="root"></div>

这篇关于MaterialUI-更改焦点上的颜色文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆