Customize the design of a React Material-UI select dropdown by overriding

I am currently utilizing the React MUI Select Component for my forms, specifically for language selection. My issue arises when I need a different style for the dropdown menu of the language Select component. Overriding the relevant class would apply this new style to every Select component, but I only want it to affect the language Select. You can see an example in the image below:

https://i.stack.imgur.com/kfXdZ.png

Below is the code snippet:

const LanguagesSelect = props => {

  return (
    <Select  className="test" classes="assad" style={{ position: "relative !important", left: "20px !important", top: "30px !important", width: "168.3px !important", background: "white !important", borderRadius:"12.75px" }} >
      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <div style={{ display: "flex", width: "100%" }}>
          <img src={require("../../../assets/img/icons/flags/franch.svg").default} />
          <div style={{ marginLeft: "5px" }} >Franch</div>
        </div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/eng.svg").default} />
        <div style={{ marginLeft: "5px" }}>English</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/turkish.svg").default} />
        <div style={{ marginLeft: "5px" }}>Turkish</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/czech.svg").default} />
        <div style={{ marginLeft: "5px" }}>Czech</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/hebrew.svg").default} />
        <div style={{ marginLeft: "5px" }}>עברית</div>
      </MenuItem>

    </Select>
  )

}

Answer №1

Override the default style by utilizing the sx prop. For additional information, check out this resource mui_sx_prop

Answer №2

Applying external CSS to the Select element allows for manipulation of its child elements, such as the MenuItem.

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

triggering php object on mouse hover

I'm currently working on creating a mouseover effect for my PHP elements within a store. My goal is to have a transparent div appear over the dynamically generated PHP sections. I have set it to display block mode to test its functionality and positio ...

Are the fetch functions within getStaticProps and getServerSideProps equivalent to the fetch API native to web browsers?

I've been working with Next.js for some time now and I'm questioning the fetch API used in both getStaticProps and getServerSideProps. Below is my understanding of these functions: getStaticProps runs during build time and ISR getServerSidePro ...

Having issues with referencing external JavaScript and CSS files in Angular 6

Dealing with an angular6 project and a bootstrap admin dashboard template, I'm facing issues importing the external js references into my Angular application. Looking for guidance on how to properly import and refer to external Js/CSS files in an angu ...

Transforming a traditional HTML/CSS/JS website into a cutting-edge React application using Tailwind CSS styling

I have a unique website template complete with HTML, CSS, and all necessary assets. Now, I am looking to develop a React JS application using this template. Firstly, I am wondering: Since I typically use Tailwind CSS for my other projects, would it be mo ...

Issue with Material UI and React Autocomplete: Popover does not properly display when an item is selected, causing Autocomplete to

I'm currently working on a customized Autocomplete feature, where each item displays a more icon when hovered over with a mouse pointer. The issue I am facing is that instead of triggering a Popover when clicking the icon, it closes the Autocomplete ...

Update the page when the React route changes

I am facing an issue with a function in a component that is supposed to load certain variables when the page is fully loaded. Interestingly, it works perfectly fine when manually reloading the page. However, if I use a NavLink to navigate to the page, the ...

Is a new object created when updating the state of an object within the useEffect() function?

import { useEffect, useState } from "react"; function CountSecrets() { const [secret, setSecret] = useState({ value: "", countSecrets: 0 }); useEffect(() => { if (secret.value === 'secret') { setSecret(s =&g ...

Ways to ensure that two divs have equal heights based on whichever one has the greater height using CSS

I need help with adjusting the heights of two divs inside a container div using CSS. Specifically, I want the height of the img_box div to match the height of the content_con div based on their actual content. For example, if the content_con div contains t ...

Is it recommended to create model classes in React components?

Within the realms of React, the Flux architecture is utilized. According to https://reactjs.org/docs/thinking-in-react.html, React operates with two distinct models - namely, the state and props. There are recommendations provided for model management in ...

Structuring MongoDB / Mongoose Schemas for organizing nested subdocuments

Is it possible to design a schema that allows for an item type to be added as its own child? For example, can a page function as a sub-page with identical properties? ...

Customize the duration of Skeleton animations in Material UI

The <Skeleton> components in mui utilize pulse or wavy animations. Wondering if there's a method to quicken this animation, perhaps by adjusting the duration? ...

Contrasting createMuiTheme and getMuiTheme

When would you choose to use one over the other? What are the key differences in how they operate? ...

Using React.js with a PHP backend to create an API ecosystem for

Creating an admin panel for a website with CRUD operations has been quite the journey. I began by setting up API endpoints and hosting them on a subdomain. Fetching data from these endpoints was successful for displaying all contacts (GET), individual cont ...

The state may be modified, but the component remains unchanged

I've been tasked with implementing a feature on a specific website. The website has a function for asynchronously retrieving data (tickets), and I need to add a sorting option. The sorting process occurs on the server side, and when a user clicks a s ...

designing icon buttons

I am interested in adding big buttons with icons to my website. I have images named largebut_hover.png, largebut.png, and icon.png. The icon image is supposed to be displayed inside the light grey background of largebut.png, and when hovering, it should sw ...

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 ...

The React.js Mui Collapse component exclusively triggers animation during the transition while closing, without any animation when expanding

Whenever I implement the Collapse component from Mui library in my projects, I face an issue where the transition animation only works when closing the component (when in={false}). However, when opening the component, there is a delay before the animation ...

Align Divs Horizontally to Center

I'm trying to find a way to horizontally center multiple DIVs in a straight line. Here's how my code currently looks: HTML: <div id="circle"> <div id="circle1"></div> <div id="circle2"></div> </div> CSS ...

How can a component be dynamically rendered in React?

I'm interested in exploring alternative approaches to accomplishing the same task. My desired outcome is as follows: Menu Item 1 Menu Item 2 Menu Item 3 Target (Where component should be displayed) When a menu item is clicked, I want the associate ...

How to Create Smooth Transitions for Text Arrays using jQuery's Fade In and Fade Out Features

I need to loop through an array of text and apply jQuery's fadeIn and fadeOut functions to each element. var greetings = ["hi, I'm", "bonjour, je m'appelle", "hallo, ich heiße"] The HTML structure I want is as follows: <h2><span ...