Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add arrows in matTooltip?

I'm trying to add arrows on matTooltip, there is any way to add arrows on matTooltip.

<button mat-raised-button
        matTooltip="Info about the action"
        aria-label="Button that displays a tooltip when focused or hovered over">   
        Action 
</button>
like image 693
Faizan Haider Avatar asked Aug 12 '18 10:08

Faizan Haider


People also ask

How do I add an arrow on tooltip?

Tooltip Arrows To create an arrow that should appear from a specific side of the tooltip, add "empty" content after tooltip, with the pseudo-element class ::after together with the content property. The arrow itself is created using borders. This will make the tooltip look like a speech bubble.

How do you use a matTooltip?

matTooltip is used when certain information is to be displayed when a user hovers on a button. Approach: First, install the angular material using the above-mentioned command. After completing the installation, Import 'MatTooltipModule' from '@angular/material/tooltip' in the app.

How do you change a matTooltip position?

By default tooltip is displayed below the element. we can change the tooltip position by using matTooltipPosition input property.

What is tooltip angular?

The Angular Material tooltip provides a text label that is displayed when the user hovers over or longpresses an element.


2 Answers

You need to override material styles. and add before/after pseudo-element as arrow. For example if you need to style a tooltip with left border and arrow just do something like that

.mat-tooltip {
    // to make possible place arrow pseudo element outside tooltip with absolute positioning
    overflow: visible;
    position: relative;
    &.right {
        border-left: 6px solid red;
        margin-left: 5px;
        &::before {
            position: absolute;
            content: '';
            display: inline-block;
            background-color: red;
            clip-path: polygon(50% 0, 0 50%, 50% 100%);
            left: -12px;
            width: 15px;
            height: 15px;
            top: 50%;
            transform: translateY(-50%);
        }
    }
}
like image 72
Dmitriy K Avatar answered Oct 12 '22 20:10

Dmitriy K


Following the usage of Material Design, arrows are not included in angular tooltip component. Here you could take a look what you can do and not to do with tooltips https://material.io/components/tooltips/

like image 27
beanic Avatar answered Sep 17 '22 18:09

beanic