Customizing Material-UI Select Styles

I have been attempting to customize the appearance of Material-UI's <Select> component with variant="outlined". In this particular scenario, my objective is to hide the dropdown icon and set padding-right to 0px.

Based on my interpretation of the API documentation, it seems like I should be able to override the default styles by providing

classes={{ icon: classes.hideIcon, outlined: classes.noPaddingRight }}
, where classes is defined as follows:

const useStyles = makeStyles(theme => ({
  hideIcon: {
    display: "none"
  },
  noPaddingRight: {
    paddingRight: "0px"
  }
}));
const classes = useStyles();

Despite successfully hiding the icon, I'm facing issues with my noPaddingRight class being overridden by both

MuiSelect-select.MuiSelect-select
and
MuiSelect-outlined.MuiSelect-outlined
(I'm also unsure about the significance of the . in those class names):

https://i.sstatic.net/13LWj.png

To address this problem, I resorted to using paddingRight: 0px !important which is not an ideal solution for me.

You can access the corresponding CodeSandbox via this link: https://codesandbox.io/s/overwrite-select-style-zqk1r

Answer №1

To target the className MuiSelect-outlined, you can utilize nesting selectors.

hideIconPadding: {
  "& .MuiSelect-outlined": {
    paddingRight: "0px"
  }
}

Make sure to include the className like this:

className={classes.hideIconPadding}

https://i.sstatic.net/OC7E8.png

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

Guide to dynamically populating a select dropdown in a Django template with Javascript

Recently, I started learning Django and HTML, but JavaScript is still quite new to me. I'm working on creating a database display page with a filter menu on the side. Here is the code for this particular page: Model.py: class Part(models.Model): ...

Angular - The connections between deeply nested object models are established

I have an Angular application that is used to display company and contact person information in a text box format. Here is the code for displaying the Company Email address: <label> Company Email address</label> <input type="text& ...

Challenges arise with the safari navigation bar within a PWA platform

Struggling with the formatting and spacing issues of a PWA application on IOS devices due to notches and navbar heights. One specific problem is that a chat input with absolute positioning and bottom: 0 does not display properly in Safari because of the n ...

Nested tables with repeated data using AngularJS' ng-repeat functionality

As a newcomer to angularjs and web-development, I am facing a challenge with using ng-repeat to display data in a complex table structure, like this: A B C D abc pqr xyz std Here is the code snippet: <div class="table-responsive"> ...

implement breakpoints using the {withStyles} imported from '@material-ui/styles'

While attempting to utilize breakpoints with {withStyles} from "@material-ui/styles", I encountered an issue where the debugger indicated that theme.breakpoints was not defined. I experimented with wrapping the component in ThemeProvider, but unfortunatel ...

Is it possible to retrieve a variable from code.gs and pass it to my html file?

I had originally set up an automated email system to trigger once a certain condition was met, which I successfully implemented. However, I now want to enhance the email by including a more structured format and embedding an image from Google Drive. While ...

The unequal division of space between two flexed child divs is caused by varying image sizes

In my parent container, I have set the display property to flex. Inside, there are two divs with both having flex:1 set. However, the first child div contains an image and takes up twice as much space as the second div. If the screen is 1000px in height, ...

Tips for sending two values to a PHP file using JavaScript Ajax

I have created a code for two dropdown menus. The goal is to select values from both menus and send them to a php file using the GET method. The values should be sent to the php file only when both menus have selections made. Below is the code snippet: ...

Can a Node.js dependent library be integrated into Cordova?

After setting up an android project using Cordova, I came across a javascript library that relies on node.js to function. Since Cordova operates with node.js, can the library be invoked within the Cordova environment? ...

Unable to organize the data associated with a specific column in the header within an Angular material Table

viewing clinical history data the output I'm receiving is not in ascending or descending order Trying to organize the data in the table, utilizing the MatTableModule module alongside other required modules. However, after conducting research, I have ...

Having trouble with a CardMedia component in React not displaying the image properly

I am facing an issue where the images in my project are not showing up. I have tried using an image with a HTTP link and also an image from the project source folder, but both are not loading. Everything else on the card is loading fine except for the ima ...

Initiating Internet Explorer using the APTool application for Selenium automation

Have you ever encountered a situation where you needed to open Internet Explorer from the start menu with the right-click option open with *apptool and then navigate to a specific webpage? I wonder, is it possible to automate this process using Selenium W ...

Animation for Images in Angular v1.2

After reviewing tutorials and previous questions, I have been trying to pinpoint where my code is going wrong in applying an animation to transition between the images I want to display. The ng-show function effectively displays the selected picture, but ...

The property length is undefined and cannot be read

I'm currently utilizing a dexi.io robot for the purpose of automating data extraction from permit databases. This particular robot has the capability to process custom JavaScript in order to dissect the incoming JSON object. While this code does func ...

Error retrieving the potsdamer_platz_1k.hdr file. Unable to load the file

Currently, I am in the process of developing a custom t-shirt website using Three.js, but I have come across a persistent error while running the project. The same error occurs when attempting to run the project live as well. Despite including the file "pl ...

Positioning of buttons within a div

I am currently designing an inspiration post style: https://i.stack.imgur.com/I5J0H.png However, I am encountering some challenges while creating it: The buttons are not rounded when the window size is changed Social icons are not being displayed I am ...

Learn how to create a disappearing dropdown menu in React that closes automatically when you select a specific category

I'm encountering an issue with a dropdown menu that remains visible on the screen even after selecting a specific category. The selected category is displayed in a box upon selection, but the dropdown menu doesn't disappear as intended. I am look ...

Do not return true from a nested function in JavaScript for form validation

After successfully creating a function to validate a form, I realized that breaking it down into three separate functions would be more beneficial. The challenge arose when attempting to return the 'false' message back to the form after splittin ...

remove an offspring item from an array assembly

I have a variable called today that stores data retrieved from an API. I'm attempting to delete some information from it using a function, but I keep encountering the error message Cannot read property 'id' of undefined. SAMPLE DATA [ ...

Ways to inform an event from a child component to its parent component without using props

Within my component structure (<Grid>), there are n nested components: <Grid> <Header> <Toolbar> ... </Toolbar> <Filters> <Form> ... < ...