简体   繁体   English

使用 mui 在 React 中更改 TextareaAutosize 颜色

[英]Change TextareaAutosize color in React with mui

I'm new at React and using mui components.我是 React 的新手,正在使用 mui 组件。

While I'm trying to set color to TextareaAutosize mui component with code like this:当我尝试使用如下代码将颜色设置为 TextareaAutosize mui 组件时:

import * as React from 'react';
import TextareaAutosize from '@mui/material/TextareaAutosize';
import { blue } from '@mui/material/colors';

export default function EmptyTextarea() {
  return (
    <TextareaAutosize
      aria-label="empty textarea"
      placeholder="Empty"
      style={{ width: 200, color: blue, background: blue}}
      //Also not works: color="{blue}"
    />
  );
}

the color of the component not changed.组件的颜色没有改变。

Thanks a lot!非常感谢!

<TextareaAutosize /> renders a plain HTMLTextAreaElement . <TextareaAutosize />呈现一个普通的HTMLTextAreaElement

Which means this CSS will work:这意味着这个 CSS 可以工作:

textarea {
  background-color: #222;
  color: #BADA55;
}

Working demo: https://codesandbox.io/s/maxheighttextarea-material-demo-forked-5hc8nv?file=/index.css工作演示: https ://codesandbox.io/s/maxheighttextarea-material-demo-forked-5hc8nv?file=/index.css

If you want to scope the CSS to your particular instance, give it an id and use it in the CSS selector.如果您想将 CSS 限定到您的特定实例,请给它一个id并在 CSS 选择器中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM