How to change text color of mui select in react js?
February 19, 2023Hi Friends 👋,
Welcome To aGuideHub!
To change text color of mui select in React js, you can use DefaultValue="option1"
to sx={{ color: "red" }}
. It will change text color of mui select in React js.
Today, I am going to show you, how to change text color of mui select in react js.
Installation
Install the following packages to use change text color of mui select in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
MUI material change text color of mui select example.
The below code is an example of To change the color of text in a select
element, inside this code, Use CSS Style sx={{ color: "red" }}
in select mui.
App.js
import { Select, MenuItem } from "@mui/material";
const options = [
{ value: "option1", label: "Option 1" },
{ value: "option2", label: "Option 2"},
{ value: "option3", label: "Option 3" }
];
export default function MySelect() {
return (
<Select
defaultValue="option1"
sx={{ color: "red" }} // set the text color to red
>
{options.map((option) => (
<MenuItem
key={option.value}
value={option.value}
disabled={option.disabled}
>
{option.label}
</MenuItem>
))}
</Select>
);
}
In the above code example, I have used the @mui/material
component and change text color of mui select.
Check the output of the above code example.
Here, we are provided code sandbox links for the above program change text color of mui select. Then you can use whenever you want and do the changes as per your requirements.
All the best 👍