Customize the arrow color in a TextField Select component from material-ui

Having some trouble changing the color of my arrow icon within the Material-ui TextField Select.

Here's what I've tried:

icon: {
    fill: "white !important",
  },

Despite applying these props, the color remains unchanged. I've experimented with various solutions from online resources but to no avail. The input props with the icon seem to be ineffective.

<TextField
          id="outlined-select-currency"
          select
          label={label}
          name={this.props.name}
          className={classNames(this.props.classes.textField)}
          onChange={(e) => this.props.handleChange(e)}
          value={this.props.value}
          SelectProps={{
            MenuProps: {
              className: this.props.classes.menu,
              icon: "white !important"
            }
          }}
          InputLabelProps={{
            classes: {
              root: this.props.overrideCssLabel,
              focused: this.props.overrideCssFocusLabel,
              icon: {
                color: "white !important"
              }
            },
          }}
          InputProps={{
            classes: {
              root: this.props.overrideCssInputRoot,
              focused: this.props.overrideCssInputFocus,
              notchedOutline: this.props.overrideCssInputNotchedOutline,
              icon: this.props.icon
            },
            style: {
              color: this.props.color
            },
          }}
          margin="normal"
          variant="outlined"
        >
          {selectList.map(option => (
            <MenuItem key={option.value} value={option.value}>
              {option.label}
            </MenuItem>
          ))}
        </TextField>

Answer №1

To tackle this issue, you can utilize the classes section of SelectProps and pass them in like this:

import React, { FunctionComponent } from 'react';
import TextField from '@material-ui/core/TextField';
import { makeStyles } from '@material-ui/core/styles';

type Props = {
  someProps: any
};

const useStyles = makeStyles({
  icon: {
    color: 'white',
  },
});

const CustomTextInput: FunctionComponent<Props> = ({
  ...someProps
}) => {
  const classes = useStyles();
  return (
    <TextField
      {...someProps}
      select
      SelectProps={{
        classes: { icon: classes.icon },
      }}
    />
  );
};

export default CustomTextInput;

For a comprehensive list of SelectProps, refer to https://material-ui.com/api/select/. Additionally, visit https://material-ui.com/api/select/#css for an inventory of CSS class names available for the classes option.

Answer №2

Including the following code snippet in the sx prop will also have an impact:

'& .MuiSvgIcon-root': {
    color: 'white',
 }

Answer №3

<TextField
  select
  fullWidth
  label={t(Translation.PAGE_INPUT_RESULTS_TEST_MEASUREMENT_LIST_FIELD_NAME_RESULT)}
  sx={{
       "& .MuiSvgIcon-root": {
            color: (theme) => theme.palette.primary.main
        }
                  }}
                >

Answer №4

After trying various methods, I ended up using CSS style to override the default settings. Even though it's a css style, you can still use !important to ensure proper styling (although I'm not entirely certain about the color variable).

<HeartIcon color="primary" style={{ color: theme.palette.primary.main }} />

Below is an example of how I implemented an icon in a Textfield:

<TextField
 placeholder="Type your message"
 endAdornment={(
  <InputAdornment position="end">
     <Box className="d-flex align-items-center">
     <IconButton onClick={() => { console.log('attachment..');}} sx={{ mr: -1.25 }}>
                      <AttachIcon style={{ color: theme.palette.primary.main }} />
                    </IconButton>
                    <IconButton onClick={() => {console.log('sent..');}}>
                      <HeartIcon color="primary" style={{ color: theme.palette.primary.main }} />
                    </IconButton>
                  </Box>
                </InputAdornment>
                )}
            />

Answer №5

Simply get rid of the quotation marks.

icon: {
    fill: white !important
  }

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

Issue found in Bootstrap-Multiselect plugin: The dropdown menu appears beneath the outer container when overflow-y is applied

My experience with using Bootstrap-Multiselect and encountering an issue where the dropdown disappears when the outer container has overflow-y: scroll and a max-height has prompted me to seek solutions. I am looking for a way to ensure that the dropdown is ...

Make sure that your inline-block elements are aligned with both the left and right edges of their

Explaining what I'm attempting can be a bit tricky, but I'll do my best. I have X number of categories that I need to organize. Each category needs to be enclosed in a box with a grey border. I want the category boxes to be displayed "inline-bl ...

I am unable to make any changes to the .navbar and #navbar elements using CSS

