【发布时间】:2020-09-23 09:19:54
【问题描述】:
所以下面是我的代码。我正在做的是在允许多选的下拉列表中显示所有可用设备,并且当设备计数超过 4 时我添加了一个搜索字段。 mat-select 的默认行为是当我选择一个选项并关闭时下拉菜单,当我重新打开它时,它会在所选选项上打开。但在这里它没有发生。它从头开始。所以我希望当我滚动并选择最后一个选项时,当我重新打开下拉菜单时,菜单应该滚动到足以显示所选选项的程度。 这个默认行为是否因为我添加了搜索栏而不起作用?
<form [formGroup]="gatewayForm" autocomplete="off">
<mat-form-field style="font-size:0.83em" class="no-arrow activity-log-field">
<mat-select formControlName="gatewayCtrl" multiple disableOptionCentering panelClass="form-panel gpanel" name="Gateway" (openedChange)="checkChanged($event,'gatewayList')" (selectionChange)="gatewaySelectedClick($event)">
<mat-select-trigger>
{{selectedText}}
<span *ngIf="extratext!=null" class="example-additional-selection">
{{extratext}}
</span>
</mat-select-trigger>
<mat-form-field *ngIf="gateways && gateways.length>4" class="organistation-searchField" appearance="outline" [floatLabel]="'never'" aria-autocomplete="off" style="padding: 5px 8px 5px 8px;font-size: 13px">
<input #search autocomplete="off" formControlName="searchTerm" (keyup)="filterDevices($event.target.value,'gatewayList','gpanel');" (keydown)="$event.stopPropagation()" matInput placeholder="Search Device">
<mat-icon matSuffix style="color:#24539f;position: relative;top: 0.1em;">search</mat-icon>
</mat-form-field>
<div class="panel-optn" style="max-height: 170px;">
<mat-option *ngIf="gateways && gateways.length>1" (click)="toggleAllSelection()" #allSelected class="gatewayList" [value]="allgateways">All devices</mat-option>
<mat-option (click)="tosslePerOne(allSelected!=null?allSelected.viewValue:null)" class="gatewayList" *ngFor="let gateway of gateways" [value]="gateway">
{{ gateway.panel_name }}
</mat-option>
</div>
</mat-select>
</mat-form-field>
</form>
【问题讨论】:
标签: javascript angular angular-material