How the Material-UI Tooltip zIndex takes precedence over the MenuItem in the Select component

My issue is quite straightforward. I have a <Tooltip> component wrapping a <Select> component, and when I click the Select, the tooltip appears above the MenuItems like this:

Expected behavior:

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

Unexpected behavior:

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

I kept all the default values for Material-UI, and for the Tooltip it's: zIndex: 1500, but there isn't one for MenuItem as far as I can tell. I tried setting the zIndex of MenuItem to 1501, but the behavior remained the same.

I am curious about the correct way to either position the tooltip behind the MenuItem or hide the tooltip altogether when the Select MenuItems are displayed...

Below is a snippet of my code:

<Tooltip title={'Filter by status'}>
    <Select value={this.state.status} onChange={this.handleChange.bind(this, Filter.Status)}>
        {statuses.sort(this.filterItemSortFn).map(item => {
            return (<MenuItem style={{zIndex: 1501}} value={item}>{item}</MenuItem>);
        })}
    </Select>
</Tooltip>

If I decrease the zIndex of the tooltip so that it hides behind the MenuItems, it works, but I prefer not to override default values as it may impact other zIndex settings.

You can access the CodeSandbox demonstration here: https://codesandbox.io/s/rn68z4xlo

Answer №1

Incorrectly, Liam's response does not match the requirements for MUI v4 while Joe's answer is irrelevant.

The z-index of the Tooltip component is inherited from the Popper component, meaning that altering the z-index exclusively for the Tooltip will yield no results. It is necessary to transmit the z-index from the Tooltip up to the Popper.

For example:

<Tooltip title={"foo"} PopperProps={{style:{zIndex:0}}}>

Answer №2

There was a known bug in the Material-Ui Tooltip, but it has been resolved in the latest version.

To resolve the issue, simply add a zIndex to your tooltip component:

<Tooltip title={"Message"} style={{ zIndex: '1' }}>
        <Select 
          value={this.state.name}
          onChange={this.handleChange}
          input={<Input id="select-multiple" />}
          MenuProps={MenuProps}
        >
          {names.map(name => (
            <MenuItem key={name} value={name}>
              {name}
            </MenuItem>
          ))}
        </Select>
      </Tooltip>

If you want to hide the tooltip completely when the menu is open, use the following code:

<Tooltip title={"Message"} 
            onClick={() => this.setState({ tooltip: !this.state.tooltip })}
          style={this.state.tooltip ? {display: 'none'}:{ zIndex: '1' }}>
            <Select 
              value={this.state.name}
              onChange={this.handleChange}
              input={<Input id="select-multiple" />}
              MenuProps={MenuProps}
            >
              {names.map(name => (
                <MenuItem key={name} value={name}>
                  {name}
                </MenuItem>
              ))}
            </Select>
          </Tooltip>

Make sure to define the tooltip state in your component:

class MultipleSelect extends React.Component {
  state = {
    name: [],
    tooltip: false,
  };

For further reference, you can check out this example on CodeSandbox.

Answer №3

If you're experiencing issues with modal and tooltip in MUI 5, the following code snippet can help:

