How to change the text color and background color of ant-tooltip component
Asked Answered
R

6

5

I implemented antd tooltip but need to change the background color and text color of it but I am unable to achieve that. I tried to do using "overlayStyle" provided by antd tooltip component but no luck not working as expected. As Shown below.

<Tooltip
    title={jobNumber * 3}
    placement="bottomRight"
    overlayStyle={{
        color: "orange",
        background: "blue",
    }}
>
    <div style={{ maxWidth: `${jobNumber * 3}px` }} />
</Tooltip>;

I tried inspecting it but unable to do so as its work on hover and till the time I move my cursor to class but no help.

What I founded on hover the div added one class named 'ant-tooltip-open' but what's that in the class I can't see.

Regicide answered 19/4, 2019 at 10:13 Comment(2)
Can you please add a jsfiddle for this, so that I can inspect...Puppetry
the example you can see from this link ant.design/components/tooltip/#headerRegicide
B
9

You can do this easily, see below code

.ant-tooltip-inner {
    color: yellow;
    background-color: green;
}

.ant-tooltip-placement-bottom .ant-tooltip-arrow, .ant-tooltip-placement-bottomLeft .ant-tooltip-arrow, .ant-tooltip-placement-bottomRight .ant-tooltip-arrow {
    border-bottom-color: green;
}

here is working demo https://codepen.io/anon/pen/JVvyGr

enter image description here

Bellicose answered 19/4, 2019 at 10:44 Comment(4)
that triangle is also getting that light color, you can see it by changing background color of your body to dark color, it may not be visible properly because there is no shadow to it like tooltip, even if you tried to add shadow to triangle it will look as square so better use different colorBellicose
It does not work for the arrow but using : .ant-tooltip-arrow::before { background-color: white; } It fixes the arrow colorBlueness
Also add !important to color and backgroundColor to make sure it works.Palladin
May I change className of the tooltip hint? (not the tooltip button / text / div) This is necessary in case I want to have different styles on different tooltips...Chondrule
R
1

I hope this can useful for you. In order to change the color of the ant tooltip arrow use:

.ant-tooltip-arrow::before{
        background-color: white;
    }
Rotl answered 24/9, 2020 at 6:8 Comment(0)
E
0

In order to change the color of the arrow use this:

.ant-tooltip-arrow-content{
    background-color: #fafafa !important;
}

because it stays as black even when changing the background color of the tooltip and apparently this line of code didn't work for me in Chrome:

.ant-tooltip-placement-bottom .ant-tooltip-arrow, .ant-tooltip-placement-bottomLeft .ant-tooltip-arrow, .ant-tooltip-placement-bottomRight .ant-tooltip-arrow {
        border-bottom-color: green;
    }
Eckhart answered 21/9, 2020 at 14:36 Comment(0)
T
0

overlayInnerStyle={{color: '#000'}}

<Tooltip title={value} color="white" overlayInnerStyle={{color: '#000'}}>

Twicetold answered 19/4 at 12:16 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Rhombic
M
0

Wrap the title with a div element, then use the style attribute to change the color, and the color attribute to change the background. (I know. It's annoying!)

For example, this tooltip should have a red background and a white text.

const backgroundColor = "red";
const textColor = "white";

<Tooltip
  color={backgroundColor}
  title={<div style={{ color: textColor }}>{text}</div>}
 >
  Show Tooltip
</Tooltip>
Minstrelsy answered 19/9 at 22:17 Comment(0)
E
-2

For somebody's looking for a theme setting solution, the color of a tooltip could be set on a theme with colorTextLightSolid token

Endeavor answered 20/3, 2023 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.