0

我正在运行 angular app ,对此我有自动完成功能,我想将水平滚动添加到 mat-option,我尝试应用 css 样式

.cdk-overlay-pane {
  overflow-x: auto;
}

 then applying syle as told in this docuemnt [enter link description here][1] showPanel: boolean

  <mat-option class="CustomerDropDown" showPanel="true" ...
extended question

<mat-form-field >
  <input matInput [matAutocomplete]="auto"  [formControl]="customerFilterControl">
  <mat-autocomplete panelWidth ="450px" #auto="matAutocomplete" [displayWith] = "displayFn" style="width:750px;">
     <mat-option  *ngFor="let customer of filteredOptions | async" [value] ="customer.AccountID + '('+ customer.AccountName + ')'" (click)="onCustomerChange(customer)">
      {{customer.AccountID}} ({{customer.AccountName}})
     </mat-option>
  </mat-autocomplete>
</mat-form-field>

两次尝试都失败了!!

4

2 回答 2

0

试试下面的 CSS。它对我有用。

::ng-deep .custom-mat-option .mat-option-text {
  overflow: auto;
  text-overflow: unset;
  // color: green;
}

custom-mat-option是我添加到<mat-option>元素中以增加 css 特异性的类。

堆栈闪电战

于 2019-11-27T12:21:51.250 回答
-1

HTML

<cdk-virtual-scroll-viewport itemSize="50" class="example-viewport">
  <div *cdkVirtualFor="let item of items" class="example-item">{{item}}</div>
</cdk-virtual-scroll-viewport>

TS 文件

import {ChangeDetectionStrategy, Component} from '@angular/core';

/** @title Basic virtual scroll */
@Component({
  selector: 'cdk-virtual-scroll-overview-example',
  styleUrls: ['cdk-virtual-scroll-overview-example.css'],
  templateUrl: 'cdk-virtual-scroll-overview-example.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CdkVirtualScrollOverviewExample {
  items = Array.from({length: 100000}).map((_, i) => `Item #${i}`);
}

CSS

.example-viewport {
  height: 200px;
  width: 200px;
  border: 1px solid black;
}

.example-item {
  height: 50px;
}

并按照此链接 滚动

于 2019-11-27T11:27:05.030 回答