 const CustomTooltipTheme = createTheme({
 components: {
    MuiTooltip: {
      styleOverrides: {
        tooltip: {
          // custom styles for tooltip
        },
        popper: {
         // custom styles for popper
          zIndex: 700 + '!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 with Phonegap: layout distortion occurs when keyboard is displayed

Having trouble with the UI when the keyboard is active. Elements with a position: fixed style seem to scroll along with the content when the keyboard is open. Any solutions to fix this issue? This problem occurs specifically in iOS versions 6.1 and 7.1. ...

Ever wonder what goes on behind the scenes when you press a button before the Javascript method is carried out

My web application is built using ASP.NET MVC 4, jQuery, and Telerik's Kendo controls. Within my webpage, I have the following code snippet: <input id="cmdSaveToFile" title="Save To File" class="button" type="button" value="Save To File" onclick= ...

How can I use jquery to eliminate classes that match?

I have a collection of items that are tagged with different classes: <ul> <li> <div class="blue active"><span>Blue</span></div> ...

What is the best way to retrieve metadata and open graph information from a link?

I am currently working on developing a sharing feature that allows users to paste links and share them with their friends. My goal is to extract information such as title, description, and images when a user pastes a link, similar to how Facebook or Linked ...

Expand Elements to occupy entire width

My CSS skills are still in the early stages. I haven't delved too deeply into it. I have a query regarding how to achieve full width for an element. I've included my code below, but the basic approach I tried using 'width: 100%' didn&a ...

Looking to implement a load more feature in Next.js to fetch additional data? Learn how to create a load more button for pagination using Next

Is there a way to load more data in next.js by clicking on the Load More button? Currently, I am using getServerSideProps to fetch data from an API for this page. Here is my page code: export default function Posts({ posts, popular }) { const classes = ...

Manipulating an SVG graphic's attributes by linking them to an external geometry in Three.js

Delving into the world of Three.js, I've embarked on a project to design a 3D kit creator for my college assignment. Through my study, I've grasped the basics of setting up scenes, scene objects, geometries, materials, and textures. I've r ...

What is the significance of "sx" in Material-UI?

I'm really confused. Can anyone explain it to me? I understand that 'fx' is pronounced as "eff-axe," which sounds like "effects", so vfx must mean 'video effects' and sfx means 'sound effects.' I tried looking for a sim ...

Verify the Javascript for file upload in ASP.NET folder prior to uploading it

Struggling with this problem for days now, I could really use some fresh perspective. My setup includes Windows Server 2012, IIS 8.0, and ASP.NET 4.5. I'm new to both IIS and ASP.NET, so please bear with me. The website I'm working on involves f ...

Return to the previous URL after executing window.open in the callback

I need help redirecting the callback URL back to the parent window that initially called window.open. Right now, the callback URL opens inside the child window created by the parent. Here's the scenario: The Parent Window opens a child window for aut ...

In Javascript, you can enhance your axes on a graph by adding labels at both the

Is there a way to add labels at the beginning and end of the axes to indicate the importance level, such as "not very important" and "very important"? I am currently utilizing a slider program from here. Since I am new to JavaScript, I would greatly appre ...

Adapt your Bootstrap sidebar for icon menu on small screens below 800px

My Background My experience lies primarily in PHP rather than modern CSS, particularly Media Queries. This has left me feeling uncertain about how to effectively troubleshoot CSS layout issues. Currently, I am working on developing a user dashboard templ ...

Sorting and filtering data using AngularJS filter and orderBy inside a controller or factory

I am currently working with a factory that looks like this: app.factory("ModuleFactory", function (api, $http, $q, filterFilter) { var moduleList = []; var categoryList = []; var moduleTypeList = []; var academyModuleTypeList = []; var mostUsed = []; var ...

Is it possible to swap out one ID value for another using JavaScript?

I am facing two issues 1) First Issue I need to update the current id value with a new one. Whenever the a tag is clicked, an event in jQuery code should be triggered to change the id value. For example, When a button is clicked <div class="video" i ...

Tips for customizing the appearance of Java FX TableView column headers with CSS

I am relatively new to JavaFX and delving into CSS stylesheets, as well as using stackoverflow. I am curious about how one can customize the styling of a table column header. This is what my current column header looks like: Current appearance of my table ...

A tutorial on how to create the appearance of disabled buttons that look the same as enabled buttons through the use

My button includes a text field that is constantly disabled. I would like for the text field to appear as bright as it does when the button is enabled. After disabling the button, they both appear dimmer compared to others and the text field follows suit ...

Steps to automatically populate the dropdown upon page load

Hello, I have a question regarding setting a value to a dropdown list in JavaScript. Currently, I am trying to execute this function during the onload event of the body tag. However, I am facing issues with setting the value. Below is the code: function s ...

Prevent one individual cell in a table from dictating the overall table width

A B A B A X A B In a contained block with a fixed width of 400px, there is a table. When the browser width drops below 421px, the width of the containing block changes to 95%. The cells labeled "A" and "B" contain simple text. There is one cel ...

Does the modularization of code impact the performance of the react-app?

The client provided me with a React app that includes an index.jsx file where 90% of the coding has been completed. To prevent getting stuck in Scroll Limbo, I have started breaking down the code into modules for each specific requirement. These include ...

Managing "post" requests in a one-page web application using node.js

Although there may be similar answers to this question, I am in search of something different. On the client side, I have a signUp form that will make a post request to the server with the username and password. On the server side, I authenticate the req ...