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.

Add custom class to tooltips - ngbTooltipClass

See original GitHub issue

A great feature could making us able to set a custom class on tooltip for setting custom styles depending about this classe.

For example, in my case, I display a variable score in a <i> tag, and each tag have color depending of its score (eg: 3/10 => .red class).

It would be wonderfull if I could set a class by the way of interpolation :

<ul>
    <template ngFor let-score [ngForOf]="scores | orderBy: ['label']">

        <template #tipScore>{{score.label}} : <strong>{{score.score}}</strong> /10</template>

        <li *ngIf="score.name != 'general'">
            <i [ngbTooltip]="tipScore" [ngbTooltipClass]="(score.note | colorScore)"></i>
        </li>
        
    </template>
</ul>

The class should set through a [ngbTooltipClass] (in my case the classname would be returned by pipe colorScore).

Edit : There is a poor way to perform this, but which has its own limits and depends of the state of [container].

When the default behavior is running the container is the element where the [ngbTooltip] directive is attached. (in my case this is <i>), we could provide custom styles.

Example :

  1. Attach a class to the element node which contains the tooltip : <i class="yellow" [ngbTooltip]="tipScore"></i>

  2. Then use this selector for cover the tooltip and setting some styles :

[ng-reflect-ngb-tooltip].yellow + .tooltip {
    background-color: yellow;
}

But when the [container] is changes to body, I unknown a way to target the tooltip and apply a particular styles.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
Ismaestrocommented, Sep 11, 2017

Any updates?? this is mandatory, not a feature!!

3reactions
mfodorcommented, Mar 26, 2018

Another use case is when you need to set container to body. Then you have no control in CSS since the element is appended to body not as a child element. Coloring tooltips e.g. when displaying error indicators and details are in tooltip. This is my case.

Any updates?

@bastienmoulia do you have plans to make your PR accepted (#1951)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add custom class to ng-bootstrap tooltip - Stack Overflow
Here is the example of custom class from ng-bootstrap website. Link to stackblitz: link. HTML <button type="button" class="btn ...
Read more >
Tooltip - Angular powered Bootstrap
Tooltips can contain any arbitrary HTML, Angular bindings and even directives! ... You can optionally pass in a custom class via tooltipClass.
Read more >
Angular – How to add custom class to ng-bootstrap tooltip
I'm trying to add a custom class to an ng-bootstrap tooltip but it won't ... <button type="button" class="btn btn-outline-secondary" ngbTooltip="Nice class!
Read more >
Angular 12 ng-bootstrap | Tooltip Tutorial with Examples
In this Angular Bootstrap tutorial, we'll learn how to add bootstrap ... class="btn btn-outline-secondary mr-2" ngbTooltip="I am Bootstrap ...
Read more >
ng-bootstrap Tooltip - P N V R K Prasad - WordPress.com
<button type=”button” class=”btn btn-secondary” [ngbTooltip]=”tipContent”> ... Custom and manual triggers ... Append tooltip in the body.
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