Material-ui: [Tooltip] Add a way for controlling the distance between the tooltip and its container

Created on 25 Feb 2020  路  7Comments  路  Source: mui-org/material-ui

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Summary/Example/Motivation 馃挕馃寛馃敠

I'd like to be able to control the distance where the tooltip is placed. I searched through the props, style classes, and also here in the Github issues but I didn't find anything that was easy to configure to achieve this:

Screen Shot 2020-02-25 at 19 12 21

I tried some hacks around marginTop and top, but the component recalculates its position based on them so it's ineffective.

Tooltip support

All 7 comments

馃憢 Thanks for using Material-UI!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://material-ui.com/getting-started/support/. Thanks!

If you have a question on StackOverflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

Using the padding/margin is the right direction to take.

Can you please clarify how exactly?
https://codesandbox.io/s/modest-solomon-qjxqk

This is left to be answered on StackOverflow.

This really should be better explained in the documentation.

In case anyone is looking for the solution, here it is:

const useTooltipStyles = makeStyles(() => ({
  tooltip: {
    margin: 0,
  },
}));

const classes = useTooltipStyles();

<Tooltip
  title="Tooltip Text"
  classes={classes}
>
  <button>Tooltip Test</button>
</Tooltip>

Unfortunately if you have an arrow, you'll need to calculate that height into the margin so the arrow doesn't sit over the anchor element.

@zeckdude Thanks for your answer. This is working. But when I tried to override in MUI theme's tooltip options it didn't work.
MuiTooltip: { tooltip: { margin: 0, }, },

I'm not using arrow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

ghost picture ghost  路  3Comments

finaiized picture finaiized  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments