Matt
Matt

Reputation: 99

Material UI - How to completely remove background \ color from tooltip

I am currently working with Material UI's tooltip and I can't seem to figure out how to make the tooltip's background completely transparent. By default there is a grey background with white text. Changing the Tooltips background color changes the child element's background color since the Tooltip is the parent element in this context.

I've tried this

 <Tooltip title="Add" classes={{
    tooltip: "backgroundColor: transparent"

  }} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

And this:

<Tooltip title="Add" style={{backgroundColor: "transparent"}} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

My objective is to have no background on hover of the tooltip. I just want to see the text.

Upvotes: 0

Views: 12706

Answers (3)

Ivan K.
Ivan K.

Reputation: 1124

APP.css

Styles applied to the tooltip (label wrapper) element.

.MuiTooltip-tooltip {
    background-color: #EDEEEF!important;
    color: #2f343D!important;
  }

Upvotes: 0

n0noob
n0noob

Reputation: 939

Since you want only the text on hover with no background of the tooltip.

Define style like this:

const useStylesBootstrap = makeStyles(theme => ({
  tooltip: {
    backgroundColor: "transparent",
    color: theme.palette.common.black
  }
}));

Use it in your React component like this:

const tooltipClass = useStylesBootstrap();

return (
  <Tooltip title="Add" classes={tooltipClass} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>
);

Upvotes: 1

Brett DeWoody
Brett DeWoody

Reputation: 62881

There are several methods for customizing components, as described in the documentation:

  1. Specific variation for a one-time situation
  2. Dynamic variation for a one-time situation
  3. Specific variation of a component re-used in different contexts
  4. Material Design variations such as with the button component
  5. Global theme variation

It appears you want to use the first method and override the style with a class. To do this we'll use makeStyles and define a background for the tooltip, something like this:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Tooltip from '@material-ui/core/Tooltip';

const useStyles = makeStyles({
  tooltip: {
    background: 'transparent',
  },
});

export default function ClassesNesting() {
  const classes = useStyles();

  return (
    <Tooltip
      classes={classes}
    >
      Button
    </Tooltip>
  );
}

Upvotes: 1

Related Questions