A guide on customizing the color of the icon in Material UI's NativeSelect component

I am using a NativeSelect component.

<NativeSelect
  input={<BootstrapInput/>}
  onChange={this.handleClick}
>
  <option value="1">1</option>
<NativeSelect>

Is there a way to customize the color of the dropdown button in NativeSelect?

Answer №1

Here is a demonstration illustrating how to modify the color of the ArrowDropDownIcon for different types of selects (Select, NativeSelect, TextField) in Material-UI. The icon CSS class is utilized for Select and NativeSelect (referencing https://material-ui.com/api/select/#css, https://material-ui.com/api/native-select/#css). For TextField, the global class name of the same icon CSS class is used as a descendant of the TextField root (& .MuiSelect-icon).

import React from "react";
import ReactDOM from "react-dom";
import Select from "@material-ui/core/Select";
import NativeSelect from "@material-ui/core/NativeSelect";
import MenuItem from "@material-ui/core/MenuItem";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";

const MySelect = withStyles({
  root: {
    width: 200
  },
  icon: {
    color: "red"
  }
})(Select);

const MyNativeSelect = withStyles({
  root: {
    width: 200
  },
  icon: {
    color: "purple"
  }
})(NativeSelect);

const MyTextField = withStyles({
  root: {
    "& .MuiSelect-root": {
      width: 200
    },
    "& .MuiSelect-icon": {
      color: "blue"
    }
  }
})(TextField);

function App() {
  return (
    <>
      <MySelect value="1">
        <MenuItem value="1">Select</MenuItem>
      </MySelect>
      <br />
      <MySelect native value="1">
        <option value="1">Select native</option>
      </MySelect>
      <br />
      <MyNativeSelect value="1">
        <option value="1">NativeSelect</option>
      </MyNativeSelect>
      <br />
      <MyTextField select value="1">
        <MenuItem value="1">TextField select</MenuItem>
      </MyTextField>
      <br />
      <MyTextField select SelectProps={{ native: true }} value="1">
        <option value="1">TextField select native</option>
      </MyTextField>
    </>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

https://codesandbox.io/s/select-icon-x9q9i?fontsize=14&hidenavigation=1&theme=dark

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to solve the issue of MUI Snackbar/Toast flickering during onHide event

I want to display a Snackbar/Toast when a button is clicked and then have it disappear after a few seconds. However, I'm experiencing an issue where the Snackbar flickers without any text once it disappears. How can I solve this problem? For referenc ...

Is there a method to verify the status of an onSnapshot listener?

There have been instances when I've observed that the link between the browser tab and Firestore gets disconnected for unknown reasons, leading to unsuccessful re-connection. Is there a reliable method to determine if your onSnapshot is still activel ...

Navigating the loading of information with fetch and React Hooks

As a newcomer to React and still learning JavaScript, I am facing a challenge with handling useEffect alongside an asynchronous function. My goal is to fetch data from an API and render a quote in the paragraph with id of text, along with the author's ...

Utilizing Next.js named imports without server-side rendering

I am looking to update this code snippet to use next.js dynamic imports without server-side rendering (SSR) import { widget } from "./charting_library/charting_library"; Here is what I have tried so far const widget = dynamic(() => import(&qu ...

Tips for retrieving react-cookies when CORS is restricting access

Using react-cookies, I am trying to transfer data from the client side to the server side. However, when examining the request in NodeJS, I cannot locate any cookies in the headers or elsewhere. It seems that the cookies may not have been sent. After some ...

Having difficulty with the installation of reactstrap

If you encounter issues with installing react-icons, reactstrap, and react-toastify C:\Users\Anupam K Krishnan\Desktop\React20\four-tictactoe>npm install react-icons reactstrap react-toastify npm ERR! code ERESOLVE npm ERR! ...

Adjust properties based on screen size with server-side rendering compatibility

I'm currently using the alpha branch of material-ui@v5. At the moment, I have developed a custom Timeline component that functions like this: const CustomTimeline = () => { const mdDown = useMediaQuery(theme => theme.breakpoints.down("md")); ...

Encountering Error 400 (Bad Request) After Submitting Data in MERN Stack Development

I'm encountering an issue while attempting to save products in my MERN project. Whenever I try to submit the data, I receive the following message: http://localhost:8000/api/product/create/5f4e7732333b2b21ec06a9f5 400 (Bad Request). Upon inspecting th ...

Is there a method to accurately detect the rendering of individual elements within a React Component, rather than the entire component itself?

While it's known that Components rendering can be detected through React's Developer Tool, I came across other methods in this source. However, what I'm specifically interested in is detecting the rendering of individual elements within a Co ...

The Material UI checkbox within the React hook form fails to update the isDirty state after the initial action

When using react hook form with MUI controlled checkbox within a formContext and fieldArray, the form's isDirty property does not get set on initial interaction. It only seems to update after a second action on the next checkbox. The desired behavior ...

The additional cost associated with using a React hook is called the "

Our system includes a theme context provider that passes down a theme to all child components, calculated based on the device's dimensions. We can easily access these values using the useTheme hook in any component. In addition, we have a constants f ...

The declaration file for module 'react-scroll-to-bottom' appears to be missing

I recently added react-scroll-to-bottom to my project and it is listed in my dependencies. However, I am encountering the following error: Could not find a declaration file for module 'react-scroll-to-bottom'. The path 'c:/Users/J/Desktop/w ...

How the React Component Class Executes OnChange Event in a Closure

When working on my React code, I found myself creating a closure by calling "onChange." class CityInput extends React.Component { constructor( props ){ super( props ); this.state = { city : "", country : "" ...

What is the best method for incorporating a custom font with @fontface in Storybook version 6.5.5?

I have attempted multiple online solutions to incorporate a custom font in Storybook, but unfortunately, none have been successful. Here are the files that I have added under the .storybook folder based on this guidance: webpack.config.js : const pat ...

Is there a Tiktok Icon available in the MUI library?

I'm currently attempting to dynamically add social media icons to my react website. I have successfully found icons for Facebook, Instagram, Youtube, and Twitter, but I am facing difficulty in adding the TikTok logo. Despite browsing through the MUI ...

Utilize resources from webpack's bundled npm package assets

I've been racking my brain over this issue for quite some time now, and I'm starting to wonder if it's even achievable. Any assistance on this matter would be greatly appreciated! The npm dilemma I have an npm package that serves as a coll ...

`More than one path from a single location in NextJs`

Currently, I am in the process of developing a marketing/consumer website for my company. We are making a shift away from WordPress to a combination of Next and Prismic, which is a move we are excited about. Our consumer site consists of approximately 600 ...

Is there logic in developing a web application using a combination of a NestJS backend and Next.js frontend, along with authentication features?

Currently, I am embarking on the journey of developing a web application using React and Next.js. With my previous experience in backend development using NestJS, I decided to integrate it into this project as well. However, I am unsure if separating the f ...

Navbars in Next.JS are configured to only refresh on the production server

I recently set up my Next.js project with a navbar added to the main layout.js file. Surprisingly, when I switch between routes on my local environment, nothing gets re-rendered at all. There are no network requests after the initial page load. However, u ...

Step-by-step guide on creating a personalized logic and redirecting to different pages using the useEffect hook in React or Next.js

I have recently developed a quiz application with three main pages - Junior, Senior, and SuperSenior. Depending on the selection made by the user from the dropdown menu on the homepage, I need to redirect them to the appropriate page. To achieve this func ...