Creating an opaque effect on a Material UI Drop down menu: Step-by-step guide

For the last half hour, I've been experimenting with my Select dropdown menu in an attempt to make it semi-transparent, but without success. I've tried adjusting the properties of the Paper, then the Menu, and then the MenuList, yet it appears that opacity changes are not supported. Here's a snippet of my code:

      <TextField
        id="outlined-select-links"
        required
        error={false}
        select
        InputLabelProps={{ shrink: true }}
        size="small"
        sx={{ width: 400, mt: 1, mb: 4 }}
        label="Links"
        helperText="Please select an account to link to your profile. 1 minimum."
        SelectProps={{
          multiple: true,
          value: links,
          MenuProps: {
            TransitionComponent: Fade,
            PaperProps: {
              sx: {
                opacity: 0.1,
              },
            },
          },
          onChange: handleLinkChange,
          renderValue: (selected) => (
            <Box sx={{ display: "flex", flexWrap: "wrap", gap: 0.5 }}>
              {selected.map((value) => (
                <Chip key={value} label={value} />
              ))}
            </Box>
          ),
        }}
      >
        {accounts.map((option) => (
          <MenuItem key={option} value={option} sx={{ my: -1 }}>
            <Checkbox checked={links.indexOf(option) > -1} />
            <ListItemText primary={option} />
          </MenuItem>
        ))}
      </TextField>

I managed to change the paper color to red as a test by targeting MenuProps, but I'm still struggling to achieve a slight transparency effect. Adjusting the opacity only seems to impact the MenuItems rather than the underlying paper menu. Any guidance would be greatly appreciated.

Answer №1

After conducting some thorough testing, it appears that I have identified the root of the issue. It seems that Material UI includes a container with opacity: 1; directly applied to house the MenuItem components. As this container is not visible within the markup, it can be challenging to style or modify. To address this, consider incorporating the following CSS snippet:

.MuiPopover-root .MuiMenu-paper {
  opacity: 0.5 !important;
}

In this instance, I am specifically targeting the pertinent Material UI classes within the component, allowing me to manipulate the div even without direct access in the markup. Moreover, the utilization of !important is essential due to Material UI's inlined opacity: 1; declaration.

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

Switch the toggle to activate or deactivate links

My attempt at coding a switch to disable and enable links using CSS is functional in terms of JavaScript, but the appearance is not changing. I am lacking experience in this area. Here is my HTML Button code: <label class="switch" isValue="0"> ...

React JS - A streamlined method for transferring data from one constant to another

I have an input on one component and I would like to pass its value to a constant called setSales in the sales_add() function when the value changes. How can this be achieved efficiently? Where am I going wrong? Is it possible to accomplish what I'm a ...

Desires to store the current state in an array composed of objects

i have the following fields on a form. there are multiple devices included in the form, each with nested fields. - manufacture_date is_exportad name sign When I submit the form, I want to store all values in local state. For example, devices{id1=& ...

Is there a way to incorporate text at the end of a row in HTML?

I have a photo and some text on my website. The photo is displayed on the left side, while the text appears nicely on the right side. Now, I am looking to include an additional block of text below the existing text. How can I accomplish this? What steps ...

Is there a way to change TextBox multiline to uppercase in Opera browser?

Does anyone know how to convert TextBox multiline to Uppercase in Opera? I tried using "text-transform:uppercase" but it only seems to work with IE ...

What is the best way to incorporate width adjustments in an image source for a responsive website?

Currently learning CSS and experimenting with it on an HTML page. For reference, I'm using this link. Encountering an issue with a responsive header image that adjusts size based on device (small on mobile, large on desktop). Is it possible to achiev ...

Utilizing Skeleton to create a cropped text button on an iPhone

I am currently using Skeleton for my simple CSS needs. While it works fine on desktop, I have noticed that on an iPhone, the text in my button gets cropped as shown in the picture. https://i.stack.imgur.com/EYo2P.png Below is the HTML code I'm using ...

Is there a way to access the state value within the reducer function of createSlice?

Currently, I am utilizing redux-toolkit within my react project. A concern arises in a specific reducer inside the createSlice method where I aim to incorporate an existing array of entities from the state and then merge it with a new array before finalizi ...

The JSX component cannot be utilized as `ToastContainer`

Check out this Code: import axios from "axios"; import React, { useState, useEffect } from "react"; import { ToastContainer, toast } from "react-toastify"; import loaderIcon from "../../assets/images/loader.gif"; imp ...

Steps to create a fixed pattern background image with a customizable background color based on the content within a div element

I am seeking guidance on how to create a single page application using Angular that features a fixed background image (such as a white pattern) in the BODY tag. However, I would like the ability to change the color behind this image depending on the conten ...

Tips on aligning vertically centered left and right floating objects without having to use the line height property

          Here is the issue I am facing http://jsfiddle.net/vT4YT/ <table><tr><td><div></div><div></div></td></tr></table> You can see that the options and row text are not vertic ...

I am experiencing difficulties with building Heroku using React and Nodemailer

Encountering difficulties with deploying my build on Heroku. Despite receiving a successful build message from Heroku, I am faced with an Application Error page whenever I try to access the site. Below is the package.JSON content for React: { "name": " ...

The variables in Next.js reset every time I navigate to a new page

Looking for a way to share a variable between pages in my Next.Js application, I have the following setup in my _app.js file: import { useState } from 'react'; const CustomApp = ({ Component, pageProps }) => { // Variables const [testVa ...

Font modification is unsuccessful in Vue-Material

Here is a snippet from my App.vue file where I encountered an issue with changing the font in the md-tabs component, taken from . The CSS line: background: #42A5F5; works perfectly fine, but this one does not: color: #E3F2FD; App.vue: <template> ...

Aligning text inputs inline within a Bootstrap form for a cleaner and organized

I am currently working on designing a form using Bootstrap, and I have a specific requirement where the first name and last name fields need to be displayed inline while the rest of the form remains unchanged. Although I have managed to make the inline fu ...

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Ensuring the first item is always active in the Bootstrap carousel in Reactjs when data is updated

My carousel contains an array of image links stored in data.img <div id="carouselExampleControls" className="codeinfo__carousel carousel slide" data-bs-ride="carousel" > <div c ...

Is there a way to enhance the react-leaflet Map component by incorporating the leaflet.contextmenu feature?

The react-leaflet-context-menu plugin serves as the react version of leaflet.contextmenu. It differs in that it utilizes the original leaflet map to implement the plugin in react rather than using react-leaflet. Incorporating react-leaflet into my applica ...

Nextjs 13: The Ultimate Guide to Incorporating mongoDb using the App Router

Looking for guidance on integrating MongoDB with a Next.js 13 application. I have set up my directory configuration in the app file. How can I incorporate MongoDB Community Server into my Next.js project? I attempted to create a services folder and used M ...

Tips on preventing unnecessary rerenders caused by changes in dependencies within useCallback

Since transitioning my VideoPlayer component from a class to a functional component, the crop functionality is not working as expected. The VideoPlayer now utilizes useState for an isVideoPlaying state and includes a function called togglePlayPauseVideo: ...