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
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.
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.
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.
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.
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.
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:
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>
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.
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>
Refer: MUI tooltip document: customized-tooltips
You can do that at global level or at component level.
This way all the Tooltip
s 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>
);
}
}
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}} />
);
}
}
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>
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>;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With