question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tooltip] How to customize the tooltip?

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

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

  1. Render Tooltip
  2. Implement styled components
  3. Override a specific class with the classes attribute
  4. Apply styling to the specified class

Your Environment

Tech Version
Material-UI latest
React latest

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

48reactions
oliviertassinaricommented, May 5, 2021

Here is a working example following our guide, it can be further improved by adding theme to the styled components theme.

capture d ecran 2018-09-23 a 22 33 25

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:

capture d ecran 2018-09-23 a 22 38 59 https://material-ui.com/api/tooltip/

or in the Dev Tool directly:

capture d ecran 2018-09-23 a 22 42 07

5reactions
artalarcommented, May 5, 2021

This is workaround to you https://codesandbox.io/s/lr20v47ql9

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create Tooltips - W3Schools
Tip: Go to our CSS Tooltip Tutorial to learn more about tooltips. Tip: To create "clickable" tooltips, go to our How To Create...
Read more >
How to Create a Custom Tooltip with Pure CSS
We make it invisible at first by setting opacity: 0 . The opacity changes to opacity: 1 when we hover over .recent-link ....
Read more >
How to Create an HTML Tooltip [+ Code Templates]
To make a simple tooltip, we'll first create the HTML element that triggers the tooltip when hovered over. We'll create this element as...
Read more >
How to customize tooltips - Datawrapper Academy
How to customize tooltips · Emphasize text with HTML · Create a mini-table · Add extra information about certain regions · Add two...
Read more >
Customization in JavaScript Tooltip control - Syncfusion
The Tooltip can be customized by using the cssClass property, which accepts custom CSS class names that define specific user-defined styles and themes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found