【问题标题】:Angular Material - How to display matTooltip for angular stepper when the steps are disabledAngular Material - 如何在禁用步骤时显示角度步进器的 matTooltip
【发布时间】:2021-09-02 11:39:23
【问题描述】:

我有一个 Angular 水平步进器,它在 css 中被禁用,我想显示工具提示。 由于禁用的 css 代码,这将不起作用。

// .ts file:
<mat-horizontal-stepper labelPosition="bottom" #stepper>
  <mat-step
    editable="false">
    <ng-template matStepLabel>
      <span matTooltip="'test11111'">test1</span>
    </ng-template>
  </mat-step>
</mat-horizontal-stepper>
// .scss file
:host ::ng-deep .mat-horizontal-stepper-header-container {
    pointer-events: none;
    cursor: not-allowed;
}

如何在禁用步骤的情况下显示工具提示?

【问题讨论】:

    标签: angular angular-material angular-material-stepper


    【解决方案1】:

    为什么你会允许一个禁用的东西的工具提示?如果你想在整个订书机上有一个工具提示,你可以将它包装在一个元素中并在那里添加工具提示。如果您确实希望在步骤的跨度上显示工具提示,则需要更改样式以再次触发指针事件。

    还有一些样式可以禁用悬停效果和事件侦听器以防止点击和禁用波纹效果。

    样式:

    :host ::ng-deep .mat-horizontal-stepper-header-container {
      pointer-events: none;
      cursor: not-allowed;
       
      .mat-step-header:hover {
        background: inherit;
      }  
    
      .mat-tooltip-trigger {
        pointer-events: auto;
        cursor: initial;
      }
    }
    

    模板:

    <mat-horizontal-stepper labelPosition="bottom" #stepper>
      <mat-step
        editable="false">
        <ng-template matStepLabel>
          <span 
            (click)="$event.stopPropagation()" 
            (mousedown)="$event.stopPropagation() 
            matTooltip="'test11111'">
            test1
          </span>
        </ng-template>
      </mat-step>
    </mat-horizontal-stepper>
    

    working stackblitz

    【讨论】:

    • 一些步骤有很长的文本标签,我想显示这些标签的工具提示。而且我不会让用户控制步进器,步骤是通过编程完成的。
    • @SaadHasan 可以理解,在这种情况下,我认为我提出的解决方案应该可行。我已对其进行了更新以使其完整
    猜你喜欢
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 2020-07-12
    相关资源
    最近更新 更多