简体   繁体   English

使用 matTooltip angular 材质的工具提示设置箭头

[英]set arrow with tooltip of matTooltip angular material

in angular material it provide matTooltip attribute to show tooltip.在 angular 材质中,它提供了 matTooltip 属性来显示工具提示。 i want to show arrow with tooltip pointing towards overflow text.我想显示带有指向溢出文本的工具提示的箭头。 but tooltip position is dynamic based on target element position in corners, top or bottom based on that appending arrow in tooltip design as per tooltip position is difficult, i applied bellow solution but works only if i open tooltip at specified position top, bottom, left or right但工具提示 position 是基于目标元素 position 在角落、顶部或底部的动态,根据工具提示设计中的附加箭头,根据工具提示 position 是困难的,我应用了以下解决方案,但仅当我在指定的 position 顶部、底部、左侧打开工具提示时才有效或对

.mat-tooltip::before {
      content     : '';
      display     : block;
      position    : absolute;
      bottom      : 100%;
      border-style: solid;
      border-color: transparent transparent #3E464E transparent;
      border-width: 12px;
      left        : calc(50% - 12px);
}  


<div class="title-ellips"
   matTooltipClass="custom-tooltip"
   matTooltip="{{exam | examColumnValue: column}}"
  *ngIf="((exam[column]) && ((exam | examColumnValue: column).toString().length>=30))"
   placement="top" data-container="body" tooltipClass="customTableTooltip">
  {{exam | examColumnValue: column}}
</div>

It can be done as follow:可以按如下方式进行:

css: css:

.mat-tooltip {
  position: absolute;

  &::after {
    width: 0;
    height: 0;
    content: '';
    position: absolute;
    border-left: 0.5rem solid transparent;
    border-right: 0.5rem solid transparent;
    border-bottom: 0.5rem solid black;
  }
  &.below {
    overflow: initial;
    margin-top: 1rem;
    &:after {
      top: -0.5rem;
      right: calc(50% - 0.5rem);
      transform: rotate(0);
    }
  }

  &.above {
    overflow: initial;
    margin-bottom: 1rem;
    &:after {
      bottom: -0.5rem;
      right: calc(50% - 0.5rem);
      transform: rotate(180deg);
    }
  }

  &.right {
    overflow: initial;
    margin-left: 1rem;
    &:after {
      left: -0.75rem;
      top: calc(50% - 0.25rem);
      transform: rotate(270deg);
    }
  }

  &.left {
    overflow: initial;
    margin-right: 1rem;
    &:after {
      right: -0.75rem;
      top: calc(50% - 0.25rem);
      transform: rotate(90deg);
    }
  }
}

In component.ts file:在 component.ts 文件中:

  positionOptions: TooltipPosition[] = ['below', 'above', 'left', 'right'];
  // You can change the logic of currentPosition according to your requirements
  currentPosition= this.positionOptions[0];

In html file:在 html 文件中:

[matTooltipPosition]="currentPosition"
[matTooltipClass]="currentPosition"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM