personalizing material-ui component styles – set select component color to be pure white

I am looking to implement a dropdown menu using material-ui components (refer to https://material-ui.com/components/selects/). To do so, I have extracted the specific component from the example:

Component

return <div>
<FormControl variant="outlined" className={classes.root}>
  <InputLabel ref={inputLabel} id="demo-simple-select-outlined-label">
    Plan
  </InputLabel>
  <Select
    labelId="demo-simple-select-outlined-label"
    id="demo-simple-select-outlined"
    value={age}
    onChange={handleChange}
    labelWidth={labelWidth}

  >
    <MenuItem value="">
      <em>None</em>
    </MenuItem>
    <MenuItem value={10}>dsnfsdjfnsduifn</MenuItem>
    <MenuItem value={20}>Twenty</MenuItem>
    <MenuItem value={30}>Thirty</MenuItem>
  </Select>
</FormControl>

Style

const useStyles = makeStyles(theme => ({
root: {
  margin: theme.spacing(1),
  minWidth: 120,
  color: 'white',
  borderColor: 'white'
},}));

Given my app's design requirements, I need to change the color of this dropdown menu to white. Currently, the component appears as shown in the following image:

https://i.stack.imgur.com/gteAF.jpg

Looking at the component code, it is outlined. Referring to the documentation (https://material-ui.com/api/select/), it seems that I need to override the .MuiSelect-outlined class, but I am unsure about how to achieve this. The documentation only covers styling simple buttons and does not provide guidance on customizing more complex components like this one. I would appreciate if someone could demonstrate an example of how to change the color of the outline, text, and arrow to white.

Answer №1

Sure thing!

.MuiOutlinedInput-notchedOutline {
    border-color: #fff;//customize border color
}
 .MuiSelect-icon {
    color: #fff;//customize dropdown icon color
}
.MuiInputLabel-root {
    color: #fff;//customize label color
}

To style when focused, simply add the parent selector .Mui-focused to these elements

Answer №2

const myStyles = customStyles(theme => ({
option: {
  borderStyle: 'solid',
  borderWidth: 2,
  borderColor: 'blue'
},
inputField{
  padding: theme.spacing(2),
  width: 200,
  color: 'black',
}
}));

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

Using percentages for CSS alignment and adjusting element widths

Greetings everyone! I have been struggling to align two divs - one on the right with a width of 30% and the other on the left with 70%. Despite my efforts, I have not been able to find a solution. I am hopeful that someone here can assist me. My setup inv ...

Creating a serial number in a Class without relying on a global variable is a useful technique that

I am looking for a way to assign a unique ID to each instance of a Class without relying on global variables. I have tried using a global variable and incrementing it, but I would prefer a more efficient approach. Is there a way to generate an ID within t ...

Ensure that you wait for all asynchronous $http requests to finish in AngularJS before continuing

I am facing a challenge with a page that generates a varying number of $http requests based on the length of a certain variable. I aim to update the scope with the data only after all requests have been completed. Without relying on jQuery for this project ...

How can users change the displayed Twitch channel?

My coding skills aren't the greatest, especially when it comes to something like this. I've tried searching for a solution with no luck, so I apologize if this is too basic or impossible. I have a simple page that loads up Twitch with a predefin ...

Button click not triggering JQuery click event

$(document).ready(function () { $('#btnApplyFilter').click(function () { alert("JQuery is not running!"); }); }); Why is the above function not working when the button is clicked? Here is the code for my button : ...

Transmit the bound data (using ng-model) to a custom AngularJS directive

/*I am looking to define the maxDate as vmEndDate*/ app.directive('myDatepicker', function ($parse) { return function (scope, element, attrs, controller) { var ngModel = $parse(attrs.ngModel); alert(element.va ...

What is the reason behind utilizing the external 'this' within the inner function in Vue: $this=this?

Recently, I came across some code online that included a line $this=this. My initial interpretation was that this line assigns the 'this' of the outer function to a variable, allowing it to be used in the inner function as well. However, upon fur ...

The script fails to start using npm start, however, it runs smoothly when using node server.js

For a while now, I've been facing an issue that I just can't seem to resolve. When I navigate to my project's src folder and execute `node server.js`, everything functions as expected. I can access the application at http://localhost:3000/cl ...

Receiving the error "Potential null object. TS2531" while working with a form input field

I am currently working on developing a straightforward form to collect email and password details from new users signing up on Firebase. I am utilizing React with Typescript, and encountering an error labeled "Object is possibly 'null'. TS2531" s ...

Encountered a session.socket.io error: unable to find session using the provided key: connect.sid

So, I've been struggling with an issue for the past couple of days and I can't seem to figure it out. I've searched through various resources like this GitHub issue and Stack Overflow, but I still haven't found a solution. Here's m ...

Icon-enhanced Bootstrap dropdown selection

I have a unique select dropdown using Bootstrap where I want to display icons like the example below: https://i.sstatic.net/dZmTS.png <!DOCTYPE html> <html> <head> <script src="/scripts/snippet-javascript-console.min.js?v=1"& ...

What is the best way to locate an item within a Redux array when working with TypeScript?

Below is the content of my slice.ts file. interface iItem { Category: string; Id: string; } interface iDataState { Items: Array<iItem>; } const initialState: iDataState = { Items: [], }; reducers: { updateItem: (state, action: PayloadAc ...

Is there a way to adjust the saturation and desaturation of an image using CSS?

Issue Update After further testing, I have discovered that the desaturation effect is only functioning properly in Chrome. How can I adjust it to work in other browsers such as FF and IE? (Title modified) Currently, I am working on turning a color image ...

Newbie struggling with executing JavaScript in Visual Studio Code

Hey there! I'm new to coding and have been struggling for the past couple of hours trying to get a simple JavaScript code to run on VSC. Can anyone lend a hand in helping me set up my sandbox correctly? Here's a snapshot for reference: https://i ...

Ways to center Bootstrap panel in the middle of a webpage

Is there a way to center this entire panel on the web page? I could use some guidance with this. Does anyone have recommendations for a good book to learn Bootstrap design? <div class="panel panel-default" style="max-width:500px;margin-left:auto;margi ...

How can you capture the VIRTUAL keyCode from a form input?

// Binding the keydown event to all input fields of type text within a form. $("form input[type=text]").keydown(function (e) { // Reference to keyCodes... var key = e.which || e.keyCode; // Only allowing numbers, backspace, and tab if((key >= 48 && ke ...

What might be the reason for my react-bootstrap modal not applying any styling?

I have two projects, one created by following a tutorial series and the other created independently later on, aiming to replicate the first project. I have narrowed down my issue to a basic comparison of index.js in both projects. This code is an edited v ...

AJAX Post Request Function without Form That Does Not Reset

I am currently struggling with understanding the Ajax POST method. I am attempting to make an API request, and since the response has similar parameters, I decided to create a global function that can be used by other HTML/JS pages. However, I am aware tha ...

Having trouble retrieving the onchange value from a reactstrap switch input

I am facing an issue with a reactstrap switch that should return true or false onchange. However, I'm struggling to retrieve the value when it changes. Here is my code: <div className='form-switch'> <Input type='switch' ...

Using .change(); in JavaScript code with jQuery does not trigger a function

Here we have a generic code example for a jQuery function: $(document).ready(function() { if (something) { // This does something } else if (something else) { // This does something else } else { // And this does somethin ...