Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background color of a MUI tooltip?

I want to have a "?" icon that users can hover and get specifications on what data they should input into the text field. MUI's default hover is grey with white words, but I'd like mine to be white with grey words, and the font to be bigger. I found that using works well for font-size and color, but when I change background color, there is a grey border around the hover textfield. This is the hover.js component:

export default function HoverTip(prop) {
    const { tip } = prop

    return (
    <Tooltip 
        title={
            <Typography 
            fontSize={15} 
            backgroundColor={'#ffff'} 
            color={'#514E6A'}>
                {tip}
            </Typography>}     
        arrow 
        placement="right"
        sx={{fontSize: '30'}}
        
         >
        <IconButton >
        <HelpOutlineIcon />
        </IconButton>
    </Tooltip>
    )

}

However this leaves a black border around the hover textbox. Any idea how to fix this? what it looks like

like image 504
Ruo Avatar asked Aug 30 '25 17:08

Ruo


2 Answers

You can solve this by using the sx.

Now I found that using it on the Tooltip directly does not work but you can pass it to the actual tooltip element using the slotProps property.

return (
  <Tooltip
    title={<Typography fontSize={15}>{tip}</Typography>}
    arrow
    placement="right"
    sx={{ fontSize: "30" }}
    slotProps={{
      tooltip: {
        sx: {
          color: "#514E6A",
          backgroundColor: "#ffff",
        },
      },
    }}
  >
    <IconButton>
      <HelpOutlineIcon />
    </IconButton>
  </Tooltip>
);
like image 131
RubenSmn Avatar answered Sep 02 '25 08:09

RubenSmn


<Tooltip
  PopperProps={{ sx: { '.MuiTooltip-tooltip': { bgcolor: 'green' } } }} 
  title="green"
>
  <SomeIcon />
</Tooltip>
like image 37
bryn Avatar answered Sep 02 '25 08:09

bryn