-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tooltip] How to customize the tooltip? #11467
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Yeah this is also effecting us. We cannot apply a |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here is a working example following our guide, it can be further improved by adding import React from "react";
import styled from "styled-components";
import Button from "@material-ui/core/Button";
import Tooltip from "@material-ui/core/Tooltip";
const StyledTooltip = styled(props => (
<Tooltip classes={{ popper: props.className }} {...props} />
))`
& .MuiTooltip-tooltip {
background-color: papayawhip;
color: #000;
}
`;
function StyledComponents() {
return (
<StyledTooltip title="Demo">
<Button>Styled Components</Button>
</StyledTooltip>
);
}
export default StyledComponents; https://codesandbox.io/s/8109v3n1x8?file=/StyledComponentsButton.js If you are wondering what classes you can use, you can find the information in the API docs page:
or in the Dev Tool directly: |
This comment has been minimized.
This comment has been minimized.
@pezzullig Did you check https://material-ui.com/demos/tooltips/#variable-width out? |
Yes I did try that and it does work withStyles. I was just trying to get it to work in your codepen with the styled-components but I couldn't manage it. Am I right in saying that setting the maxWidth parameter in the .tooltip section should be equivalent to the withStyles method suggested? |
@pezzullig |
Ah yes you're right thanks @oliviertassinari ! |
Hi @oliviertassinari . When I use your solution, it works as expected. But I tried to rewrite it by const StyledTooltip = styled(Tooltip).attrs((props) => ({
classes: { popper: props.className, tooltip: "tooltip" }
}))`
& .tooltip {
background-color: red;
color: #000;
}
`; |
2021 and I can't get this example to work :-/ |
@BeKnowDo I have updated my initial comment to be more up to date. This case is even in the docs now: https://next.material-ui.com/guides/interoperability/#portals. The customization demos cover it too: https://next.material-ui.com/components/tooltips/#customized-tooltips. |
Thanks @oliviertassinari . This helped me a lot. |
Expected Behavior
Turn Tooltip into styled component
-> use classes attribute to override
tooltip
class-> styles should be applied to the element
Current Behavior
I can see that my new tooltip class is on the element itself but without styles.
Steps to Reproduce (for bugs)
https://codesandbox.io/s/yj7wjr753z
Your Environment
latest
latest
The text was updated successfully, but these errors were encountered: