Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust MUI Tooltip font size?

I implemented a tooltip with MUI but the fontSize is too small. And I can't change it with a .scss.

import React from "react";
import "./InfoTooltip.scss";
import InfoIcon from '@material-ui/icons/Info';
import Tooltip from '@material-ui/core/Tooltip';

const InfoTooltip: React.FC<{ children?: any }> = ({ children }) => {
  const [label, ...rest] = children;
  return (
    <div className="info-tooltip-container">
      <div className="label-container">
        <Tooltip title={label}>
          <InfoIcon style={{ fontSize: '24px' }} />
        </Tooltip>
      </div>
      {rest}
    </div>
  );
};

export default InfoTooltip;
.info-tooltip-container {
  .label-container {
    font-size: 18px;
  }
  label {
    font-size: 18px;
  }
}

https://mui.com/components/tooltips/#main-content

like image 316
Ferma Avatar asked Mar 30 '20 08:03

Ferma


People also ask

How do I increase font size in tooltip?

You can change the variable $ tooltip-inner-font-size and assign it a new value. You will find this variable in src/mdb/scss/free/_variables. scss . Remember that this will change the text size of all tooltips.

How do you customize tooltip in MUI?

import Tooltip, { tooltipClasses } from "@mui/material/Tooltip"; import Button from "@mui/material/Button"; import Stack from "@mui/material/Stack"; import { styled } from "@mui/material/styles"; The tooltipClasses import is a useful way to get access to all the names of CSS classes applied by default to the tooltip.

How do I change font size on mat tooltip?

You can fix this by adding a . mat-tooltip css declaration in you main styles file and change the font size there. You need to set ! important on the font size otherwise it won't show up.

How do you style a material tooltip?

To style React Material UI tooltip, we can use the makeStyles function. We call makeStyles with a function that returns an object that has some classes with some styles. We set the background color and the color in the classes.

How do I change the font size on a tooltip?

To Change Text Size for Tooltips using "System Font Size Changer" by WinTools 1 Select (dot) Tooltip. 2 Check or uncheck Bold if you want bold text or not. 3 Adjust the slider for the font size you want. 4 When finished, click/tap on Apply.

How to change the font-size of Mui?

To change the font-size of MUI you can provide a fontSize property. The default value is 14px. The computed font size by the browser follows this mathematical equation: The theme.typography.* variant properties map directly to the generated CSS. You can use media queries inside them:

How do I change the font size of an icon button?

You can also use Typography and set the fontSize directly. Some components like Box or Typography inherit system props which allow you to change the styling using the top-level props: <Tooltip title= {<Typography fontSize= {30}>title</Typography>}> <IconButton> <DeleteIcon /> </IconButton> </Tooltip>

What is a tooltip in Windows 10?

A tooltip is a small pop-up that displays the label of an unlabeled control or glyph in Windows. This tutorial will show you how to change the font size of text for tooltips to what you want for your account in Windows 10.


4 Answers

You can add a customized component directly to props title.

If needed, you can add whatever inline-styles to the component you just added.

Include the font-size

<Tooltip title={<h1 style={{ color: "lightblue" }}>title</h1>}>
  <InfoIcon />
</Tooltip>

enter image description here


Refer: MUI tooltip document: customized-tooltips

like image 66
keikai Avatar answered Oct 17 '22 04:10

keikai


You can do that at global level or at component level.

Global level

This way all the Tooltips in the application will get the style.

First you need to create a theme.js file:

'use strict';

import { createMuiTheme } from '@material-ui/core/styles';

const theme = createMuiTheme({
    overrides: {
        MuiTooltip: {
            tooltip: {
                fontSize: "1em",
            },
        },
    },
});

export default theme;

Then import it in your main application component, so it will be applied to all the application components:

'use strict';

import React from "react";
import { ThemeProvider } from '@material-ui/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import theme from 'theme.js';

export default class App extends React.Component {

    render() {
        return (
            <ThemeProvider theme={theme}>
                <CssBaseline />
                    {/* Your app content */}
            </ThemeProvider>
        );
    }
}

Component level

With this approach you can define a different style for each component.

'use strict';

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

const useStyles = makeStyles({
    tooltip: {
      fontSize: "1em",
    },
});

export default class MyComponent extends React.Component {

    const classes = useStyles();

    render() {
        return (
            <Tooltip classes={{tooltip: classes.tooltip}} />
        );
    }

}
like image 31
Luca Fagioli Avatar answered Oct 17 '22 06:10

Luca Fagioli


You can also use Typography and set the fontSize directly. Some components like Box or Typography inherit system props which allow you to change the styling using the top-level props:

<Tooltip title={<Typography fontSize={30}>title</Typography>}>
  <IconButton>
    <DeleteIcon />
  </IconButton>
</Tooltip>

Live Demo

Codesandbox Demo

like image 41
NearHuscarl Avatar answered Oct 17 '22 04:10

NearHuscarl


Using MUI v5

This will change the font size for all tooltips within <ThemeProvider>

import React from "react";
import { createTheme, CssBaseline, ThemeProvider } from '@mui/material';

const theme = createTheme({
    components: {
        MuiTooltip: {
            styleOverrides: {
                tooltip: {
                    fontSize: '1em'
                }
            }
        }
    }
});

export default function App() {
    return <ThemeProvider theme={theme}>
        {/* Your app content */}
        <CssBaseline />
    </ThemeProvider>;
}
like image 3
zXynK Avatar answered Oct 17 '22 05:10

zXynK