我正在为我的应用程序使用 Angular-Material Autocomplete(版本 7)。我用的是<cdk-virtual-scroll-viewport>里面的 除了我已经解决的许多问题之外,还有一个我不明白的问题:
当我添加 max-height css 时,下拉菜单不会显示,如果我添加高度,它将以固定高度显示。
这是我的代码的一部分:html:
<mat-form-field class="single-select">
<input matInput #singleInput class="single-input layout flex" type="text" [formControl]="selectControl" [matAutocomplete]="auto" (blur)="onBlur()" (focus)="onFocus()">
<mat-autocomplete class="single-autocomplete" #auto="matAutocomplete" [displayWith]="displayFn">
<cdk-virtual-scroll-viewport itemSize="45" minBufferPx="360" maxBufferPx="360" class="virtual-scroll">
<mat-option *cdkVirtualFor="let option of filteredOptions" [class.selected]="option === oldValue" [value]="option" (click)="onSelect(option)">{{option.label}}</mat-option>
</cdk-virtual-scroll-viewport>
</mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
TS:
export class SingleSelectComponent implements OnInit {
@Input() value;
@Input('options')
set options(value) {
if (value) {
this.filteredOptions = value.slice();
this.data = value;
this.initValue();
}
}
@Output() formValue = new EventEmitter<any>();
@ViewChild('singleInput') singleInput;
selectControl …Run Code Online (Sandbox Code Playgroud)