如何在 TimePicker 禁用时更改字体颜色 – MUI React

huangapple go评论79阅读模式
英文:

How to change fontColor when TimePicker is disabled- MUI React

问题

我试图在 TimePicker 中将文本颜色设置为另一种颜色,但没有成功。有谁知道如何使用 sx 或 slotProps 来更改它吗?这是我的当前代码。

<TimePicker
  disabled={true} // 在此处禁用
  ampm={false}
  views={['hours', 'minutes', 'seconds']}
  sx={{
    backgroundColor: "#333335",
    font: "white",
    color: "#FFFF",
    textDecoration: "bold",
    input: {
      color: "#FFFF",
      fontSize: "1.4rem",
    }
  }}
  slotProps={{
    popper: {
      sx: {
        "& .MuiList-root": {
          backgroundColor: "#333335",
        },
        "& .MuiMenuItem-root": {
          "&.Mui-selected": {
            backgroundColor: "#04395E",
            color: "white"
          },
          color: "white"
        },
      },
    },
  }}
  value={selectedTime}
  onChange={(newTime: any) => setSelectedTime(newTime)}
  timeSteps={{ hours: 1, minutes: 1, seconds: 1 }}
/>

如何在 TimePicker 禁用时更改字体颜色 – MUI React

英文:

I'm trying to set another color to the text in TimePicker when it is disabled, but with no success. Does anyone knows how to do change it using sx or slotProps? Here is my current code.

&lt;TimePicker
          disabled={true} // disabled here
          ampm={false}
          views={[&#39;hours&#39;, &#39;minutes&#39;, &#39;seconds&#39;]}
          sx={{
            backgroundColor: &quot;#333335&quot;,
            font: &quot;white&quot;,
            color: &quot;#FFFF&quot;,
            textDecoration: &quot;bold&quot;,
            input: {
              color: &quot;#FFFF&quot;,
              fontSize: &quot;1.4rem&quot;,
            }
          }}
          slotProps={{
            popper: {
              sx: {
                &quot;&amp; .MuiList-root&quot;: {
                  backgroundColor: &quot;#333335&quot;,
                },
                &quot;&amp; .MuiMenuItem-root&quot;: {
                  &quot;&amp;.Mui-selected&quot;: {
                    backgroundColor: &quot;#04395E&quot;,
                    color: &quot;white&quot;
                  },
                  color: &quot;white&quot;
                },
               
              },
            },
          }}
          value={selectedTime}
          onChange={(newTime: any) =&gt; setSelectedTime(newTime)}
          timeSteps={{hours: 1, minutes: 1, seconds: 1}}
/&gt;

如何在 TimePicker 禁用时更改字体颜色 – MUI React

答案1

得分: 2

The placeholder is styled using the -webkit-text-fill-color property. Also, it has an opacity of .42 by default so any color will be semi-transparent, unless you set the opacity back to 1:

&lt;TimePicker
  sx={{
    input: {
      &#39;&amp;.Mui-disabled&#39;: {
        WebkitTextFillColor: &#39;#FFF&#39;,
        opacity: 1
      }
    }
  }}
/&gt;

Demo.

英文:

The placeholder is styled using the -webkit-text-fill-color property. Also, it has an opacity of .42 by default so any color will be semi-transparent, unless you set the opacity back to 1:

&lt;TimePicker
  sx={{
    input: {
      &#39;&amp;.Mui-disabled&#39;: {
        WebkitTextFillColor: &#39;#FFF&#39;,
        opacity: 1
      }
    }
  }}
/&gt;

Demo.

huangapple
  • 本文由 发表于 2023年8月4日 06:48:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76832013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定