[英]How to set the number of items in mat-autocomplete
I'm now trying to change the number of items in a mat-autocomplete for a while without success.我现在正在尝试更改 mat-autocomplete 中的项目数,但没有成功。 I'm using material.angular.io
我正在使用 material.angular.io
Here's my code这是我的代码
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-add-and-search', templateUrl: './add-and-search.component.html', styleUrls: ['./add-and-search.component.css'] }) export class AddAndSearchComponent implements OnInit { items: string[] = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; constructor() { } ngOnInit() { } }
<mat-form-field appearance="standard"> <mat-label>Search...</mat-label> <input matInput placeholder="Search..." [matAutocomplete]="auto"> <mat-icon matSuffix>search</mat-icon> </mat-form-field> <mat-autocomplete #auto="matAutocomplete"> <mat-optgroup label="Items"> <mat-option *ngFor="let item of items" [value]="item">{{item}}</mat-option> <mat-option><mat-icon>add</mat-icon>Add</mat-option> </mat-optgroup> </mat-autocomplete>
From the docs I learned that the autocomplete panel has a constant height of 256px ( https://material.angular.io/components/autocomplete/api#AUTOCOMPLETE_PANEL_HEIGHT ).从文档中我了解到自动完成面板的高度为 256 像素( https://material.angular.io/components/autocomplete/api#AUTOCOMPLETE_PANEL_HEIGHT )。
My question is: How can I change the autocomplete panel to display more items.我的问题是:如何更改自动完成面板以显示更多项目。 Let's say 10. If there is no intended way of doing this could someone give me a hint on a CSS trick to set the height eg to 512px instead of the default 256px?
让我们说 10。如果没有打算这样做的方法,有人可以给我一个关于 CSS 技巧的提示,例如将高度设置为 512px 而不是默认的 256px?
Many thanks!非常感谢!
You can change the height of the autocomplete panel by overwriting the max-height like this:您可以通过像这样覆盖 max-height 来更改自动完成面板的高度:
::ng-deep .mat-autocomplete-panel {
max-height: 512px !important;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.