I'm having trouble customizing the navigation bar using .navbar and #navbar in CSS. I was hoping to make changes to the Bootstrap navbar, but nothing seems to be working. I'm not sure if it's an issue with the HTML or CSS. I've include ...

Refresh Search Suggestions in React Material Design Interface

Is there a way to reset the state_id when I select a value from the Autocomplete for city_id? Currently, it doesn't clear out automatically. If you want to see the code in action, please click on the link below: CLICK HERE CODE <Autocomple ...

What is the best way to spin a div HTML layer?

I'm trying to modify a Div layer that looks like this: ... <style type="text/css"> <!-- #newImg { position:absolute; left:180px; top:99px; width:704px; height:387px; z-index:1; background-image:url(../Pictures/rep ...

Ways to display an image overlay on hover using sprite sheets

Is there a way to make a line appear, around 10px in size, when hovering over an image at the bottom of that image? I came across this effect on MTV's website within their "You would also like these" section below each post. They utilized css-backgro ...

I am in search of a clean and efficient method to modify the class of a link that triggers an HTMX request in Django. Perhaps something like "auto-refresh" or a similar solution would be ideal

I've encountered an issue with HTMX in Django. The page consists of two main components: a list of categories and the content that is displayed when a category is clicked. Initially, everything was working smoothly with standard htmx functionality. H ...

There appears to be an empty void on the website

If you could kindly click on this link & use CTRL + F to search for the text "Info", you will see a visual representation similar to the image below. There seems to be quite a bit of empty space below these texts. I experimented with padding, display: ...

Controlling the back DIV while maintaining overlapping layers

I successfully positioned my right hand content on top of the leaflet map in the background using CSS properties like position and z-index. However, I am looking for a way to make the overlapping div not only transparent but also non-interactive while stil ...

Proper application of article, aside, and header elements

Can someone help me with my page template setup? I have a sidebar on the left and main content area on the right. I'm wondering if I am using the article, aside, and header tags correctly. Also, should I attach classes/ids to html5 elements or is that ...

Tips for automatically increasing row ID when adding a new row in MUI Data Grid

Trying to populate rows in my Data Grid component from MUI Kit without having to handle unnecessary unique ids. I attempted increasing the id number based on rows.length, but I consistently get 0 for some unknown reason. This is the code snippet: const ...

Adding Text Above a Material Icon in Angular: A Guide

Here is some sample HTML code to consider: <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <mat-icon class="fa fa-folder" style="font-size:48px;"><span style="color: re ...

What could be causing the removeChild() method to fail when trying to delete a list item in JavaScript DOM manipulation?

Check out this interactive shopping list. You can add items, delete them, and mark them as completed. Adding and deleting items works fine, but there's an issue when toggling them. Issue (occurs when toggling multiple list items) If you add 3 items ...

When the mouse hovers over it, show text instead of an icon on a React Material UI button

I'm currently working on a project that involves using material ui buttons. Initially, the add button only displays the + icon. Now, I want to change the button content from the icon to the text "CREATE ITEM" when the mouse is hovered over it. Check ...

Improving Material UI Responsiveness: A Comprehensive Guide

Could someone please help me resolve the overflow issue in my UI? You can view the overflow here. The second image explains the reason behind it, which you can see here. I am currently working on fixing my UI using React and Material UI. When checking the ...

The issue of CSS3 Grid-gap not functioning properly on iPhone devices

I've been working on creating a CSS template and everything seems to be functioning correctly, except for the grid gap which doesn't seem to work properly on my iPhone. Here's the code I have so far: <div class="grid"> <h1 ...

CSS: Creating a block that stretches the entire width of its parent block

I've been facing the same issue multiple times. Whenever I use the float property to display one block, the next block ends up overlapping with the first one. For example: Consider the following block of code: .row_item{ width: 30%; display: block; ...

SVG to create a gradient mask that appears transparent

I require assistance with working on svg's. I have a "background image" with another "image" layered over it. The "image" needs to have a hole cut out of it so that the background image can shine through. I managed to achieve this by utilizing svg: ...

Create dynamic animations for HTML lists with seamless transitions

I am looking to create a smooth animation effect for an HTML list that moves from left to right and vice versa with a fixed length. The issue I am encountering is that when I click on the right button, it is replacing the list elements instead of animating ...

Do lengthy words sink while short words swim?

I need to display some text inside a box. To achieve this, I enclose my text within an <article> element. <article> <p>Here is the text that I want to display in a box.</p> </article> I then style it as a block with fix ...