繁体   English   中英

如何设置 mat-option 文本的样式以在将鼠标悬停在每个 mat-option 文本上时获取 mat-select 面板外的文本

[英]How to style mat-option text to get the text outside mat-select panel on hovering over every mat-option text

我想在每个 mat-option 文本上设置悬停样式,我希望文本显示在 mat-option 之外。 为了实现这一点,我应用了非常高的 z-index,但没有任何改变。 我尝试将 z-index 添加到更高的值,但这没有解决。

我的灵感来自以下stackblitz 链接

这是当前的行为

在此处输入图片说明

这是我需要的在此处输入图片说明

这是代码片段

模板.html

<mat-form-field [style.cursor]="pointer"  [style.width.px]=450 >
  <input  id="inputCustomer" matInput [matAutocomplete]="auto"  [formControl]="customerFilterControl" [(ngModel)]="customerName">

   <mat-autocomplete  style="left:775px;" #auto="matAutocomplete" [displayWith] = "displayFn" >
    <mat-option  (onSelectionChange)="onCustomerChange(customer)" [value] ="customer.AccountID +' '+'('+ customer.AccountName + ')'">
       <span>{{customerName}}</span>
  <span id="para2">{{customerName}}</span>
    </mat-option>
</mat-autocomplete>

模板.ts

  customer:Array<any>;
  filteredOptions: Observable<any[]>;
  customerFilterControl = new FormControl();
customer =[
{
AccountID :1,
AccountName:"account1"
},
{
 AccountID:2,
 AccountName:"account2"
},
{
 AccountID:3,
 AccountName:"Earliest_Creation_Date_Ent_Tests_id7 (Earliest_Creation_Date_Ent_Tests_id7accountName)"
}

  displayFn(subject) {
    return subject ? subject : undefined;  
  }


onCustomerChange(customer) {
this.filteredOptions = this.customerFilterControl.valueChanges.pipe(
  startWith(''),
  map(value => this._filter(value))
 );  
}


  _filter(value:any):any[] {

    const filterValue = value;
    return this.customers.filter(function (option) {
       if(option.AccountID.includes(filterValue) | option.AccountName.includes(filterValue)) {
          return option;
        }
    }); 
  }

模板.scss

#para2 {
display:none;
}
.mat-option:hover {
  background-color: white !important;
  z-index:500000 !important;
  width:440px !important;
  word-break: break-all !important; 
}


.mat-option-text {
  padding-left: 60px !important;
  overflow: auto !important;
  text-overflow: unset !important; 
}


.mat-option {

    &:hover {
        white-space: unset!important;
        overflow: unset !important;
        background-color: #FFFFFF;


        #para2
        {

            z-index:500000 !important;
            width:400px !important;
            word-break: break-all !important; 
            display: block;
            position: relative !important;
            overflow: visible !important;
            text-align: left;
            top:0px;
            right:50px !important;
            background-color: #232F34;
            color:#FFFFFF;
            border: 5px !important;
            font-size:11px;


        }
    }
}

将鼠标悬停在每个选项上方时,您是否考虑过为每个 mat-option 使用 matTooltip?

添加一个

matTooltip="{{state.name}} | Population: {{state.population}}"

在垫子选项上,角材料完成其余的工作。

此处检查工作示例

暂无
暂无

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

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